Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions api/src/__test__/core/log.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
1 change: 1 addition & 0 deletions api/src/core/log.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const PRETTY_LOG_TIME_FORMAT = 'SYS:HH:MM:ss';
3 changes: 2 additions & 1 deletion api/src/core/log.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) => {
Expand Down
Loading