From 3a2a6b7a1ab4021baff13cee7f3713e96ed95c1d Mon Sep 17 00:00:00 2001 From: idinium96 <47635037+idinium96@users.noreply.github.com> Date: Fri, 27 May 2022 00:52:29 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=F0=9F=94=87=20an=20option=20to=20disa?= =?UTF-8?q?ble=20saving=20log=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/Options.ts | 2 ++ src/lib/logger.ts | 62 +++++++++++++++++++++++------------------ template.ecosystem.json | 1 + template.env | 1 + 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/classes/Options.ts b/src/classes/Options.ts index c5df1cf8a..44b47accc 100644 --- a/src/classes/Options.ts +++ b/src/classes/Options.ts @@ -2007,6 +2007,7 @@ export default interface Options extends JsonOptions { debug?: boolean; debugFile?: boolean; + enableSaveLogFile?: boolean; folderName?: string; filePrefix?: string; @@ -2260,6 +2261,7 @@ export function loadOptions(options?: Options): Options { debug: getOption('debug', true, jsonParseBoolean, incomingOptions), debugFile: getOption('debugFile', true, jsonParseBoolean, incomingOptions), + enableSaveLogFile: getOption('enableSaveLogFile', true, jsonParseBoolean, incomingOptions), enableHttpApi: getOption('enableHttpApi', false, jsonParseBoolean, incomingOptions), httpApiPort: getOption('httpApiPort', 3001, jsonParseNumber, incomingOptions) diff --git a/src/lib/logger.ts b/src/lib/logger.ts index 340a1f82f..960d8c464 100644 --- a/src/lib/logger.ts +++ b/src/lib/logger.ts @@ -103,33 +103,41 @@ export function init(paths: Paths, options: Options): void { const debugConsole = options.debug; // Debug to file is enabled by default const debugFile = options.debugFile; - - const transports = [ - { - type: 'DailyRotateFile', - filename: paths.logs.log, - level: debugFile ? 'debug' : 'verbose', - filter: 'private', - datePattern: 'YYYY-MM-DD', - zippedArchive: true, - maxFiles: '14d' - }, - { - type: 'File', - filename: paths.logs.trade, - level: 'trade', - filter: 'trade' - }, - { - type: 'File', - filename: paths.logs.error, - level: 'error' - }, - { - type: 'Console', - level: debugConsole ? 'debug' : 'verbose' - } - ]; + const enableSaveLogs = options.enableSaveLogFile; + + const transports = enableSaveLogs + ? [ + { + type: 'DailyRotateFile', + filename: paths.logs.log, + level: debugFile ? 'debug' : 'verbose', + filter: 'private', + datePattern: 'YYYY-MM-DD', + zippedArchive: true, + maxFiles: '14d' + }, + { + type: 'File', + filename: paths.logs.trade, + level: 'trade', + filter: 'trade' + }, + { + type: 'File', + filename: paths.logs.error, + level: 'error' + }, + { + type: 'Console', + level: debugConsole ? 'debug' : 'verbose' + } + ] + : [ + { + type: 'Console', + level: debugConsole ? 'debug' : 'verbose' + } + ]; transports.forEach(transport => { const type = transport.type; diff --git a/template.ecosystem.json b/template.ecosystem.json index a606e9dba..217da01a6 100644 --- a/template.ecosystem.json +++ b/template.ecosystem.json @@ -42,6 +42,7 @@ "DEBUG": true, "DEBUG_FILE": true, + "ENABLE_SAVE_LOG_FILE": true, "ENABLE_HTTP_API": false, "HTTP_API_PORT": 3001 diff --git a/template.env b/template.env index 76c682e4f..c47611675 100644 --- a/template.env +++ b/template.env @@ -29,6 +29,7 @@ TIME_ADDITIONAL_NOTES="" DEBUG=true DEBUG_FILE=true +ENABLE_SAVE_LOG_FILE=true ENABLE_HTTP_API=false HTTP_API_PORT=3001