Skip to content

Commit 09c79cd

Browse files
fix: store log timestamps in ISO format (#333)
1 parent b6159f0 commit 09c79cd

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/lib/api-logs-transport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ApiLogsTransport extends Transport {
4545
let message = getWinstonMessageContent(info);
4646
message = message.length > ApiLogsTransport.MAX_MESSAGE_LEN ? `${message.slice(0, ApiLogsTransport.MAX_MESSAGE_LEN - 3)}...` : message;
4747

48-
this.logBuffer.push({ message, level, timestamp: timestamp as string, scope: scope as string });
48+
this.logBuffer.push({ message, level, timestamp: new Date(timestamp as string).toISOString(), scope: scope as string });
4949
const bufferLength = this.logBuffer.length;
5050
const bufferOverflow = bufferLength - this.maxBufferSize;
5151

test/unit/lib/api-logs-transport.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useSandboxWithFakeTimers } from '../../utils.js';
88
describe('ApiLogsTransport', () => {
99
let sandbox: sinon.SinonSandbox;
1010
let socket: sinon.SinonStubbedInstance<Socket>;
11+
const timestamp = '2025-10-27 20:00:00 +01:00';
1112
const ACK_DELAY = 50;
1213

1314
const setEmitWithAckResponse = (response: string) => {
@@ -20,7 +21,7 @@ describe('ApiLogsTransport', () => {
2021

2122
const createTransportAndLogger = (options: ApiTransportOptions) => {
2223
const transport = new ApiLogsTransport({ ...options, socket });
23-
const logger = winston.createLogger({ transports: [ transport ] });
24+
const logger = winston.createLogger({ defaultMeta: { timestamp }, transports: [ transport ] });
2425

2526
return { transport, logger };
2627
};
@@ -67,6 +68,7 @@ describe('ApiLogsTransport', () => {
6768

6869
transport.on('logged', (info) => {
6970
expect(info).to.have.property('message', 'test log');
71+
expect(info).to.have.property('timestamp', timestamp);
7072
done();
7173
});
7274

@@ -130,6 +132,7 @@ describe('ApiLogsTransport', () => {
130132
const payload = socket.emitWithAck.firstCall.args[1];
131133
expect(payload.logs).to.have.lengthOf(1);
132134
expect(payload.logs[0]).to.have.property('message', 'test');
135+
expect(payload.logs[0]).to.have.property('timestamp', new Date(timestamp).toISOString());
133136
expect(payload.skipped).to.equal(0);
134137

135138
await sandbox.clock.tickAsync(1000);

0 commit comments

Comments
 (0)