Updating logger to display timestamp

This commit is contained in:
Collin Duncan 2023-01-20 15:37:15 +01:00
parent 09e4b3a1b8
commit f8747ea045
No known key found for this signature in database
2 changed files with 14 additions and 5 deletions

View file

@ -1,4 +1,5 @@
import { AsyncLocalStorage } from 'async_hooks'
import dayjs from './dayjs'
export enum LogLevel {
DEBUG,
@ -42,8 +43,9 @@ export class Logger {
break
}
let fmtString = '<%s> [%s] %s: %s'
let fmtString = '(%s) <%s> [%s] %s: %s'
const params: Array<unknown> = [
dayjs().format(),
this.tag,
this.correlationId,
levelString,

View file

@ -1,5 +1,8 @@
import dayjs from '../../../src/common/dayjs'
import { Logger, LogLevel } from '../../../src/common/logger'
jest.useFakeTimers().setSystemTime(new Date('2023-01-01'))
describe('Logger', () => {
beforeEach(() => {
jest.resetAllMocks()
@ -19,7 +22,8 @@ describe('Logger', () => {
expect(consoleLogSpy).toHaveBeenCalledTimes(2)
expect(consoleLogSpy).toHaveBeenNthCalledWith(
1,
'<%s> [%s] %s: %s',
'(%s) <%s> [%s] %s: %s',
dayjs().format(),
'tag',
'abc',
'DEBUG',
@ -27,7 +31,8 @@ describe('Logger', () => {
)
expect(consoleLogSpy).toHaveBeenNthCalledWith(
2,
'<%s> [%s] %s: %s',
'(%s) <%s> [%s] %s: %s',
dayjs().format(),
'tag',
'abc',
'INFO',
@ -35,7 +40,8 @@ describe('Logger', () => {
)
expect(consoleErrorSpy).toHaveBeenCalledTimes(1)
expect(consoleErrorSpy).toHaveBeenCalledWith(
'<%s> [%s] %s: %s - %O',
'(%s) <%s> [%s] %s: %s - %O',
dayjs().format(),
'tag',
'abc',
'ERROR',
@ -66,7 +72,8 @@ describe('Logger', () => {
expect(consoleLogSpy).toHaveBeenCalledTimes(1)
expect(consoleLogSpy).toHaveBeenNthCalledWith(
1,
'<%s> [%s] %s: %s - %O',
'(%s) <%s> [%s] %s: %s - %O',
dayjs().format(),
'tag',
'abc',
'INFO',