Skip to content

Commit

Permalink
Add process.uptime to the json logger (elastic#171873)
Browse files Browse the repository at this point in the history
  • Loading branch information
afharo authored Nov 24, 2023
1 parent 87213e7 commit 1a4ac01
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { EcsVersion } from '@kbn/ecs';
import { LogLevel, LogRecord } from '@kbn/logging';
import { JsonLayout } from './json_layout';

jest.spyOn(process, 'uptime').mockReturnValue(10);

const timestamp = new Date(Date.UTC(2012, 1, 1, 14, 30, 22, 11));
const records: LogRecord[] = [
{
Expand Down Expand Up @@ -121,6 +123,7 @@ test('`format()` correctly formats record with meta-data', () => {
},
process: {
pid: 5355,
uptime: 10,
},
});
});
Expand Down Expand Up @@ -169,6 +172,7 @@ test('`format()` correctly formats error record with meta-data', () => {
},
process: {
pid: 5355,
uptime: 10,
},
});
});
Expand Down Expand Up @@ -202,6 +206,7 @@ test('format() meta can merge override logs', () => {
},
process: {
pid: 3,
uptime: 10,
},
});
});
Expand Down Expand Up @@ -232,6 +237,7 @@ test('format() meta can not override message', () => {
},
process: {
pid: 3,
uptime: 10,
},
});
});
Expand Down Expand Up @@ -262,6 +268,7 @@ test('format() meta can not override ecs version', () => {
},
process: {
pid: 3,
uptime: 10,
},
});
});
Expand Down Expand Up @@ -295,6 +302,7 @@ test('format() meta can not override logger or level', () => {
},
process: {
pid: 3,
uptime: 10,
},
});
});
Expand Down Expand Up @@ -325,6 +333,7 @@ test('format() meta can not override timestamp', () => {
},
process: {
pid: 3,
uptime: 10,
},
});
});
Expand Down Expand Up @@ -359,6 +368,7 @@ test('format() meta can not override tracing properties', () => {
},
process: {
pid: 3,
uptime: 10,
},
span: { id: 'span_override' },
trace: { id: 'trace_override' },
Expand Down Expand Up @@ -404,6 +414,7 @@ test('format() meta.toJSON() is used if own property', () => {
},
process: {
pid: 3,
uptime: 10,
},
server: {
address: 'localhost',
Expand Down Expand Up @@ -448,6 +459,7 @@ test('format() meta.toJSON() is used if present on prototype', () => {
},
process: {
pid: 3,
uptime: 10,
},
foo: 'bar',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class JsonLayout implements Layout {
},
process: {
pid: record.pid,
uptime: process.uptime(),
},
span: spanId ? { id: spanId } : undefined,
trace: traceId ? { id: traceId } : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let system: LoggingSystem;
beforeEach(() => {
mockConsoleLog = jest.spyOn(global.console, 'log').mockReturnValue(undefined);
jest.spyOn<any, any>(global, 'Date').mockImplementation(() => timestamp);
jest.spyOn(process, 'uptime').mockReturnValue(10);
system = new LoggingSystem();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe('Error logging', () => {
name: 'ResponseError',
process: {
pid: expect.any(Number),
uptime: expect.any(Number),
},
});
}
Expand Down

0 comments on commit 1a4ac01

Please sign in to comment.