Skip to content

Commit

Permalink
stringify event before sending to console
Browse files Browse the repository at this point in the history
  • Loading branch information
SollyzDev committed Mar 27, 2024
1 parent 10de2dd commit 289b2b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class Logger {
// to send logs to Axiom without HTTP.
// This saves resources and time on lambda and edge functions
if (isVercel && (this.config.source === 'edge' || this.config.source === 'lambda')) {
this.logEvents.forEach((ev) => console.log(ev));
this.logEvents.forEach((ev) => console.log(JSON.stringify(ev)));
this.logEvents = [];
return;
}
Expand Down
17 changes: 6 additions & 11 deletions tests/vercelConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ test('logging to console when running on lambda', async () => {

await logger.flush();
expect(mockedConsole).toHaveBeenCalledTimes(1);
expect(mockedConsole).toHaveBeenCalledWith({
_time: time,
fields: {},
level: 'info',
message: 'hello, world!',
vercel: {
environment: 'test',
region: undefined,
source: 'lambda',
},
});

const calledWithPayload = JSON.parse(mockedConsole.mock.calls[0][0]);
expect(calledWithPayload.message).toEqual('hello, world!');
expect(calledWithPayload.level).toEqual('info');
expect(calledWithPayload._time).toEqual(time);
expect(calledWithPayload.vercel.source).toEqual('lambda');
});

0 comments on commit 289b2b8

Please sign in to comment.