mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
log: Append the current time to the crash log filename
This should make it easier to identify the latest crash file and correlate crashes with external monitoring tools.
This commit is contained in:
@@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
their capacity or their `htlc_minimum_msat` parameter (#1777)
|
||||
- We now try to connect to all known addresses for a peer, not just
|
||||
the one given or the first one announced.
|
||||
- Crash logs are now placed one-per file like `crash.log.20180822233752`
|
||||
|
||||
### Deprecated
|
||||
|
||||
|
||||
@@ -569,18 +569,22 @@ static void log_dump_to_file(int fd, const struct log_book *lr)
|
||||
void log_backtrace_exit(void)
|
||||
{
|
||||
int fd;
|
||||
char logfile[sizeof("/tmp/lightning-crash.log.%u") + STR_MAX_CHARS(int)];
|
||||
char timebuf[sizeof("YYYYmmddHHMMSS")];
|
||||
char logfile[sizeof("/tmp/lightning-crash.log.") + sizeof(timebuf)];
|
||||
struct timeabs time = time_now();
|
||||
|
||||
strftime(timebuf, sizeof(timebuf), "%Y%m%d%H%M%S", gmtime(&time.ts.tv_sec));
|
||||
|
||||
if (!crashlog)
|
||||
return;
|
||||
|
||||
/* We expect to be in config dir. */
|
||||
snprintf(logfile, sizeof(logfile), "crash.log.%u", getpid());
|
||||
snprintf(logfile, sizeof(logfile), "crash.log.%s", timebuf);
|
||||
|
||||
fd = open(logfile, O_WRONLY|O_CREAT|O_TRUNC, 0600);
|
||||
if (fd < 0) {
|
||||
snprintf(logfile, sizeof(logfile),
|
||||
"/tmp/lightning-crash.log.%u", getpid());
|
||||
"/tmp/lightning-crash.log.%s", timebuf);
|
||||
fd = open(logfile, O_WRONLY|O_CREAT|O_TRUNC, 0600);
|
||||
}
|
||||
|
||||
|
||||
@@ -875,8 +875,11 @@ def test_logging(node_factory):
|
||||
def test_crashlog(node_factory):
|
||||
l1 = node_factory.get_node(may_fail=True)
|
||||
|
||||
crashpath = os.path.join(l1.daemon.lightning_dir,
|
||||
'crash.log.{}'.format(l1.daemon.proc.pid))
|
||||
assert not os.path.exists(crashpath)
|
||||
def has_crash_log(n):
|
||||
files = os.listdir(n.daemon.lightning_dir)
|
||||
crashfiles = [f for f in files if 'crash.log' in f]
|
||||
return len(crashfiles) > 0
|
||||
|
||||
assert not has_crash_log(l1)
|
||||
l1.daemon.proc.send_signal(signal.SIGSEGV)
|
||||
wait_for(lambda: os.path.exists(crashpath))
|
||||
wait_for(lambda: has_crash_log(l1))
|
||||
|
||||
Reference in New Issue
Block a user