Browse Source

log: add ltmp convenience context.

It's sometimes nicer where you don't have a convenient tmpctx.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
afabbe0cb0
  1. 10
      lightningd/log.c
  2. 4
      lightningd/log.h

10
lightningd/log.c

@ -108,6 +108,10 @@ struct log_book *new_log_book(const tal_t *ctx,
lr->init_time = time_now();
list_head_init(&lr->log);
/* In case ltmp not initialized, do so now. */
if (!ltmp)
ltmp = tal_tmpctx(lr);
return lr;
}
@ -185,6 +189,12 @@ static void add_entry(struct log *log, struct log_entry *l)
log_debug(log, "Log pruned %zu entries (mem %zu -> %zu)",
deleted, old_mem, log->lr->mem_used);
}
/* Free up temporaries now if any */
if (tal_first(ltmp)) {
tal_free(ltmp);
ltmp = tal_tmpctx(log->lr);
}
}
static struct log_entry *new_log_entry(struct log *log, enum log_level level)

4
lightningd/log.h

@ -129,6 +129,10 @@ void log_dump_to_file(int fd, const struct log_book *lr);
void opt_register_logging(struct log *log);
void crashlog_activate(struct log *log);
/* Convenience parent for temporary allocations (eg. type_to_string)
* during log calls; freed after every log_*() */
const tal_t *ltmp;
/* Before the crashlog is activated, just prints to stderr. */
void NORETURN PRINTF_FMT(1,2) fatal(const char *fmt, ...);
#endif /* LIGHTNING_LIGHTNINGD_LOG_H */

Loading…
Cancel
Save