mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 07:34:24 +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:
committed by
Christian Decker
parent
dfa062b06a
commit
afabbe0cb0
@@ -108,6 +108,10 @@ struct log_book *new_log_book(const tal_t *ctx,
|
|||||||
lr->init_time = time_now();
|
lr->init_time = time_now();
|
||||||
list_head_init(&lr->log);
|
list_head_init(&lr->log);
|
||||||
|
|
||||||
|
/* In case ltmp not initialized, do so now. */
|
||||||
|
if (!ltmp)
|
||||||
|
ltmp = tal_tmpctx(lr);
|
||||||
|
|
||||||
return 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)",
|
log_debug(log, "Log pruned %zu entries (mem %zu -> %zu)",
|
||||||
deleted, old_mem, log->lr->mem_used);
|
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)
|
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 opt_register_logging(struct log *log);
|
||||||
void crashlog_activate(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. */
|
/* Before the crashlog is activated, just prints to stderr. */
|
||||||
void NORETURN PRINTF_FMT(1,2) fatal(const char *fmt, ...);
|
void NORETURN PRINTF_FMT(1,2) fatal(const char *fmt, ...);
|
||||||
#endif /* LIGHTNING_LIGHTNINGD_LOG_H */
|
#endif /* LIGHTNING_LIGHTNINGD_LOG_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user