mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
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>
This commit is contained in:
parent
dfa062b06a
commit
afabbe0cb0
@ -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)
|
||||
|
@ -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…
Reference in New Issue
Block a user