From 4986d6b39d47f163b7e48e377674f1d770016423 Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Thu, 21 Feb 2019 22:54:39 +0100 Subject: [PATCH] feat: block of newlines when attaching a logfile This will make the logger write 4 newlines to re-attached logfiles. The newlines wont appear on logfiles that are just created. Additionally the server prints 50 '-' dashes before printing his startup message, which also help increase readability on logfile. This was inspired by the way Bitcoin Core handles logfiles. --- lightningd/lightningd.c | 1 + lightningd/log.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 056ce3a92..b26441d99 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -799,6 +799,7 @@ int main(int argc, char *argv[]) * log. And tal_hex() is a helper from utils which returns a hex string; * it's assumed that the argument was allocated with tal or tal_arr * so it can use tal_bytelen() to get the length. */ + log_info(ld->log, "--------------------------------------------------"); log_info(ld->log, "Server started with public key %s, alias %s (color #%s) and lightningd %s", type_to_string(tmpctx, struct pubkey, &ld->id), json_escape(tmpctx, (const char *)ld->alias)->s, diff --git a/lightningd/log.c b/lightningd/log.c index 787cf4ce8..ef02ced2c 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -504,6 +504,7 @@ char *arg_log_to_file(const char *arg, struct lightningd *ld) { const struct log_entry *i; FILE *logf; + int size; if (ld->logfile) { fclose(ld->log->lr->print_arg); @@ -517,6 +518,11 @@ char *arg_log_to_file(const char *arg, struct lightningd *ld) return tal_fmt(NULL, "Failed to open: %s", strerror(errno)); set_log_outfn(ld->log->lr, log_to_file, logf); + /* For convenience make a block of empty lines just like Bitcoin Core */ + size = ftell(logf); + if (size > 0) + fprintf(logf, "\n\n\n\n"); + /* Catch up */ list_for_each(&ld->log->lr->log, i, list) maybe_print(ld->log, i, 0);