-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[server/logging] Allow opting out of UTC (#14705)
* [server/logging] make use of UTC configurable * [server/logging/tests] try removing TZ from moment * [server/log/formatJson] use strict equality checks * [server/log/format] note in method name that time is extracted (cherry picked from commit b79ba98)
- Loading branch information
Showing
7 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import moment from 'moment'; | ||
import expect from 'expect.js'; | ||
|
||
import { | ||
createListStream, | ||
createPromiseFromStreams, | ||
} from '../../../utils'; | ||
|
||
import KbnLoggerJsonFormat from '../log_format_json'; | ||
|
||
const time = +moment('2010-01-01T05:15:59Z', moment.ISO_8601); | ||
|
||
const makeEvent = () => ({ | ||
event: 'log', | ||
timestamp: time, | ||
tags: ['tag'], | ||
pid: 1, | ||
data: 'my log message' | ||
}); | ||
|
||
describe('KbnLoggerJsonFormat', () => { | ||
it('logs in UTC when useUTC is true', async () => { | ||
const format = new KbnLoggerJsonFormat({ | ||
useUTC: true | ||
}); | ||
|
||
const result = await createPromiseFromStreams([ | ||
createListStream([makeEvent()]), | ||
format | ||
]); | ||
|
||
const { '@timestamp': timestamp } = JSON.parse(result); | ||
expect(timestamp).to.be(moment.utc(time).format()); | ||
}); | ||
|
||
it('logs in local timezone when useUTC is false', async () => { | ||
const format = new KbnLoggerJsonFormat({ | ||
useUTC: false | ||
}); | ||
|
||
const result = await createPromiseFromStreams([ | ||
createListStream([makeEvent()]), | ||
format | ||
]); | ||
|
||
const { '@timestamp': timestamp } = JSON.parse(result); | ||
expect(timestamp).to.be(moment(time).format()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import moment from 'moment'; | ||
import expect from 'expect.js'; | ||
|
||
import { | ||
createListStream, | ||
createPromiseFromStreams, | ||
} from '../../../utils'; | ||
|
||
import KbnLoggerStringFormat from '../log_format_string'; | ||
|
||
const time = +moment('2010-01-01T05:15:59Z', moment.ISO_8601); | ||
|
||
const makeEvent = () => ({ | ||
event: 'log', | ||
timestamp: time, | ||
tags: ['tag'], | ||
pid: 1, | ||
data: 'my log message' | ||
}); | ||
|
||
describe('KbnLoggerStringFormat', () => { | ||
it('logs in UTC when useUTC is true', async () => { | ||
const format = new KbnLoggerStringFormat({ | ||
useUTC: true | ||
}); | ||
|
||
const result = await createPromiseFromStreams([ | ||
createListStream([makeEvent()]), | ||
format | ||
]); | ||
|
||
expect(String(result)) | ||
.to.contain(moment.utc(time).format('HH:mm:ss.SSS')); | ||
}); | ||
|
||
it('logs in local timezone when useUTC is false', async () => { | ||
const format = new KbnLoggerStringFormat({ | ||
useUTC: false | ||
}); | ||
|
||
const result = await createPromiseFromStreams([ | ||
createListStream([makeEvent()]), | ||
format | ||
]); | ||
|
||
expect(String(result)).to | ||
.contain(moment(time).format('HH:mm:ss.SSS')); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters