Skip to content

Commit

Permalink
Logger: moved initLoggerOptions to initLogging method.
Browse files Browse the repository at this point in the history
  • Loading branch information
jszuminski committed Jul 4, 2024
1 parent f6e9b1a commit 7219a1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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);
Expand Down
25 changes: 12 additions & 13 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
);
}
};
Expand Down

0 comments on commit 7219a1b

Please sign in to comment.