Browse Source

lightningd/log: prefix log messages with level.

In particular, this lets us spot UNUSUAL and BROKEN messages easily.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
pull/2938/head
Rusty Russell 6 years ago
parent
commit
5f02294b5b
  1. 22
      lightningd/log.c
  2. 2
      tests/test_plugin.py

22
lightningd/log.c

@ -32,6 +32,24 @@
/* Once we're up and running, this is set up. */
struct log *crashlog;
static const char *level_prefix(enum log_level level)
{
switch (level) {
case LOG_IO_OUT:
case LOG_IO_IN:
return "IO";
case LOG_DBG:
return "DEBUG";
case LOG_INFORM:
return "INFO";
case LOG_UNUSUAL:
return "UNUSUAL";
case LOG_BROKEN:
return "**BROKEN**";
}
abort();
}
static void log_to_file(const char *prefix,
enum log_level level,
bool continued,
@ -52,8 +70,8 @@ static void log_to_file(const char *prefix,
fprintf(logf, "%s %s%s%s %s\n",
iso8601_s, prefix, str, dir, hex);
tal_free(hex);
} else if (!continued) {
fprintf(logf, "%s %s %s\n", iso8601_s, prefix, str);
} else if (!continued) {
fprintf(logf, "%s %s %s %s\n", iso8601_s, level_prefix(level), prefix, str);
} else {
fprintf(logf, "%s %s \t%s\n", iso8601_s, prefix, str);
}

2
tests/test_plugin.py

@ -454,7 +454,7 @@ def test_warning_notification(node_factory):
# 2. test 'error' level, steps like above
event = "Test warning notification(for broken event)"
l1.rpc.call('pretendbad', {'event': event, 'level': 'error'})
l1.daemon.wait_for_log('plugin-pretend_badlog.py Test warning notification\\(for broken event\\)')
l1.daemon.wait_for_log(r'\*\*BROKEN\*\* plugin-pretend_badlog.py Test warning notification\(for broken event\)')
l1.daemon.wait_for_log('plugin-pretend_badlog.py Received warning')
l1.daemon.wait_for_log('plugin-pretend_badlog.py level: error')

Loading…
Cancel
Save