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"
|
|
|
|
#include <ccan/tal/tal.h>
|
|
|
|
#include <ccan/typesafe_cb/typesafe_cb.h>
|
2017-08-28 18:02:01 +02:00
|
|
|
#include <common/type_to_string.h>
|
2016-01-21 21:11:47 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
struct timerel;
|
|
|
|
|
|
|
|
enum log_level {
|
|
|
|
/* Logging all IO. */
|
|
|
|
LOG_IO,
|
|
|
|
/* Gory details which are mainly good for debugging. */
|
|
|
|
LOG_DBG,
|
|
|
|
/* Information about what's going in. */
|
|
|
|
LOG_INFORM,
|
|
|
|
/* That's strange... */
|
|
|
|
LOG_UNUSUAL,
|
|
|
|
/* That's really bad, we're broken. */
|
|
|
|
LOG_BROKEN
|
|
|
|
};
|
|
|
|
|
2017-01-10 05:48:26 +01:00
|
|
|
/* We can have a single log book, with multiple logs in it. */
|
|
|
|
struct log_book *new_log_book(const tal_t *ctx,
|
|
|
|
size_t max_mem,
|
|
|
|
enum log_level printlevel);
|
2016-01-21 21:11:47 +01:00
|
|
|
|
|
|
|
/* With different entry points */
|
2017-09-15 04:18:52 +02:00
|
|
|
struct log *new_log(const tal_t *ctx, struct log_book *record, const char *fmt, ...) PRINTF_FMT(3,4);
|
2016-01-21 21:11:47 +01:00
|
|
|
|
|
|
|
#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__)
|
|
|
|
|
|
|
|
void log_io(struct log *log, bool in, const void *data, size_t len);
|
|
|
|
|
|
|
|
void log_(struct log *log, enum log_level level, const char *fmt, ...)
|
|
|
|
PRINTF_FMT(3,4);
|
|
|
|
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);
|
2017-06-20 02:39:17 +02:00
|
|
|
void logv_add(struct log *log, const char *fmt, va_list ap);
|
2016-01-21 21:11:47 +01:00
|
|
|
|
2017-02-24 06:52:56 +01:00
|
|
|
enum log_level get_log_level(struct log_book *lr);
|
2017-01-10 05:48:26 +01:00
|
|
|
void set_log_level(struct log_book *lr, enum log_level level);
|
2016-01-21 21:11:47 +01:00
|
|
|
void set_log_prefix(struct log *log, const char *prefix);
|
|
|
|
const char *log_prefix(const struct log *log);
|
2016-01-21 21:11:47 +01:00
|
|
|
#define set_log_outfn(lr, print, arg) \
|
|
|
|
set_log_outfn_((lr), \
|
|
|
|
typesafe_cb_preargs(void, void *, (print), (arg),\
|
|
|
|
const char *, \
|
|
|
|
enum log_level, \
|
|
|
|
bool, \
|
|
|
|
const char *), (arg))
|
|
|
|
|
2017-01-10 05:48:26 +01:00
|
|
|
void set_log_outfn_(struct log_book *lr,
|
2016-01-21 21:11:47 +01:00
|
|
|
void (*print)(const char *prefix,
|
|
|
|
enum log_level level,
|
|
|
|
bool continued,
|
|
|
|
const char *str, void *arg),
|
|
|
|
void *arg);
|
2016-01-21 21:11:47 +01:00
|
|
|
|
2017-01-10 05:48:26 +01:00
|
|
|
size_t log_max_mem(const struct log_book *lr);
|
|
|
|
size_t log_used(const struct log_book *lr);
|
|
|
|
const struct timeabs *log_init_time(const struct log_book *lr);
|
2016-01-21 21:11:47 +01:00
|
|
|
|
|
|
|
#define log_each_line(lr, func, arg) \
|
|
|
|
log_each_line_((lr), \
|
|
|
|
typesafe_cb_preargs(void, void *, (func), (arg), \
|
|
|
|
unsigned int, \
|
|
|
|
struct timerel, \
|
|
|
|
enum log_level, \
|
|
|
|
const char *, \
|
|
|
|
const char *), (arg))
|
|
|
|
|
2017-01-10 05:48:26 +01:00
|
|
|
void log_each_line_(const struct log_book *lr,
|
2016-01-21 21:11:47 +01:00
|
|
|
void (*func)(unsigned int skipped,
|
|
|
|
struct timerel time,
|
|
|
|
enum log_level level,
|
|
|
|
const char *prefix,
|
|
|
|
const char *log,
|
|
|
|
void *arg),
|
|
|
|
void *arg);
|
|
|
|
|
|
|
|
|
2017-01-10 05:48:26 +01:00
|
|
|
void log_dump_to_file(int fd, const struct log_book *lr);
|
2016-01-21 21:11:47 +01:00
|
|
|
void opt_register_logging(struct log *log);
|
2017-09-12 06:56:45 +02:00
|
|
|
void crashlog_activate(const char *argv0, struct log *log);
|
2016-01-21 21:11:48 +01:00
|
|
|
|
2017-09-12 13:49:37 +02:00
|
|
|
/* Convenience parent for temporary allocations (eg. type_to_string)
|
|
|
|
* during log calls; freed after every log_*() */
|
|
|
|
const tal_t *ltmp;
|
|
|
|
|
2016-01-21 21:11:48 +01:00
|
|
|
/* Before the crashlog is activated, just prints to stderr. */
|
|
|
|
void NORETURN PRINTF_FMT(1,2) fatal(const char *fmt, ...);
|
2017-10-31 01:04:59 +01:00
|
|
|
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_LOG_H */
|