Skip to content

Commit

Permalink
Add time to the processor logger
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdulrhmnGhanem authored and kasbah committed Apr 12, 2024
1 parent 30768d5 commit 4f79d6d
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions processor/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,28 @@ const logLevels: ReadonlyArray<string> = ['debug', 'info', 'warn', 'error']

const level = logLevels.indexOf(LOG_LEVEL)

const getTimeString = () => {
const now = new Date()
const isoString = `[${now.toISOString().split('.')[0]}Z] `
return isoString
}

/* eslint-disable no-console */
export const log = {
debug: level <= 0 ? console.debug : () => {},
info: level <= 1 ? console.info : () => {},
warn: level <= 2 ? console.warn : () => {},
error: level <= 3 ? console.error : () => {},
debug:
level <= 0
? (...args: Array<unknown>) => console.debug(getTimeString(), ...args)
: () => {},
info:
level <= 1
? (...args: Array<unknown>) => console.info(getTimeString(), ...args)
: () => {},
warn:
level <= 2
? (...args: Array<unknown>) => console.warn(getTimeString(), ...args)
: () => {},
error:
level <= 3
? (...args: Array<unknown>) => console.error(getTimeString(), ...args)
: () => {},
}

0 comments on commit 4f79d6d

Please sign in to comment.