lightningd: move log_prefix and log_entry struct definitions into log.c.
They're only exposed because of the notifications, but they are better off with explicit parameters anyway. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -21,6 +21,24 @@
|
||||
/* Once we're up and running, this is set up. */
|
||||
struct logger *crashlog;
|
||||
|
||||
/* Reference counted log_prefix. Log entries keep a pointer, and they
|
||||
* can outlast the log entry point which created them. */
|
||||
struct log_prefix {
|
||||
size_t refcnt;
|
||||
const char *prefix;
|
||||
};
|
||||
|
||||
struct log_entry {
|
||||
struct timeabs time;
|
||||
enum log_level level;
|
||||
unsigned int skipped;
|
||||
struct node_id_cache *nc;
|
||||
struct log_prefix *prefix;
|
||||
char *log;
|
||||
/* Iff LOG_IO */
|
||||
const u8 *io;
|
||||
};
|
||||
|
||||
struct print_filter {
|
||||
/* In list log_book->print_filters / log_file->print_filters */
|
||||
struct list_node list;
|
||||
@@ -565,7 +583,11 @@ static void maybe_notify_log(struct logger *log,
|
||||
const struct log_entry *l)
|
||||
{
|
||||
if (l->level >= log->print_level)
|
||||
notify_log(log->log_book->ld, l);
|
||||
notify_log(log->log_book->ld,
|
||||
l->level,
|
||||
l->time,
|
||||
l->prefix->prefix,
|
||||
l->log);
|
||||
}
|
||||
|
||||
void logv(struct logger *log, enum log_level level,
|
||||
@@ -594,7 +616,11 @@ void logv(struct logger *log, enum log_level level,
|
||||
add_entry(log, &l);
|
||||
|
||||
if (call_notifier)
|
||||
notify_warning(log->log_book->ld, l);
|
||||
notify_warning(log->log_book->ld,
|
||||
l->level,
|
||||
l->time,
|
||||
l->prefix->prefix,
|
||||
l->log);
|
||||
|
||||
errno = save_errno;
|
||||
}
|
||||
|
||||
@@ -75,24 +75,6 @@ struct command_result *param_loglevel(struct command *cmd,
|
||||
const jsmntok_t *tok,
|
||||
enum log_level **level);
|
||||
|
||||
/* Reference counted log_prefix. Log entries keep a pointer, and they
|
||||
* can outlast the log entry point which created them. */
|
||||
struct log_prefix {
|
||||
size_t refcnt;
|
||||
const char *prefix;
|
||||
};
|
||||
|
||||
struct log_entry {
|
||||
struct timeabs time;
|
||||
enum log_level level;
|
||||
unsigned int skipped;
|
||||
struct node_id_cache *nc;
|
||||
struct log_prefix *prefix;
|
||||
char *log;
|
||||
/* Iff LOG_IO */
|
||||
const u8 *io;
|
||||
};
|
||||
|
||||
/* For options.c's listconfig */
|
||||
char *opt_log_level(const char *arg, struct log_book *log_book);
|
||||
void json_add_opt_log_levels(struct json_stream *response, struct log_book *log_book);
|
||||
|
||||
@@ -100,31 +100,38 @@ void notify_disconnect(struct lightningd *ld, const struct node_id *nodeid)
|
||||
/*'warning' is based on LOG_UNUSUAL/LOG_BROKEN level log
|
||||
*(in plugin module, they're 'warn'/'error' level). */
|
||||
static void warning_notification_serialize(struct json_stream *stream,
|
||||
struct log_entry *l)
|
||||
enum log_level level,
|
||||
struct timeabs time,
|
||||
const char *source,
|
||||
const char *logmsg)
|
||||
{
|
||||
/* Choose "BROKEN"/"UNUSUAL" to keep consistent with the habit
|
||||
* of plugin. But this may confuses the users who want to 'getlog'
|
||||
* with the level indicated by notifications. It is the duty of a
|
||||
* plugin to eliminate this misunderstanding. */
|
||||
json_add_string(stream, "level",
|
||||
l->level == LOG_BROKEN ? "error"
|
||||
level == LOG_BROKEN ? "error"
|
||||
: "warn");
|
||||
/* unsuaul/broken event is rare, plugin pay more attentions on
|
||||
* the absolute time, like when channels failed. */
|
||||
json_add_timestr(stream, "time", l->time.ts);
|
||||
json_add_timeiso(stream, "timestamp", l->time);
|
||||
json_add_string(stream, "source", l->prefix->prefix);
|
||||
json_add_string(stream, "log", l->log);
|
||||
json_add_timestr(stream, "time", time.ts);
|
||||
json_add_timeiso(stream, "timestamp", time);
|
||||
json_add_string(stream, "source", source);
|
||||
json_add_string(stream, "log", logmsg);
|
||||
}
|
||||
|
||||
REGISTER_NOTIFICATION(warning);
|
||||
|
||||
void notify_warning(struct lightningd *ld, struct log_entry *l)
|
||||
void notify_warning(struct lightningd *ld,
|
||||
enum log_level level,
|
||||
struct timeabs time,
|
||||
const char *source,
|
||||
const char *logmsg)
|
||||
{
|
||||
struct jsonrpc_notification *n = notify_start(ld, "warning");
|
||||
if (!n)
|
||||
return;
|
||||
warning_notification_serialize(n->stream, l);
|
||||
warning_notification_serialize(n->stream, level, time, source, logmsg);
|
||||
notify_send(ld, n);
|
||||
}
|
||||
|
||||
@@ -631,26 +638,33 @@ bool notify_deprecated_oneshot(struct lightningd *ld,
|
||||
REGISTER_NOTIFICATION(deprecated_oneshot);
|
||||
|
||||
static void log_notification_serialize(struct json_stream *stream,
|
||||
const struct log_entry *l)
|
||||
enum log_level level,
|
||||
struct timeabs time,
|
||||
const char *source,
|
||||
const char *logmsg)
|
||||
{
|
||||
json_add_string(stream, "level", log_level_name(l->level));
|
||||
json_add_timestr(stream, "time", l->time.ts);
|
||||
json_add_timeiso(stream, "timestamp", l->time);
|
||||
json_add_string(stream, "source", l->prefix->prefix);
|
||||
json_add_string(stream, "log", l->log);
|
||||
json_add_string(stream, "level", log_level_name(level));
|
||||
json_add_timestr(stream, "time", time.ts);
|
||||
json_add_timeiso(stream, "timestamp", time);
|
||||
json_add_string(stream, "source", source);
|
||||
json_add_string(stream, "log", logmsg);
|
||||
}
|
||||
|
||||
|
||||
REGISTER_NOTIFICATION(log);
|
||||
|
||||
void notify_log(struct lightningd *ld, const struct log_entry *l)
|
||||
void notify_log(struct lightningd *ld,
|
||||
enum log_level level,
|
||||
struct timeabs time,
|
||||
const char *source,
|
||||
const char *logmsg)
|
||||
{
|
||||
struct jsonrpc_notification *n;
|
||||
|
||||
n = notify_start(ld, "log");
|
||||
if (!n)
|
||||
return;
|
||||
log_notification_serialize(n->stream, l);
|
||||
log_notification_serialize(n->stream, level, time, source, logmsg);
|
||||
notify_send(ld, n);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,11 @@ void notify_connect(struct lightningd *ld,
|
||||
const struct wireaddr_internal *addr);
|
||||
void notify_disconnect(struct lightningd *ld, const struct node_id *nodeid);
|
||||
|
||||
void notify_warning(struct lightningd *ld, struct log_entry *l);
|
||||
void notify_warning(struct lightningd *ld,
|
||||
enum log_level level,
|
||||
struct timeabs time,
|
||||
const char *source,
|
||||
const char *logmsg);
|
||||
|
||||
void notify_custommsg(struct lightningd *ld,
|
||||
const struct node_id *peer_id,
|
||||
@@ -120,7 +124,11 @@ bool notify_deprecated_oneshot(struct lightningd *ld,
|
||||
/* Tell this plugin to shutdown: returns true if it was subscribed. */
|
||||
bool notify_plugin_shutdown(struct lightningd *ld, struct plugin *p);
|
||||
/* Inform the plugin when a log line is emitted */
|
||||
void notify_log(struct lightningd *ld, const struct log_entry *l);
|
||||
void notify_log(struct lightningd *ld,
|
||||
enum log_level level,
|
||||
struct timeabs time,
|
||||
const char *source,
|
||||
const char *logmsg);
|
||||
|
||||
void notify_plugin_started(struct lightningd *ld, struct plugin *plugin);
|
||||
void notify_plugin_stopped(struct lightningd *ld, struct plugin *plugin);
|
||||
|
||||
@@ -56,10 +56,18 @@ void json_stream_log_suppress_for_cmd(struct json_stream *js UNNEEDED,
|
||||
struct json_stream *json_stream_success(struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "json_stream_success called!\n"); abort(); }
|
||||
/* Generated stub for notify_log */
|
||||
void notify_log(struct lightningd *ld UNNEEDED, const struct log_entry *l UNNEEDED)
|
||||
void notify_log(struct lightningd *ld UNNEEDED,
|
||||
enum log_level level UNNEEDED,
|
||||
struct timeabs time UNNEEDED,
|
||||
const char *source UNNEEDED,
|
||||
const char *logmsg UNNEEDED)
|
||||
{ fprintf(stderr, "notify_log called!\n"); abort(); }
|
||||
/* Generated stub for notify_warning */
|
||||
void notify_warning(struct lightningd *ld UNNEEDED, struct log_entry *l UNNEEDED)
|
||||
void notify_warning(struct lightningd *ld UNNEEDED,
|
||||
enum log_level level UNNEEDED,
|
||||
struct timeabs time UNNEEDED,
|
||||
const char *source UNNEEDED,
|
||||
const char *logmsg UNNEEDED)
|
||||
{ fprintf(stderr, "notify_warning called!\n"); abort(); }
|
||||
/* AUTOGENERATED MOCKS END */
|
||||
|
||||
|
||||
@@ -11,7 +11,11 @@ static size_t test_fwrite(const void *ptr, size_t size, size_t nmemb,
|
||||
|
||||
#include "../log.c"
|
||||
|
||||
void notify_log(struct lightningd *ld UNNEEDED, const struct log_entry *l UNNEEDED)
|
||||
void notify_log(struct lightningd *ld UNNEEDED,
|
||||
enum log_level level UNNEEDED,
|
||||
struct timeabs time UNNEEDED,
|
||||
const char *source UNNEEDED,
|
||||
const char *logmsg UNNEEDED)
|
||||
{ }
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
@@ -67,7 +71,11 @@ void json_stream_log_suppress_for_cmd(struct json_stream *js UNNEEDED,
|
||||
struct json_stream *json_stream_success(struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "json_stream_success called!\n"); abort(); }
|
||||
/* Generated stub for notify_warning */
|
||||
void notify_warning(struct lightningd *ld UNNEEDED, struct log_entry *l UNNEEDED)
|
||||
void notify_warning(struct lightningd *ld UNNEEDED,
|
||||
enum log_level level UNNEEDED,
|
||||
struct timeabs time UNNEEDED,
|
||||
const char *source UNNEEDED,
|
||||
const char *logmsg UNNEEDED)
|
||||
{ fprintf(stderr, "notify_warning called!\n"); abort(); }
|
||||
/* AUTOGENERATED MOCKS END */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user