diff --git a/packages/common/services/console-logger.service.ts b/packages/common/services/console-logger.service.ts index addc3167303..cd81308bca7 100644 --- a/packages/common/services/console-logger.service.ts +++ b/packages/common/services/console-logger.service.ts @@ -23,6 +23,15 @@ const DEFAULT_LOG_LEVELS: LogLevel[] = [ 'verbose', ]; +const dateTimeFormatter = new Intl.DateTimeFormat(undefined, { + year: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + day: '2-digit', + month: '2-digit', +}); + @Injectable() export class ConsoleLogger implements LoggerService { private static lastTimestampAt?: number; @@ -162,18 +171,7 @@ export class ConsoleLogger implements LoggerService { } protected getTimestamp(): string { - const localeStringOptions = { - year: 'numeric', - hour: 'numeric', - minute: 'numeric', - second: 'numeric', - day: '2-digit', - month: '2-digit', - }; - return new Date(Date.now()).toLocaleString( - undefined, - localeStringOptions as Intl.DateTimeFormatOptions, - ); + return dateTimeFormatter.format(Date.now()); } protected printMessages( diff --git a/packages/common/services/logger.service.ts b/packages/common/services/logger.service.ts index 6f7f38712a8..31f2c4f9fbd 100644 --- a/packages/common/services/logger.service.ts +++ b/packages/common/services/logger.service.ts @@ -53,6 +53,15 @@ interface LogBufferRecord { const DEFAULT_LOGGER = new ConsoleLogger(); +const dateTimeFormatter = new Intl.DateTimeFormat(undefined, { + year: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + day: '2-digit', + month: '2-digit', +}); + @Injectable() export class Logger implements LoggerService { protected static logBuffer = new Array(); @@ -249,18 +258,7 @@ export class Logger implements LoggerService { } static getTimestamp() { - const localeStringOptions = { - year: 'numeric', - hour: 'numeric', - minute: 'numeric', - second: 'numeric', - day: '2-digit', - month: '2-digit', - }; - return new Date(Date.now()).toLocaleString( - undefined, - localeStringOptions as Intl.DateTimeFormatOptions, - ); + return dateTimeFormatter.format(Date.now()); } static overrideLogger(logger: LoggerService | LogLevel[] | boolean) {