Skip to content

Commit 9113275

Browse files
LimiNodeclaude
andcommitted
docs(mdbx): add live callback subscription to example
- Show add_log_callback, live events via LOGIT_INFO, LOGIT_WAIT - Show remove_log_callback and verify no further updates Co-Authored-By: Claude Opus 4.8 <[email protected]>
1 parent d3e17e4 commit 9113275

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

examples/example_logit_mdbx_logger.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,33 @@ int main() {
184184
<< r.timestamp_ms << " " << r.message << std::endl;
185185
}
186186

187+
// Live subscription: snapshot + real-time updates
188+
std::vector<logit::LogRecordView> live_updates;
189+
uint64_t cb_id = mdbx->add_log_callback(
190+
[&live_updates](const logit::LogRecordView& v) {
191+
live_updates.push_back(v);
192+
});
193+
194+
LOGIT_INFO("Live event 1 via callback");
195+
LOGIT_INFO("Live event 2 via callback");
196+
LOGIT_WAIT();
197+
198+
std::cout << "\n--- Live updates received (" << live_updates.size()
199+
<< ") ---" << std::endl;
200+
for (const auto& r : live_updates) {
201+
std::cout << " [" << logit::to_string(r.level) << "] "
202+
<< r.message << std::endl;
203+
}
204+
205+
if (mdbx->remove_log_callback(cb_id)) {
206+
std::cout << "Callback removed" << std::endl;
207+
}
208+
209+
LOGIT_INFO("Event after unsubscribe");
210+
LOGIT_WAIT();
211+
std::cout << "Live updates after unsubscribe: " << live_updates.size()
212+
<< std::endl;
213+
187214
// Statistics
188215
std::cout << "\n--- Statistics ---" << std::endl;
189216
std::cout << " dropped: " << mdbx->dropped_count() << std::endl;

0 commit comments

Comments
 (0)