Browse Source

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.
htlc_accepted_hook
trueptolemy 6 years ago
committed by Rusty Russell
parent
commit
96135dab5e
  1. 2
      lightningd/lightningd.c
  2. 20
      lightningd/log.c
  3. 25
      lightningd/log.h
  4. 5
      lightningd/log_status.c
  5. 4
      lightningd/peer_control.c
  6. 4
      lightningd/plugin.c
  7. 4
      lightningd/test/run-find_my_abspath.c
  8. 4
      lightningd/test/run-invoice-select-inchan.c
  9. 2
      lightningd/test/run-jsonrpc.c
  10. 2
      wallet/test/run-db.c
  11. 4
      wallet/test/run-wallet.c

2
lightningd/lightningd.c

@ -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
* log objects which each can write into it, each with a unique
* 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
* allocation function): ld->log will be implicitly freed when ld
* is. */

20
lightningd/log.c

@ -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();
}

25
lightningd/log.h

@ -41,6 +41,11 @@ struct log_book {
struct timeabs init_time;
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 {
@ -48,26 +53,26 @@ struct log {
const char *prefix;
};
/* We can have a single log book, with multiple logs in it: it's freed by
* the last struct log itself. */
struct log_book *new_log_book(size_t max_mem,
/* We can have a single log book, with multiple logs in it: it's freed
* by the last struct log itself. */
struct log_book *new_log_book(struct lightningd *ld, size_t max_mem,
enum log_level printlevel);
/* With different entry points */
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_info(log, ...) log_((log), LOG_INFORM, __VA_ARGS__)
#define log_unusual(log, ...) log_((log), LOG_UNUSUAL, __VA_ARGS__)
#define log_broken(log, ...) log_((log), LOG_BROKEN, __VA_ARGS__)
#define log_debug(log, ...) log_((log), LOG_DBG, false, __VA_ARGS__)
#define log_info(log, ...) log_((log), LOG_INFORM, false, __VA_ARGS__)
#define log_unusual(log, ...) log_((log), LOG_UNUSUAL, true, __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,
const void *data, size_t len);
void log_(struct log *log, enum log_level level, const char *fmt, ...)
PRINTF_FMT(3,4);
void log_(struct log *log, enum log_level level, bool call_notifier, const char *fmt, ...)
PRINTF_FMT(4,5);
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);
enum log_level get_log_level(struct log_book *lr);

5
lightningd/log_status.c

@ -6,10 +6,13 @@ bool log_status_msg(struct log *log, const u8 *msg)
char *entry, *who;
u8 *data;
enum log_level level;
bool call_notifier;
if (fromwire_status_log(msg, msg, &level, &entry)) {
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;
}
} else if (fromwire_status_io(msg, msg, &level, &who, &data)) {

4
lightningd/peer_control.c

@ -81,7 +81,7 @@ static void copy_to_parent_log(const char *prefix,
else if (continued)
log_add(parent_log, "%s ... %s", prefix, str);
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,
@ -119,7 +119,7 @@ struct peer *new_peer(struct lightningd *ld, u64 dbid,
#endif
/* 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);
list_add_tail(&ld->peers, &peer->list);
tal_add_destructor(peer, destroy_peer);

4
lightningd/plugin.c

@ -196,6 +196,7 @@ static void plugin_log_handle(struct plugin *plugin, const jsmntok_t *paramstok)
{
const jsmntok_t *msgtok, *leveltok;
enum log_level level;
bool call_notifier;
msgtok = json_get_member(plugin->buffer, paramstok, "message");
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;
}
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);
}

4
lightningd/test/run-find_my_abspath.c

@ -106,7 +106,7 @@ void jsonrpc_setup(struct lightningd *ld UNNEEDED)
void load_channels_from_wallet(struct lightningd *ld UNNEEDED)
{ fprintf(stderr, "load_channels_from_wallet called!\n"); abort(); }
/* 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(); }
/* 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, ...)
{ fprintf(stderr, "new_log called!\n"); abort(); }
/* 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)
{ fprintf(stderr, "new_log_book called!\n"); abort(); }
/* Generated stub for new_topology */

4
lightningd/test/run-invoice-select-inchan.c

@ -244,7 +244,7 @@ void kill_uncommitted_channel(struct uncommitted_channel *uc UNNEEDED,
const char *why UNNEEDED)
{ fprintf(stderr, "kill_uncommitted_channel called!\n"); abort(); }
/* 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(); }
/* 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, ...)
{ fprintf(stderr, "new_log called!\n"); abort(); }
/* 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)
{ fprintf(stderr, "new_log_book called!\n"); abort(); }
/* Generated stub for new_reltimer_ */

2
lightningd/test/run-jsonrpc.c

@ -39,7 +39,7 @@ bool json_to_txid(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct bitcoin_txid *txid UNNEEDED)
{ fprintf(stderr, "json_to_txid called!\n"); abort(); }
/* 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(); }
/* Generated stub for log_io */

2
wallet/test/run-db.c

@ -3,7 +3,7 @@
static void db_test_fatal(const char *fmt, ...);
#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_

4
wallet/test/run-wallet.c

@ -4,7 +4,7 @@ static void wallet_test_fatal(const char *fmt, ...);
#define db_fatal wallet_test_fatal
#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_
@ -647,7 +647,7 @@ struct log *new_log(const tal_t *ctx UNNEEDED, struct log_book *record UNNEEDED,
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)
{
return NULL;

Loading…
Cancel
Save