From 1a9a12e9183cc2e3829c60841e7116d06b9849c3 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Fri, 10 Apr 2020 17:36:29 +0200 Subject: [PATCH] fix: fatal exception and crash when log rotate signal event is called (#1774) fix #1709 --- src/lib/logger.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/logger.ts b/src/lib/logger.ts index 9e60b55f6..986dd5e27 100644 --- a/src/lib/logger.ts +++ b/src/lib/logger.ts @@ -150,7 +150,15 @@ function setup(logs, { logStart } = { logStart: true }) { } process.on('SIGUSR2', function() { - Logger.reopenFileStreams(); + // https://github.com/trentm/node-bunyan#stream-type-rotating-file + if (logger) { + /** + * Note on log rotation: Often you may be using external log rotation utilities like logrotate on Linux or logadm + * on SmartOS/Illumos. In those cases, unless your are ensuring "copy and truncate" semantics + * (via copytruncate with logrotate or -c with logadm) then the fd for your 'file' stream will change. + */ + logger.reopenFileStreams(); + } }); }