mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
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:
committed by
Rusty Russell
parent
231703cc7f
commit
96135dab5e
@@ -155,7 +155,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
|
|||||||
* book to hold all the entries (and trims as necessary), and multiple
|
* book to hold all the entries (and trims as necessary), and multiple
|
||||||
* log objects which each can write into it, each with a unique
|
* log objects which each can write into it, each with a unique
|
||||||
* prefix. */
|
* prefix. */
|
||||||
ld->log_book = new_log_book(20*1024*1024, LOG_INFORM);
|
ld->log_book = new_log_book(ld, 20*1024*1024, LOG_INFORM);
|
||||||
/*~ Note the tal context arg (by convention, the first argument to any
|
/*~ Note the tal context arg (by convention, the first argument to any
|
||||||
* allocation function): ld->log will be implicitly freed when ld
|
* allocation function): ld->log will be implicitly freed when ld
|
||||||
* is. */
|
* is. */
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <lightningd/json.h>
|
#include <lightningd/json.h>
|
||||||
#include <lightningd/jsonrpc.h>
|
#include <lightningd/jsonrpc.h>
|
||||||
#include <lightningd/lightningd.h>
|
#include <lightningd/lightningd.h>
|
||||||
|
#include <lightningd/notification.h>
|
||||||
#include <lightningd/options.h>
|
#include <lightningd/options.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -102,7 +103,7 @@ static size_t prune_log(struct log_book *log)
|
|||||||
return deleted;
|
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)
|
enum log_level printlevel)
|
||||||
{
|
{
|
||||||
struct log_book *lr = tal_linkable(tal(NULL, struct log_book));
|
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 = log_to_stdout;
|
||||||
lr->print_level = printlevel;
|
lr->print_level = printlevel;
|
||||||
lr->init_time = time_now();
|
lr->init_time = time_now();
|
||||||
|
lr->ld = ld;
|
||||||
list_head_init(&lr->log);
|
list_head_init(&lr->log);
|
||||||
|
|
||||||
return lr;
|
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);
|
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;
|
int save_errno = errno;
|
||||||
struct log_entry *l = new_log_entry(log, level);
|
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);
|
maybe_print(log, l, 0);
|
||||||
|
|
||||||
add_entry(log, l);
|
add_entry(log, l);
|
||||||
|
|
||||||
|
if (call_notifier)
|
||||||
|
notify_warning(log->lr->ld, l);
|
||||||
|
|
||||||
errno = save_errno;
|
errno = save_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,12 +302,13 @@ void logv_add(struct log *log, const char *fmt, va_list ap)
|
|||||||
maybe_print(log, l, oldlen);
|
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_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
logv(log, level, fmt, ap);
|
logv(log, level, call_notifier, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,7 +544,7 @@ void log_backtrace_print(const char *fmt, ...)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
logv(crashlog, LOG_BROKEN, fmt, ap);
|
logv(crashlog, LOG_BROKEN, false, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,7 +617,7 @@ void fatal(const char *fmt, ...)
|
|||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
logv(crashlog, LOG_BROKEN, fmt, ap);
|
logv(crashlog, LOG_BROKEN, true, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ struct log_book {
|
|||||||
struct timeabs init_time;
|
struct timeabs init_time;
|
||||||
|
|
||||||
struct list_head log;
|
struct list_head log;
|
||||||
|
/* Although log_book will copy log entries to parent log_book
|
||||||
|
* (the log_book belongs to lightningd), a pointer to lightningd
|
||||||
|
* is more directly because the notification needs ld->plugins.
|
||||||
|
*/
|
||||||
|
struct lightningd *ld;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct log {
|
struct log {
|
||||||
@@ -48,26 +53,26 @@ struct log {
|
|||||||
const char *prefix;
|
const char *prefix;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* We can have a single log book, with multiple logs in it: it's freed by
|
/* We can have a single log book, with multiple logs in it: it's freed
|
||||||
* the last struct log itself. */
|
* by the last struct log itself. */
|
||||||
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);
|
enum log_level printlevel);
|
||||||
|
|
||||||
/* With different entry points */
|
/* With different entry points */
|
||||||
struct log *new_log(const tal_t *ctx, struct log_book *record, const char *fmt, ...) PRINTF_FMT(3,4);
|
struct log *new_log(const tal_t *ctx, struct log_book *record, const char *fmt, ...) PRINTF_FMT(3,4);
|
||||||
|
|
||||||
#define log_debug(log, ...) log_((log), LOG_DBG, __VA_ARGS__)
|
#define log_debug(log, ...) log_((log), LOG_DBG, false, __VA_ARGS__)
|
||||||
#define log_info(log, ...) log_((log), LOG_INFORM, __VA_ARGS__)
|
#define log_info(log, ...) log_((log), LOG_INFORM, false, __VA_ARGS__)
|
||||||
#define log_unusual(log, ...) log_((log), LOG_UNUSUAL, __VA_ARGS__)
|
#define log_unusual(log, ...) log_((log), LOG_UNUSUAL, true, __VA_ARGS__)
|
||||||
#define log_broken(log, ...) log_((log), LOG_BROKEN, __VA_ARGS__)
|
#define log_broken(log, ...) log_((log), LOG_BROKEN, true, __VA_ARGS__)
|
||||||
|
|
||||||
void log_io(struct log *log, enum log_level dir, const char *comment,
|
void log_io(struct log *log, enum log_level dir, const char *comment,
|
||||||
const void *data, size_t len);
|
const void *data, size_t len);
|
||||||
|
|
||||||
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, ...)
|
||||||
PRINTF_FMT(3,4);
|
PRINTF_FMT(4,5);
|
||||||
void log_add(struct log *log, const char *fmt, ...) PRINTF_FMT(2,3);
|
void log_add(struct log *log, const char *fmt, ...) PRINTF_FMT(2,3);
|
||||||
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);
|
||||||
void logv_add(struct log *log, const char *fmt, va_list ap);
|
void logv_add(struct log *log, const char *fmt, va_list ap);
|
||||||
|
|
||||||
enum log_level get_log_level(struct log_book *lr);
|
enum log_level get_log_level(struct log_book *lr);
|
||||||
|
|||||||
@@ -6,10 +6,13 @@ bool log_status_msg(struct log *log, const u8 *msg)
|
|||||||
char *entry, *who;
|
char *entry, *who;
|
||||||
u8 *data;
|
u8 *data;
|
||||||
enum log_level level;
|
enum log_level level;
|
||||||
|
bool call_notifier;
|
||||||
|
|
||||||
if (fromwire_status_log(msg, msg, &level, &entry)) {
|
if (fromwire_status_log(msg, msg, &level, &entry)) {
|
||||||
if (level != LOG_IO_IN && level != LOG_IO_OUT) {
|
if (level != LOG_IO_IN && level != LOG_IO_OUT) {
|
||||||
log_(log, level, "%s", entry);
|
call_notifier = (level == LOG_BROKEN ||
|
||||||
|
level == LOG_UNUSUAL)? true : false;
|
||||||
|
log_(log, level, call_notifier, "%s", entry);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (fromwire_status_io(msg, msg, &level, &who, &data)) {
|
} else if (fromwire_status_io(msg, msg, &level, &who, &data)) {
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ static void copy_to_parent_log(const char *prefix,
|
|||||||
else if (continued)
|
else if (continued)
|
||||||
log_add(parent_log, "%s ... %s", prefix, str);
|
log_add(parent_log, "%s ... %s", prefix, str);
|
||||||
else
|
else
|
||||||
log_(parent_log, level, "%s %s", prefix, str);
|
log_(parent_log, level, false, "%s %s", prefix, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void peer_update_features(struct peer *peer,
|
static void peer_update_features(struct peer *peer,
|
||||||
@@ -119,7 +119,7 @@ struct peer *new_peer(struct lightningd *ld, u64 dbid,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Max 128k per peer. */
|
/* Max 128k per peer. */
|
||||||
peer->log_book = new_log_book(128*1024, get_log_level(ld->log_book));
|
peer->log_book = new_log_book(peer->ld, 128*1024, get_log_level(ld->log_book));
|
||||||
set_log_outfn(peer->log_book, copy_to_parent_log, ld->log);
|
set_log_outfn(peer->log_book, copy_to_parent_log, ld->log);
|
||||||
list_add_tail(&ld->peers, &peer->list);
|
list_add_tail(&ld->peers, &peer->list);
|
||||||
tal_add_destructor(peer, destroy_peer);
|
tal_add_destructor(peer, destroy_peer);
|
||||||
|
|||||||
@@ -196,6 +196,7 @@ static void plugin_log_handle(struct plugin *plugin, const jsmntok_t *paramstok)
|
|||||||
{
|
{
|
||||||
const jsmntok_t *msgtok, *leveltok;
|
const jsmntok_t *msgtok, *leveltok;
|
||||||
enum log_level level;
|
enum log_level level;
|
||||||
|
bool call_notifier;
|
||||||
msgtok = json_get_member(plugin->buffer, paramstok, "message");
|
msgtok = json_get_member(plugin->buffer, paramstok, "message");
|
||||||
leveltok = json_get_member(plugin->buffer, paramstok, "level");
|
leveltok = json_get_member(plugin->buffer, paramstok, "level");
|
||||||
|
|
||||||
@@ -222,7 +223,8 @@ static void plugin_log_handle(struct plugin *plugin, const jsmntok_t *paramstok)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_(plugin->log, level, "%.*s", msgtok->end - msgtok->start,
|
call_notifier = (level == LOG_BROKEN || level == LOG_UNUSUAL)? true : false;
|
||||||
|
log_(plugin->log, level, call_notifier, "%.*s", msgtok->end - msgtok->start,
|
||||||
plugin->buffer + msgtok->start);
|
plugin->buffer + msgtok->start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ void jsonrpc_setup(struct lightningd *ld UNNEEDED)
|
|||||||
void load_channels_from_wallet(struct lightningd *ld UNNEEDED)
|
void load_channels_from_wallet(struct lightningd *ld UNNEEDED)
|
||||||
{ fprintf(stderr, "load_channels_from_wallet called!\n"); abort(); }
|
{ fprintf(stderr, "load_channels_from_wallet called!\n"); abort(); }
|
||||||
/* Generated stub for log_ */
|
/* Generated stub for log_ */
|
||||||
void log_(struct log *log UNNEEDED, enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)
|
void log_(struct log *log UNNEEDED, enum log_level level UNNEEDED, bool call_notifier UNNEEDED, const char *fmt UNNEEDED, ...)
|
||||||
|
|
||||||
{ fprintf(stderr, "log_ called!\n"); abort(); }
|
{ fprintf(stderr, "log_ called!\n"); abort(); }
|
||||||
/* Generated stub for log_backtrace_exit */
|
/* Generated stub for log_backtrace_exit */
|
||||||
@@ -125,7 +125,7 @@ bool log_status_msg(struct log *log UNNEEDED, const u8 *msg UNNEEDED)
|
|||||||
struct log *new_log(const tal_t *ctx UNNEEDED, struct log_book *record UNNEEDED, const char *fmt UNNEEDED, ...)
|
struct log *new_log(const tal_t *ctx UNNEEDED, struct log_book *record UNNEEDED, const char *fmt UNNEEDED, ...)
|
||||||
{ fprintf(stderr, "new_log called!\n"); abort(); }
|
{ fprintf(stderr, "new_log called!\n"); abort(); }
|
||||||
/* Generated stub for new_log_book */
|
/* Generated stub for new_log_book */
|
||||||
struct log_book *new_log_book(size_t max_mem UNNEEDED,
|
struct log_book *new_log_book(struct lightningd *ld UNNEEDED, size_t max_mem UNNEEDED,
|
||||||
enum log_level printlevel UNNEEDED)
|
enum log_level printlevel UNNEEDED)
|
||||||
{ fprintf(stderr, "new_log_book called!\n"); abort(); }
|
{ fprintf(stderr, "new_log_book called!\n"); abort(); }
|
||||||
/* Generated stub for new_topology */
|
/* Generated stub for new_topology */
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ void kill_uncommitted_channel(struct uncommitted_channel *uc UNNEEDED,
|
|||||||
const char *why UNNEEDED)
|
const char *why UNNEEDED)
|
||||||
{ fprintf(stderr, "kill_uncommitted_channel called!\n"); abort(); }
|
{ fprintf(stderr, "kill_uncommitted_channel called!\n"); abort(); }
|
||||||
/* Generated stub for log_ */
|
/* Generated stub for log_ */
|
||||||
void log_(struct log *log UNNEEDED, enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)
|
void log_(struct log *log UNNEEDED, enum log_level level UNNEEDED, bool call_notifier UNNEEDED, const char *fmt UNNEEDED, ...)
|
||||||
|
|
||||||
{ fprintf(stderr, "log_ called!\n"); abort(); }
|
{ fprintf(stderr, "log_ called!\n"); abort(); }
|
||||||
/* Generated stub for log_add */
|
/* Generated stub for log_add */
|
||||||
@@ -262,7 +262,7 @@ struct bolt11 *new_bolt11(const tal_t *ctx UNNEEDED,
|
|||||||
struct log *new_log(const tal_t *ctx UNNEEDED, struct log_book *record UNNEEDED, const char *fmt UNNEEDED, ...)
|
struct log *new_log(const tal_t *ctx UNNEEDED, struct log_book *record UNNEEDED, const char *fmt UNNEEDED, ...)
|
||||||
{ fprintf(stderr, "new_log called!\n"); abort(); }
|
{ fprintf(stderr, "new_log called!\n"); abort(); }
|
||||||
/* Generated stub for new_log_book */
|
/* Generated stub for new_log_book */
|
||||||
struct log_book *new_log_book(size_t max_mem UNNEEDED,
|
struct log_book *new_log_book(struct lightningd *ld UNNEEDED, size_t max_mem UNNEEDED,
|
||||||
enum log_level printlevel UNNEEDED)
|
enum log_level printlevel UNNEEDED)
|
||||||
{ fprintf(stderr, "new_log_book called!\n"); abort(); }
|
{ fprintf(stderr, "new_log_book called!\n"); abort(); }
|
||||||
/* Generated stub for new_reltimer_ */
|
/* Generated stub for new_reltimer_ */
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ bool json_to_txid(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
|||||||
struct bitcoin_txid *txid UNNEEDED)
|
struct bitcoin_txid *txid UNNEEDED)
|
||||||
{ fprintf(stderr, "json_to_txid called!\n"); abort(); }
|
{ fprintf(stderr, "json_to_txid called!\n"); abort(); }
|
||||||
/* Generated stub for log_ */
|
/* Generated stub for log_ */
|
||||||
void log_(struct log *log UNNEEDED, enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)
|
void log_(struct log *log UNNEEDED, enum log_level level UNNEEDED, bool call_notifier UNNEEDED, const char *fmt UNNEEDED, ...)
|
||||||
|
|
||||||
{ fprintf(stderr, "log_ called!\n"); abort(); }
|
{ fprintf(stderr, "log_ called!\n"); abort(); }
|
||||||
/* Generated stub for log_io */
|
/* Generated stub for log_io */
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
static void db_test_fatal(const char *fmt, ...);
|
static void db_test_fatal(const char *fmt, ...);
|
||||||
#define db_fatal db_test_fatal
|
#define db_fatal db_test_fatal
|
||||||
|
|
||||||
static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, const char *fmt UNUSED, ...)
|
static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, bool call_notifier UNUSED, const char *fmt UNUSED, ...)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#define log_ db_log_
|
#define log_ db_log_
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ static void wallet_test_fatal(const char *fmt, ...);
|
|||||||
#define db_fatal wallet_test_fatal
|
#define db_fatal wallet_test_fatal
|
||||||
#include "test_utils.h"
|
#include "test_utils.h"
|
||||||
|
|
||||||
static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, const char *fmt UNUSED, ...)
|
static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, bool call_notifier UNUSED, const char *fmt UNUSED, ...)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#define log_ db_log_
|
#define log_ db_log_
|
||||||
@@ -647,7 +647,7 @@ struct log *new_log(const tal_t *ctx UNNEEDED, struct log_book *record UNNEEDED,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct log_book *new_log_book(size_t max_mem UNNEEDED,
|
struct log_book *new_log_book(struct lightningd *ld UNNEEDED, size_t max_mem UNNEEDED,
|
||||||
enum log_level printlevel UNNEEDED)
|
enum log_level printlevel UNNEEDED)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user