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>
This commit is contained in:
Rusty Russell 2019-06-30 10:12:43 +09:30
parent cbf240e110
commit 5f02294b5b
2 changed files with 21 additions and 3 deletions

View File

@ -32,6 +32,24 @@
/* Once we're up and running, this is set up. */ /* Once we're up and running, this is set up. */
struct log *crashlog; 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, static void log_to_file(const char *prefix,
enum log_level level, enum log_level level,
bool continued, bool continued,
@ -52,8 +70,8 @@ static void log_to_file(const char *prefix,
fprintf(logf, "%s %s%s%s %s\n", fprintf(logf, "%s %s%s%s %s\n",
iso8601_s, prefix, str, dir, hex); iso8601_s, prefix, str, dir, hex);
tal_free(hex); tal_free(hex);
} else if (!continued) { } else if (!continued) {
fprintf(logf, "%s %s %s\n", iso8601_s, prefix, str); fprintf(logf, "%s %s %s %s\n", iso8601_s, level_prefix(level), prefix, str);
} else { } else {
fprintf(logf, "%s %s \t%s\n", iso8601_s, prefix, str); fprintf(logf, "%s %s \t%s\n", iso8601_s, prefix, str);
} }

View File

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