awesomeeng / awesome-log

Logging for enterprise ready nodejs applications.
MIT License
34 stars 4 forks source link

Node app crashes when first logged value is falsy. #25

Closed chuckntaylor closed 2 years ago

chuckntaylor commented 2 years ago

Node is crashing when the first logged value is falsy. Examples:

log.debug(0) // crash
log.debug(0, 'items') // crash
log.debug(false) // crash
log.debug(null) // crash

The error is:

Error: Missing level argument.
    at AwesomeLog.getLevel (.../node_modules/@awesomeeng/awesome-log/src/AwesomeLog.js:510:21)
    at AwesomeLog.log (...node_modules/@awesomeeng/awesome-log/src/AwesomeLog.js:557:16)

My setup is:

// logger.ts
import log from '@awesomeeng/awesome-log'

// LOG LEVELS
// 'access'
// 'error'
// 'warn'
// 'info'
// 'debug'

log.init({
  writers: [
    {
      name: 'MyConsoleWriter',
      type: 'console',
      levels: '*',
      formatter: 'default',
      options: {
        colorStyle: 'line',
      },
    },
  ],
})
log.start()

export { log }

Any advice?

arei commented 2 years ago

Quick advice: Always put a log message as the first argument. AwesomeLog is not intended as a straight up replacement for console.log() and thus doesn't handle the same usage.

Better advice: A fix is coming shortly.

arei commented 2 years ago

Fixed in v4.3.0, out now.