Updating logger to display timestamp
This commit is contained in:
parent
09e4b3a1b8
commit
f8747ea045
2 changed files with 14 additions and 5 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import { AsyncLocalStorage } from 'async_hooks'
|
import { AsyncLocalStorage } from 'async_hooks'
|
||||||
|
import dayjs from './dayjs'
|
||||||
|
|
||||||
export enum LogLevel {
|
export enum LogLevel {
|
||||||
DEBUG,
|
DEBUG,
|
||||||
|
|
@ -42,8 +43,9 @@ export class Logger {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
let fmtString = '<%s> [%s] %s: %s'
|
let fmtString = '(%s) <%s> [%s] %s: %s'
|
||||||
const params: Array<unknown> = [
|
const params: Array<unknown> = [
|
||||||
|
dayjs().format(),
|
||||||
this.tag,
|
this.tag,
|
||||||
this.correlationId,
|
this.correlationId,
|
||||||
levelString,
|
levelString,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
|
import dayjs from '../../../src/common/dayjs'
|
||||||
import { Logger, LogLevel } from '../../../src/common/logger'
|
import { Logger, LogLevel } from '../../../src/common/logger'
|
||||||
|
|
||||||
|
jest.useFakeTimers().setSystemTime(new Date('2023-01-01'))
|
||||||
|
|
||||||
describe('Logger', () => {
|
describe('Logger', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks()
|
jest.resetAllMocks()
|
||||||
|
|
@ -19,7 +22,8 @@ describe('Logger', () => {
|
||||||
expect(consoleLogSpy).toHaveBeenCalledTimes(2)
|
expect(consoleLogSpy).toHaveBeenCalledTimes(2)
|
||||||
expect(consoleLogSpy).toHaveBeenNthCalledWith(
|
expect(consoleLogSpy).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
'<%s> [%s] %s: %s',
|
'(%s) <%s> [%s] %s: %s',
|
||||||
|
dayjs().format(),
|
||||||
'tag',
|
'tag',
|
||||||
'abc',
|
'abc',
|
||||||
'DEBUG',
|
'DEBUG',
|
||||||
|
|
@ -27,7 +31,8 @@ describe('Logger', () => {
|
||||||
)
|
)
|
||||||
expect(consoleLogSpy).toHaveBeenNthCalledWith(
|
expect(consoleLogSpy).toHaveBeenNthCalledWith(
|
||||||
2,
|
2,
|
||||||
'<%s> [%s] %s: %s',
|
'(%s) <%s> [%s] %s: %s',
|
||||||
|
dayjs().format(),
|
||||||
'tag',
|
'tag',
|
||||||
'abc',
|
'abc',
|
||||||
'INFO',
|
'INFO',
|
||||||
|
|
@ -35,7 +40,8 @@ describe('Logger', () => {
|
||||||
)
|
)
|
||||||
expect(consoleErrorSpy).toHaveBeenCalledTimes(1)
|
expect(consoleErrorSpy).toHaveBeenCalledTimes(1)
|
||||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||||
'<%s> [%s] %s: %s - %O',
|
'(%s) <%s> [%s] %s: %s - %O',
|
||||||
|
dayjs().format(),
|
||||||
'tag',
|
'tag',
|
||||||
'abc',
|
'abc',
|
||||||
'ERROR',
|
'ERROR',
|
||||||
|
|
@ -66,7 +72,8 @@ describe('Logger', () => {
|
||||||
expect(consoleLogSpy).toHaveBeenCalledTimes(1)
|
expect(consoleLogSpy).toHaveBeenCalledTimes(1)
|
||||||
expect(consoleLogSpy).toHaveBeenNthCalledWith(
|
expect(consoleLogSpy).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
'<%s> [%s] %s: %s - %O',
|
'(%s) <%s> [%s] %s: %s - %O',
|
||||||
|
dayjs().format(),
|
||||||
'tag',
|
'tag',
|
||||||
'abc',
|
'abc',
|
||||||
'INFO',
|
'INFO',
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue