From 7219a1b54fb710e8260c476b44bfc97ff23c01f7 Mon Sep 17 00:00:00 2001 From: jszuminski Date: Thu, 4 Jul 2024 17:05:23 +0200 Subject: [PATCH] Logger: moved initLoggerOptions to initLogging method. --- bin/cli.js | 4 ++-- lib/logger.js | 25 ++++++++++++------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 16884d50..28e4aab1 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -15,7 +15,7 @@ See LICENSE file in root for details. import main from '../lib/index.js'; -import { initLoggerOptions } from '../lib/logger.js'; +import { initLogging } from '../lib/logger.js'; import ExportError from '../lib/errors/ExportError.js'; /** @@ -48,7 +48,7 @@ const start = async () => { // If all options correctly parsed if (options) { - initLoggerOptions(options.logging); + initLogging(options.logging); // Print initial logo or text main.printLogo(options.other.noLogo); diff --git a/lib/logger.js b/lib/logger.js index 5f320b48..1b0d17d8 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -50,14 +50,6 @@ let logging = { listeners: [] }; -export const initLoggerOptions = (loggingOptions) => { - for (const [key, value] of Object.entries(loggingOptions)) { - logging[key] = value; - } - - logging.toFile = false; -}; - /** * Logs the provided texts to a file, if file logging is enabled. It creates * the necessary directory structure if not already created and appends the @@ -235,15 +227,22 @@ export const enableFileLogging = (logDest, logFile) => { * * @param {Object} logging - The logging configuration object. */ -export const initLogging = (logging) => { +export const initLogging = (loggingOptions) => { + // Set all the logging options on our logging module object + for (const [key, value] of Object.entries(loggingOptions)) { + logging[key] = value; + } + + logging.toFile = false; + // Set the log level - setLogLevel(logging && parseInt(logging.level)); + setLogLevel(loggingOptions && parseInt(loggingOptions.level)); // Set the log file path and name - if (logging && logging.dest && logging.toFile) { + if (loggingOptions && loggingOptions.dest && loggingOptions.toFile) { enableFileLogging( - logging.dest, - logging.file || 'highcharts-export-server.log' + loggingOptions.dest, + loggingOptions.file || 'highcharts-export-server.log' ); } };