From a418c77b250374b03ad7e8433b254b2fb0080fa0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 8 Sep 2023 22:56:44 +0200 Subject: [PATCH] refactor: ensure logPrefix helper is always used MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Helpers.ts | 2 +- src/utils/Configuration.ts | 21 ++++++++++++++------- src/worker/WorkerUtils.ts | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/charging-station/Helpers.ts b/src/charging-station/Helpers.ts index 068bc6c9..90ecd0e8 100644 --- a/src/charging-station/Helpers.ts +++ b/src/charging-station/Helpers.ts @@ -714,7 +714,7 @@ const warnDeprecatedTemplateKey = ( isNotEmptyString(logMsgToAppend) ? `. ${logMsgToAppend}` : '' }`; logger.warn(`${logPrefix} ${logMsg}`); - console.warn(chalk.yellow(`${logMsg}`)); + console.warn(`${chalk.green(logPrefix)} ${chalk.yellow(logMsg)}`); } }; diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 190a31a3..bf691fa8 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -6,7 +6,14 @@ import chalk from 'chalk'; import merge from 'just-merge'; import { Constants } from './Constants'; -import { hasOwnProp, isCFEnvironment, isNotEmptyString, isUndefined, once } from './Utils'; +import { + hasOwnProp, + isCFEnvironment, + isNotEmptyString, + isUndefined, + logPrefix, + once, +} from './Utils'; import { ApplicationProtocol, type ConfigurationData, @@ -114,6 +121,10 @@ export class Configuration { ); } + private static logPrefix = (): string => { + return logPrefix(' Simulator configuration |'); + }; + private static isConfigurationSectionCached(sectionName: ConfigurationSection): boolean { return Configuration.configurationSectionCache.has(sectionName); } @@ -287,10 +298,6 @@ export class Configuration { return workerConfiguration; } - private static logPrefix = (): string => { - return `${new Date().toLocaleString()} Simulator configuration |`; - }; - private static checkDeprecatedConfigurationKeys() { // connection timeout Configuration.warnDeprecatedConfigurationKey( @@ -555,9 +562,9 @@ export class Configuration { file: string, fileType: FileType, error: NodeJS.ErrnoException, - logPrefix: string, + logPfx: string, ): void { - const prefix = isNotEmptyString(logPrefix) ? `${logPrefix} ` : ''; + const prefix = isNotEmptyString(logPfx) ? `${logPfx} ` : ''; let logMsg: string; switch (error.code) { case 'ENOENT': diff --git a/src/worker/WorkerUtils.ts b/src/worker/WorkerUtils.ts index 452f8cfe..e930a47f 100644 --- a/src/worker/WorkerUtils.ts +++ b/src/worker/WorkerUtils.ts @@ -15,5 +15,5 @@ export const defaultExitHandler = (code: number): void => { }; export const defaultErrorHandler = (error: Error): void => { - console.error(chalk.red('Worker errored: ', error)); + console.error(chalk.red('Worker errored: '), error); }; -- 2.34.1