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"
|
2018-02-02 01:05:41 +01:00
|
|
|
#include <ccan/time/time.h>
|
2018-02-05 05:09:27 +01:00
|
|
|
#include <common/status.h>
|
2018-02-05 05:09:28 +01:00
|
|
|
#include <jsmn.h>
|
2016-01-21 21:11:47 +01:00
|
|
|
|
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;
|
|
|
|
|
2023-07-16 07:56:52 +02:00
|
|
|
/* We can have a single log book, with multiple loggers writing to it: it's freed
|
|
|
|
* by the last struct logger 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 */
|
2023-07-16 07:56:52 +02:00
|
|
|
struct logger *new_logger(const tal_t *ctx, struct log_book *record,
|
|
|
|
const struct node_id *default_node_id,
|
|
|
|
const char *fmt, ...) PRINTF_FMT(4,5);
|
2019-11-17 12:41:33 +01:00
|
|
|
|
2023-07-16 07:56:52 +02:00
|
|
|
#define log_debug(logger, ...) log_((logger), LOG_DBG, NULL, false, __VA_ARGS__)
|
|
|
|
#define log_info(logger, ...) log_((logger), LOG_INFORM, NULL, false, __VA_ARGS__)
|
|
|
|
#define log_unusual(logger, ...) log_((logger), LOG_UNUSUAL, NULL, true, __VA_ARGS__)
|
|
|
|
#define log_broken(logger, ...) log_((logger), LOG_BROKEN, NULL, true, __VA_ARGS__)
|
2019-11-17 12:41:33 +01:00
|
|
|
|
2023-07-16 07:56:52 +02:00
|
|
|
#define log_peer_debug(logger, nodeid, ...) log_((logger), LOG_DBG, nodeid, false, __VA_ARGS__)
|
|
|
|
#define log_peer_info(logger, nodeid, ...) log_((logger), LOG_INFORM, nodeid, false, __VA_ARGS__)
|
|
|
|
#define log_peer_unusual(logger, nodeid, ...) log_((logger), LOG_UNUSUAL, nodeid, true, __VA_ARGS__)
|
|
|
|
#define log_peer_broken(logger, nodeid, ...) log_((logger), LOG_BROKEN, nodeid, true, __VA_ARGS__)
|
2019-11-17 12:41:33 +01:00
|
|
|
|
2023-07-16 07:56:52 +02:00
|
|
|
void log_io(struct logger *logger, enum log_level dir,
|
2019-11-17 12:41:33 +01:00
|
|
|
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
|
|
|
|
2023-07-16 07:56:52 +02:00
|
|
|
void log_(struct logger *logger, enum log_level level,
|
2019-11-17 12:41:33 +01:00
|
|
|
const struct node_id *node_id,
|
|
|
|
bool call_notifier,
|
|
|
|
const char *fmt, ...)
|
|
|
|
PRINTF_FMT(5,6);
|
2023-07-16 07:56:52 +02:00
|
|
|
void logv(struct logger *logger, enum log_level level, const struct node_id *node_id,
|
2019-11-17 12:41:33 +01:00
|
|
|
bool call_notifier, const char *fmt, va_list ap);
|
2016-01-21 21:11:47 +01:00
|
|
|
|
2023-07-16 07:56:52 +02:00
|
|
|
const char *log_prefix(const struct logger *logger);
|
2023-07-17 09:35:22 +02:00
|
|
|
/* Is there any chance we do io-level logging for this node_id in log? */
|
|
|
|
bool log_has_io_logging(const struct logger *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 */
|
2023-07-16 07:56:52 +02:00
|
|
|
extern struct logger *crashlog;
|
2016-01-21 21:11:48 +01:00
|
|
|
void NORETURN PRINTF_FMT(1,2) fatal(const char *fmt, ...);
|
2022-03-01 18:22:15 +01:00
|
|
|
void NORETURN fatal_vfmt(const char *fmt, va_list ap);
|
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,
|
2023-07-16 07:56:52 +02:00
|
|
|
const struct log_book *log_book,
|
2019-11-18 01:27:15 +01:00
|
|
|
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
|
|
|
|
2021-11-24 20:59:18 +01:00
|
|
|
/* 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;
|
|
|
|
};
|
|
|
|
|
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;
|
2021-11-24 20:59:18 +01:00
|
|
|
struct log_prefix *prefix;
|
2019-11-18 01:26:27 +01:00
|
|
|
char *log;
|
|
|
|
/* Iff LOG_IO */
|
|
|
|
const u8 *io;
|
|
|
|
};
|
|
|
|
|
2019-11-18 01:27:17 +01:00
|
|
|
/* For options.c's listconfig */
|
2023-07-17 09:36:07 +02:00
|
|
|
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);
|
2023-07-16 07:56:52 +02:00
|
|
|
void logging_options_parsed(struct log_book *log_book);
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_LOG_H */
|