Browse Source

lightningd: move log structs into log.c.

Simply better encapsulation.   We still need to expose log_entry, since the
notification hook uses it though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-debug
Rusty Russell 5 years ago
parent
commit
3270e5c843
  1. 45
      lightningd/log.c
  2. 55
      lightningd/log.h

45
lightningd/log.c

@ -32,6 +32,35 @@
/* Once we're up and running, this is set up. */
struct log *crashlog;
struct log_book {
size_t mem_used;
size_t max_mem;
void (*print)(const char *prefix,
enum log_level level,
const struct node_id *node_id,
bool continued,
const struct timeabs *time,
const char *str,
const u8 *io, size_t io_len,
void *arg);
void *print_arg;
enum log_level print_level;
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 {
struct log_book *lr;
const struct node_id *default_node_id;
const char *prefix;
};
static const char *level_prefix(enum log_level level)
{
switch (level) {
@ -188,17 +217,6 @@ enum log_level get_log_level(struct log_book *lr)
return lr->print_level;
}
void set_log_level(struct log_book *lr, enum log_level level)
{
lr->print_level = level;
}
void set_log_prefix(struct log *log, const char *prefix)
{
/* log->lr owns this, since it keeps a pointer to it. */
log->prefix = tal_strdup(log->lr, prefix);
}
void set_log_outfn_(struct log_book *lr,
void (*print)(const char *prefix,
enum log_level level,
@ -463,7 +481,7 @@ static char *arg_log_level(const char *arg, struct log *log)
for (i = 0; i < ARRAY_SIZE(log_levels); i++) {
if (strcasecmp(arg, log_levels[i].name) == 0) {
set_log_level(log->lr, log_levels[i].level);
log->lr->print_level = log_levels[i].level;
return NULL;
}
}
@ -485,7 +503,8 @@ static void show_log_level(char buf[OPT_SHOW_LEN], const struct log *log)
static char *arg_log_prefix(const char *arg, struct log *log)
{
set_log_prefix(log, arg);
/* log->lr owns this, since it keeps a pointer to it. */
log->prefix = tal_strdup(log->lr, arg);
return NULL;
}

55
lightningd/log.h

@ -16,47 +16,6 @@ struct lightningd;
struct node_id;
struct timerel;
struct log_entry {
struct list_node list;
struct timeabs time;
enum log_level level;
unsigned int skipped;
struct node_id *node_id;
const char *prefix;
char *log;
/* Iff LOG_IO */
const u8 *io;
};
struct log_book {
size_t mem_used;
size_t max_mem;
void (*print)(const char *prefix,
enum log_level level,
const struct node_id *node_id,
bool continued,
const struct timeabs *time,
const char *str,
const u8 *io, size_t io_len,
void *arg);
void *print_arg;
enum log_level print_level;
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 {
struct log_book *lr;
const struct node_id *default_node_id;
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(struct lightningd *ld, size_t max_mem,
@ -93,8 +52,6 @@ void logv(struct log *log, enum log_level level, const struct node_id *node_id,
void logv_add(struct log *log, const char *fmt, va_list ap);
enum log_level get_log_level(struct log_book *lr);
void set_log_level(struct log_book *lr, enum log_level level);
void set_log_prefix(struct log *log, const char *prefix);
const char *log_prefix(const struct log *log);
struct log_book *get_log_book(const struct log *log);
@ -169,4 +126,16 @@ struct command_result *param_loglevel(struct command *cmd,
const jsmntok_t *tok,
enum log_level **level);
struct log_entry {
struct list_node list;
struct timeabs time;
enum log_level level;
unsigned int skipped;
struct node_id *node_id;
const char *prefix;
char *log;
/* Iff LOG_IO */
const u8 *io;
};
#endif /* LIGHTNING_LIGHTNINGD_LOG_H */

Loading…
Cancel
Save