diff --git a/api/src/__test__/core/log.test.ts b/api/src/__test__/core/log.test.ts new file mode 100644 index 0000000000..8bc696aa0c --- /dev/null +++ b/api/src/__test__/core/log.test.ts @@ -0,0 +1,30 @@ +import pretty from 'pino-pretty'; +import { expect, test } from 'vitest'; + +import { PRETTY_LOG_TIME_FORMAT } from '@app/core/log.constants.js'; + +const padTime = (value: number) => value.toString().padStart(2, '0'); + +test('pretty log timestamps keep local minutes instead of using the month token', () => { + const timestamp = '2026-03-15T20:21:34.611Z'; + const date = new Date(timestamp); + const expectedTime = `${padTime(date.getHours())}:${padTime(date.getMinutes())}:${padTime(date.getSeconds())}`; + + const prettify = pretty.prettyFactory({ + colorize: false, + translateTime: PRETTY_LOG_TIME_FORMAT, + }); + + const output = prettify({ + level: 30, + time: timestamp, + pid: 123, + hostname: 'tower', + msg: 'test message', + }); + + expect(output).toContain(`[${expectedTime}]`); + expect(output).toContain('INFO'); + expect(output).toContain('test message'); + expect(output).not.toContain('[16:03:34'); +}); diff --git a/api/src/core/log.constants.ts b/api/src/core/log.constants.ts new file mode 100644 index 0000000000..930449dc3f --- /dev/null +++ b/api/src/core/log.constants.ts @@ -0,0 +1 @@ +export const PRETTY_LOG_TIME_FORMAT = 'SYS:HH:MM:ss'; diff --git a/api/src/core/log.ts b/api/src/core/log.ts index eb859399e2..22433ff5b7 100644 --- a/api/src/core/log.ts +++ b/api/src/core/log.ts @@ -1,6 +1,7 @@ import pino from 'pino'; import pretty from 'pino-pretty'; +import { PRETTY_LOG_TIME_FORMAT } from '@app/core/log.constants.js'; import { API_VERSION, LOG_LEVEL, LOG_TYPE, PATHS_LOGS_FILE, SUPPRESS_LOGS } from '@app/environment.js'; export const levels = ['trace', 'debug', 'info', 'warn', 'error', 'fatal'] as const; @@ -36,7 +37,7 @@ const stream = SUPPRESS_LOGS levelFirst: false, ignore: 'hostname,pid', destination: logDestination, - translateTime: 'SYS:HH:mm:ss', + translateTime: PRETTY_LOG_TIME_FORMAT, customPrettifiers: { time: (timestamp: string | object) => `[${timestamp}`, level: (_logLevel: string | object, _key: string, log: any, extras: any) => {