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

Function log_one_line

lightningd/log.c:534–580  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

532};
533
534static void log_one_line(unsigned int skipped,
535 struct timerel diff,
536 enum log_level level,
537 const struct node_id *node_id,
538 const char *prefix,
539 const char *log,
540 const u8 *io,
541 struct log_data *data)
542{
543 char buf[101];
544
545 if (skipped) {
546 snprintf(buf, sizeof(buf), "%s... %u skipped...", data->prefix, skipped);
547 write_all(data->fd, buf, strlen(buf));
548 data->prefix = "\n";
549 }
550
551 snprintf(buf, sizeof(buf), "%s+%lu.%09u %s%s: ",
552 data->prefix,
553 (unsigned long)diff.ts.tv_sec,
554 (unsigned)diff.ts.tv_nsec,
555 prefix,
556 level == LOG_IO_IN ? "IO_IN"
557 : level == LOG_IO_OUT ? "IO_OUT"
558 : level == LOG_DBG ? "DEBUG"
559 : level == LOG_INFORM ? "INFO"
560 : level == LOG_UNUSUAL ? "UNUSUAL"
561 : level == LOG_BROKEN ? "BROKEN"
562 : "**INVALID**");
563
564 write_all(data->fd, buf, strlen(buf));
565 write_all(data->fd, log, strlen(log));
566 if (level == LOG_IO_IN || level == LOG_IO_OUT) {
567 size_t off, used, len = tal_count(io);
568
569 /* No allocations, may be in signal handler. */
570 for (off = 0; off < len; off += used) {
571 used = len - off;
572 if (hex_str_size(used) > sizeof(buf))
573 used = hex_data_size(sizeof(buf));
574 hex_encode(io + off, used, buf, hex_str_size(used));
575 write_all(data->fd, buf, strlen(buf));
576 }
577 }
578
579 data->prefix = "\n";
580}
581
582char *opt_log_level(const char *arg, struct log *log)
583{

Callers

nothing calls this directly

Calls 4

hex_str_sizeFunction · 0.85
hex_data_sizeFunction · 0.85
hex_encodeFunction · 0.85
write_allFunction · 0.50

Tested by

no test coverage detected