darrylwest/simple-node-logger

Jest throws a warning when simple-node-logger is used in unit tests

Opened this issue · 0 comments

Hello,

My current logger implementation is

let logger = undefined

const getLogger = () => {
    if (logger === undefined) {
        logger = simpleLogger.createSimpleLogger({ timestampFormat: '-' })
        logger.setLevel(LOG_LEVEL || 'info')
    }
    return logger
}

export const log = getLogger()

when I use log.info(something) in jest unit tests I get

Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "- INFO something".

 at CustomConsole.log (node_modules/@jest/console/build/CustomConsole.js:183:10)
 at ConsoleAppender.write (node_modules/simple-node-logger/lib/ConsoleAppender.js:45:13)
 at node_modules/simple-node-logger/lib/Logger.js:42:26
      at Array.forEach (<anonymous>)
  at node_modules/simple-node-logger/lib/Logger.js:41:23

if I use console.log instead all is good ...

Am I doing something wrong or this is a bug?