MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_log

Function cbm_log

src/foundation/log.c:264–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262}
263
264void cbm_log(CBMLogLevel level, const char *msg, ...) {
265 if (level < atomic_load_explicit(&g_log_level, memory_order_relaxed)) {
266 return;
267 }
268
269 char line_buf[CBM_SZ_4K];
270 size_t pos = 0;
271 va_list args;
272 va_start(args, msg);
273
274 if (atomic_load_explicit(&g_log_format, memory_order_relaxed) == CBM_LOG_FORMAT_JSON) {
275 append_raw(line_buf, sizeof(line_buf), &pos, "{\"level\":");
276 append_json_string(line_buf, sizeof(line_buf), &pos, level_str(level));
277 append_raw(line_buf, sizeof(line_buf), &pos, ",\"event\":");
278 append_json_string(line_buf, sizeof(line_buf), &pos, msg ? msg : "");
279 for (;;) {
280 const char *key = va_arg(args, const char *);
281 if (!key) {
282 break;
283 }
284 const char *val = va_arg(args, const char *);
285 append_char(line_buf, sizeof(line_buf), &pos, ',');
286 append_json_string(line_buf, sizeof(line_buf), &pos, key);
287 append_char(line_buf, sizeof(line_buf), &pos, ':');
288 append_json_string(line_buf, sizeof(line_buf), &pos, val ? val : "");
289 }
290 append_char(line_buf, sizeof(line_buf), &pos, '}');
291 } else {
292 append_raw(line_buf, sizeof(line_buf), &pos, "level=");
293 append_text_atom(line_buf, sizeof(line_buf), &pos, level_str(level));
294 append_raw(line_buf, sizeof(line_buf), &pos, " msg=");
295 append_text_atom(line_buf, sizeof(line_buf), &pos, msg ? msg : "");
296 for (;;) {
297 const char *key = va_arg(args, const char *);
298 if (!key) {
299 break;
300 }
301 const char *val = va_arg(args, const char *);
302 append_char(line_buf, sizeof(line_buf), &pos, ' ');
303 append_text_atom(line_buf, sizeof(line_buf), &pos, key);
304 append_char(line_buf, sizeof(line_buf), &pos, '=');
305 append_text_atom(line_buf, sizeof(line_buf), &pos, val ? val : "");
306 }
307 }
308 va_end(args);
309
310 finish_line(line_buf, sizeof(line_buf), pos);
311 emit_line(line_buf);
312}
313
314void cbm_log_control_record(const char *msg, ...) {
315 /* No threshold check: a control record's whole purpose is surviving

Callers 6

cbm_log_intFunction · 0.85
cbm_log_mcp_requestFunction · 0.85
cbm_log_http_requestFunction · 0.85
index_thread_fnFunction · 0.85
application_job_publishFunction · 0.85

Calls 7

append_rawFunction · 0.85
level_strFunction · 0.85
append_charFunction · 0.85
append_text_atomFunction · 0.85
finish_lineFunction · 0.85
emit_lineFunction · 0.85
append_json_stringFunction · 0.70

Tested by

no test coverage detected