Skip to content

Commit 620b7c2

Browse files
chore: update logic
1 parent 4a9f464 commit 620b7c2

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

packages/collector/src/logger.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ exports.init = function init(userConfig = {}) {
123123
const pinoOpts = {
124124
...parentLogger.levels,
125125
level: parentLogger.level || 'info',
126-
base: parentLogger.bindings()
126+
base: parentLogger.bindings(),
127+
timestamp: () => `,"time":"${new Date().toISOString()}"`
127128
};
128129

129130
// CASE: Either its the customers pino instance (and probably a different pino installation/version)
@@ -134,18 +135,14 @@ exports.init = function init(userConfig = {}) {
134135
const symbols = Object.getOwnPropertySymbols(instance);
135136

136137
// CASE: We copy any settings from the pino instance such as custom formats.
137-
if (symbols && Array.isArray(symbols)) {
138+
if (userConfig.logger && symbols && Array.isArray(symbols)) {
138139
// If there's a custom timestamp function from the userConfig logger , we'll respect that
139140
const timeSym = symbols.find(sym => String(sym) === 'Symbol(pino.time)');
140141
// @ts-ignore
141142
const timestampFn = instance[timeSym];
142143

143-
// Only use the user's timestamp function if it's from a user-provided logger
144-
if (timestampFn && userConfig.logger) {
144+
if (timestampFn) {
145145
pinoOpts.timestamp = timestampFn;
146-
} else if (!pinoOpts.timestamp) {
147-
// If no timestamp function is set yet, fallback to ISO format
148-
pinoOpts.timestamp = () => `,"time":"${new Date().toISOString()}"`;
149146
}
150147

151148
const formattersSym = symbols.find(sym => String(sym) === 'Symbol(pino.formatters)');

packages/collector/test/logger_test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,13 @@ describe('logger', () => {
151151
}
152152
};
153153

154-
// Replace the stream temporarily
155154
const originalStream = logger.logger[uninstrumentedLogger.symbols.streamSym];
156155
logger.logger[uninstrumentedLogger.symbols.streamSym] = mockStream;
157156

158157
logger.info('Test log message');
159158

160-
// Restore the original stream
161159
logger.logger[uninstrumentedLogger.symbols.streamSym] = originalStream;
162160

163-
// Verify the timestamp format in the captured log
164161
expect(capturedLogs.length).to.equal(1);
165162
expect(capturedLogs[0]).to.have.property('time');
166163
expect(capturedLogs[0].time).to.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/);

0 commit comments

Comments
 (0)