MCPcopy Create free account
hub / github.com/ElementsProject/lightning / log_to_files

Function log_to_files

lightningd/log.c:374–479  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

372}
373
374static void log_to_files(const char *log_prefix,
375 const char *entry_prefix,
376 enum log_level level,
377 /* The node_id to log under. */
378 const struct node_id *node_id,
379 /* Filters to apply, if non-NULL */
380 const struct list_head *print_filters,
381 const struct timeabs *time,
382 const char *str, size_t str_len,
383 const u8 *io, size_t io_len,
384 bool print_timestamps,
385 const enum log_level *default_print_level,
386 struct log_file **log_files)
387{
388 char tstamp[sizeof("YYYY-mm-ddTHH:MM:SS.nnnZ ")];
389 char *entry, nodestr[hex_str_size(PUBKEY_CMPR_LEN)];
390 char buf[sizeof("%s%s%s %s-%s: %s\n")
391 + strlen(log_prefix)
392 + sizeof(tstamp)
393 + strlen(level_prefix(level))
394 + sizeof(nodestr)
395 + strlen(entry_prefix)
396 + str_len];
397 bool filtered;
398
399 if (print_timestamps) {
400 char iso8601_msec_fmt[sizeof("YYYY-mm-ddTHH:MM:SS.%03dZ ")];
401 strftime(iso8601_msec_fmt, sizeof(iso8601_msec_fmt), "%FT%T.%%03dZ ", gmtime(&time->ts.tv_sec));
402 snprintf(tstamp, sizeof(tstamp), iso8601_msec_fmt, (int) time->ts.tv_nsec / 1000000);
403 } else
404 tstamp[0] = '\0';
405
406 if (node_id)
407 hex_encode(node_id->k, sizeof(node_id->k),
408 nodestr, sizeof(nodestr));
409 else
410 nodestr[0] = '\0';
411 if (level == LOG_IO_IN || level == LOG_IO_OUT) {
412 const char *dir = level == LOG_IO_IN ? "[IN]" : "[OUT]";
413 char *hex = tal_hexstr(NULL, io, io_len);
414 if (!node_id)
415 entry = tal_fmt(tmpctx, "%s%s%s: %.*s%s %s\n",
416 log_prefix, tstamp, entry_prefix, (int)str_len, str, dir, hex);
417 else
418 entry = tal_fmt(tmpctx, "%s%s%s-%s: %.*s%s %s\n",
419 log_prefix, tstamp,
420 nodestr,
421 entry_prefix, (int)str_len, str, dir, hex);
422 tal_free(hex);
423 } else {
424 size_t len;
425 entry = buf;
426 if (!node_id)
427 len = snprintf(buf, sizeof(buf),
428 "%s%s%s %s: %.*s\n",
429 log_prefix, tstamp, level_prefix(level), entry_prefix, (int)str_len, str);
430 else
431 len = snprintf(buf, sizeof(buf), "%s%s%s %s-%s: %.*s\n",

Callers 3

maybe_printFunction · 0.85
log_ioFunction · 0.85
logging_options_parsedFunction · 0.85

Calls 6

hex_str_sizeFunction · 0.85
level_prefixFunction · 0.85
hex_encodeFunction · 0.85
tal_hexstrFunction · 0.85
tal_freeFunction · 0.85
filter_levelFunction · 0.85

Tested by

no test coverage detected