log: add 'warning' notification when log

- Related Changes for `warning` notification

Add a `bool` type parameter in `log_()` and `lov()`, this `bool` flag
 indicates if we should call `warning` notifier.

1) The process of copying `log_book` of every peer to the `log_book` of
`ld` is usually included in `log_()` and `lov()`, and it may lead to
repeated `warning` notification. So a `bool`, which explicitly indicates
if the `warning` notification is disabled during this call, is necessary
.
2) The `LOG_INFO` and `LOG_DEBUG` level don't need to call
warning, so set that `bool` paramater as `FALSE` for these log level and
only set it as `TRUE` for `LOG_UNUAUSL`/`LOG_BROKEN`. As for `LOG_IO`,
it use `log_io()` to log, so we needn't think about notifier for it.
This commit is contained in:
trueptolemy
2019-06-06 16:26:42 +08:00
committed by Rusty Russell
parent 231703cc7f
commit 96135dab5e
11 changed files with 47 additions and 29 deletions

View File

@@ -21,6 +21,7 @@
#include <lightningd/json.h>
#include <lightningd/jsonrpc.h>
#include <lightningd/lightningd.h>
#include <lightningd/notification.h>
#include <lightningd/options.h>
#include <signal.h>
#include <stdio.h>
@@ -102,7 +103,7 @@ static size_t prune_log(struct log_book *log)
return deleted;
}
struct log_book *new_log_book(size_t max_mem,
struct log_book *new_log_book(struct lightningd *ld, size_t max_mem,
enum log_level printlevel)
{
struct log_book *lr = tal_linkable(tal(NULL, struct log_book));
@@ -114,6 +115,7 @@ struct log_book *new_log_book(size_t max_mem,
lr->print = log_to_stdout;
lr->print_level = printlevel;
lr->init_time = time_now();
lr->ld = ld;
list_head_init(&lr->log);
return lr;
@@ -226,7 +228,8 @@ static void maybe_print(const struct log *log, const struct log_entry *l,
l->io, tal_bytelen(l->io), log->lr->print_arg);
}
void logv(struct log *log, enum log_level level, const char *fmt, va_list ap)
void logv(struct log *log, enum log_level level, bool call_notifier,
const char *fmt, va_list ap)
{
int save_errno = errno;
struct log_entry *l = new_log_entry(log, level);
@@ -243,6 +246,10 @@ void logv(struct log *log, enum log_level level, const char *fmt, va_list ap)
maybe_print(log, l, 0);
add_entry(log, l);
if (call_notifier)
notify_warning(log->lr->ld, l);
errno = save_errno;
}
@@ -295,12 +302,13 @@ void logv_add(struct log *log, const char *fmt, va_list ap)
maybe_print(log, l, oldlen);
}
void log_(struct log *log, enum log_level level, const char *fmt, ...)
void log_(struct log *log, enum log_level level, bool call_notifier,
const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
logv(log, level, fmt, ap);
logv(log, level, call_notifier, fmt, ap);
va_end(ap);
}
@@ -536,7 +544,7 @@ void log_backtrace_print(const char *fmt, ...)
return;
va_start(ap, fmt);
logv(crashlog, LOG_BROKEN, fmt, ap);
logv(crashlog, LOG_BROKEN, false, fmt, ap);
va_end(ap);
}
@@ -609,7 +617,7 @@ void fatal(const char *fmt, ...)
exit(1);
va_start(ap, fmt);
logv(crashlog, LOG_BROKEN, fmt, ap);
logv(crashlog, LOG_BROKEN, true, fmt, ap);
va_end(ap);
abort();
}