2017-08-28 18:06:01 +02:00
|
|
|
#ifndef LIGHTNING_LIGHTNINGD_LOG_H
|
|
|
|
#define LIGHTNING_LIGHTNINGD_LOG_H
|
2016-01-21 21:11:47 +01:00
|
|
|
#include "config.h"
|
plugin: Add new notification type: warning
This notification bases on `LOG_BROKEN` and `LOG_UNUSUAL` level log.
--Introduction
A notification for topic `warning` is sent every time a new `BROKEN`/
`UNUSUAL` level(in plugins, we use `error`/`warn`) log generated, which
means an unusual/borken thing happens, such as channel failed,
message resolving failed...
```json
{
"warning": {
"level": "warn",
"time": "1559743608.565342521",
"source": "lightningd(17652): 0821f80652fb840239df8dc99205792bba2e559a05469915804c08420230e23c7c chan #7854:",
"log": "Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: sent ERROR bad reestablish dataloss msg"
}
}
```
1. `level` is `warn` or `error`:
`warn` means something seems bad happened and it's under control, but
we'd better check it;
`error` means something extremely bad is out of control, and it may lead
to crash;
2. `time` is the second since epoch;
3. `source`, in fact, is the `prefix` of the log_entry. It means where
the event happened, it may have the following forms:
`<node_id> chan #<db_id_of_channel>:`, `lightningd(<lightningd_pid>):`,
`plugin-<plugin_name>:`, `<daemon_name>(<daemon_pid>):`, `jsonrpc:`,
`jcon fd <error_fd_to_jsonrpc>:`, `plugin-manager`;
4. `log` is the context of the original log entry.
--Note:
1. The main code uses `UNUSUAL`/`BROKEN`, and plugin module uses `warn`
/`error`, considering the consistency with plugin, warning choose `warn`
/`error`. But users who use c-lightning with plugins may want to
`getlog` with specified level when receive warning. It's the duty for
plugin dev to turn `warn`/`error` into `UNUSUAL`/`BROKEN` and present it
to the users, or pass it directly to `getlog`;
2. About time, `json_log()` in `log` module uses the Relative Time, from
the time when `log_book` inited to the time when this event happend.
But I consider the `UNUSUAL`/`BROKEN` event is rare, and it is very
likely to happen after running for a long time, so for users, they will
pay more attention to Absolute Time.
-- Related Change
1. Remove the definitions of `log`, `log_book`, `log_entry` from `log.c`
to `log.h`, then they can be used in warning declaration and definition.
2. Remove `void json_add_time(struct json_stream *result, const char
*fieldname, struct timespec ts)` from `log.c` to `json.c`, and add
related declaration in `json.h`. Now the notification function in
`notification.c` can call it.
2. Add a pointer to `struct lightningd` in `struct log_book`. This may
affect the independence of the `log` module, but storing a pointer to
`ld` is more direct;
2019-06-03 20:26:58 +02:00
|
|
|
#include <ccan/list/list.h>
|
2016-01-21 21:11:47 +01:00
|
|
|
#include <ccan/tal/tal.h>
|
2018-02-02 01:05:41 +01:00
|
|
|
#include <ccan/time/time.h>
|
2016-01-21 21:11:47 +01:00
|
|
|
#include <ccan/typesafe_cb/typesafe_cb.h>
|
2018-02-05 05:09:27 +01:00
|
|
|
#include <common/status.h>
|
2017-08-28 18:02:01 +02:00
|
|
|
#include <common/type_to_string.h>
|
2018-02-05 05:09:28 +01:00
|
|
|
#include <jsmn.h>
|
2016-01-21 21:11:47 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2018-08-15 16:40:37 +02:00
|
|
|
struct command;
|
2018-10-19 03:17:49 +02:00
|
|
|
struct json_stream;
|
2018-01-29 01:30:15 +01:00
|
|
|
struct lightningd;
|
2019-11-17 12:41:33 +01:00
|
|
|
struct node_id;
|
2016-01-21 21:11:47 +01:00
|
|
|
struct timerel;
|
|
|
|
|
2019-06-06 10:26:42 +02:00
|
|
|
/* We can have a single log book, with multiple logs in it: it's freed
|
|
|
|
* by the last struct log itself. */
|
2019-11-18 01:27:17 +01:00
|
|
|
struct log_book *new_log_book(struct lightningd *ld, size_t max_mem);
|
2016-01-21 21:11:47 +01:00
|
|
|
|
|
|
|
/* With different entry points */
|
2019-11-17 12:41:33 +01:00
|
|
|
struct log *new_log(const tal_t *ctx, struct log_book *record,
|
|
|
|
const struct node_id *default_node_id,
|
|
|
|
const char *fmt, ...) PRINTF_FMT(4,5);
|
|
|
|
|
|
|
|
#define log_debug(log, ...) log_((log), LOG_DBG, NULL, false, __VA_ARGS__)
|
|
|
|
#define log_info(log, ...) log_((log), LOG_INFORM, NULL, false, __VA_ARGS__)
|
|
|
|
#define log_unusual(log, ...) log_((log), LOG_UNUSUAL, NULL, true, __VA_ARGS__)
|
|
|
|
#define log_broken(log, ...) log_((log), LOG_BROKEN, NULL, true, __VA_ARGS__)
|
|
|
|
|
|
|
|
#define log_peer_debug(log, nodeid, ...) log_((log), LOG_DBG, nodeid, false, __VA_ARGS__)
|
|
|
|
#define log_peer_info(log, nodeid, ...) log_((log), LOG_INFORM, nodeid, false, __VA_ARGS__)
|
|
|
|
#define log_peer_unusual(log, nodeid, ...) log_((log), LOG_UNUSUAL, nodeid, true, __VA_ARGS__)
|
|
|
|
#define log_peer_broken(log, nodeid, ...) log_((log), LOG_BROKEN, nodeid, true, __VA_ARGS__)
|
|
|
|
|
|
|
|
void log_io(struct log *log, enum log_level dir,
|
|
|
|
const struct node_id *node_id,
|
|
|
|
const char *comment,
|
2018-02-05 05:09:28 +01:00
|
|
|
const void *data, size_t len);
|
2016-01-21 21:11:47 +01:00
|
|
|
|
2019-11-17 12:41:33 +01:00
|
|
|
void log_(struct log *log, enum log_level level,
|
|
|
|
const struct node_id *node_id,
|
|
|
|
bool call_notifier,
|
|
|
|
const char *fmt, ...)
|
|
|
|
PRINTF_FMT(5,6);
|
|
|
|
void logv(struct log *log, enum log_level level, const struct node_id *node_id,
|
|
|
|
bool call_notifier, const char *fmt, va_list ap);
|
2016-01-21 21:11:47 +01:00
|
|
|
|
|
|
|
const char *log_prefix(const struct log *log);
|
2019-11-18 01:27:17 +01:00
|
|
|
enum log_level log_print_level(struct log *log);
|
2016-01-21 21:11:47 +01:00
|
|
|
|
2018-01-29 01:30:15 +01:00
|
|
|
void opt_register_logging(struct lightningd *ld);
|
2016-01-21 21:11:48 +01:00
|
|
|
|
2018-01-29 01:30:15 +01:00
|
|
|
char *arg_log_to_file(const char *arg, struct lightningd *ld);
|
|
|
|
|
2018-03-29 04:06:45 +02:00
|
|
|
/* Once this is set, we dump fatal with a backtrace to this log */
|
|
|
|
extern struct log *crashlog;
|
2016-01-21 21:11:48 +01:00
|
|
|
void NORETURN PRINTF_FMT(1,2) fatal(const char *fmt, ...);
|
2017-10-31 01:04:59 +01:00
|
|
|
|
2018-03-29 04:06:45 +02:00
|
|
|
void log_backtrace_print(const char *fmt, ...);
|
|
|
|
void log_backtrace_exit(void);
|
|
|
|
|
2018-02-05 05:09:28 +01:00
|
|
|
/* Adds an array showing log entries */
|
2018-10-19 03:17:49 +02:00
|
|
|
void json_add_log(struct json_stream *result,
|
2019-11-18 01:27:15 +01:00
|
|
|
const struct log_book *lr,
|
|
|
|
const struct node_id *node_id,
|
|
|
|
enum log_level minlevel);
|
2018-02-05 05:09:28 +01:00
|
|
|
|
2018-12-16 05:50:06 +01:00
|
|
|
struct command_result *param_loglevel(struct command *cmd,
|
|
|
|
const char *name,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
enum log_level **level);
|
2018-02-05 05:09:28 +01:00
|
|
|
|
2019-11-18 01:26:27 +01:00
|
|
|
struct log_entry {
|
|
|
|
struct timeabs time;
|
|
|
|
enum log_level level;
|
|
|
|
unsigned int skipped;
|
2019-11-18 01:27:17 +01:00
|
|
|
struct node_id_cache *nc;
|
2019-11-18 01:26:27 +01:00
|
|
|
const char *prefix;
|
|
|
|
char *log;
|
|
|
|
/* Iff LOG_IO */
|
|
|
|
const u8 *io;
|
|
|
|
};
|
|
|
|
|
2019-11-18 01:27:17 +01:00
|
|
|
/* For options.c's listconfig */
|
|
|
|
char *opt_log_level(const char *arg, struct log *log);
|
|
|
|
void json_add_opt_log_levels(struct json_stream *response, struct log *log);
|
|
|
|
void logging_options_parsed(struct log_book *lr);
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_LOG_H */
|