Skip to content

Commit

Permalink
feat: accept level in capitals (#2034)
Browse files Browse the repository at this point in the history
  • Loading branch information
balaji-atoa authored Aug 31, 2024
1 parent 470df82 commit 74fc0db
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pino.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ const serializers = Object.assign(Object.create(null), stdSerializers)
function pino (...args) {
const instance = {}
const { opts, stream } = normalize(instance, caller(), ...args)

if (opts.level && typeof opts.level === 'string' && DEFAULT_LEVELS[opts.level.toLowerCase()] !== undefined) opts.level = opts.level.toLowerCase()

const {
redact,
crlf,
Expand Down
66 changes: 66 additions & 0 deletions test/levels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,69 @@ test('trying to get levels when `this` is no longer a Pino instance returns an e
const blankedLevelValue = notPinoInstance.getLevel()
equal(blankedLevelValue, '')
})

test('accepts capital letter for INFO level', async ({ equal }) => {
const stream = sink()
const logger = pino({
level: 'INFO'
}, stream)

logger.info('test')
const { level } = await once(stream, 'data')
equal(level, 30)
})

test('accepts capital letter for FATAL level', async ({ equal }) => {
const stream = sink()
const logger = pino({
level: 'FATAL'
}, stream)

logger.fatal('test')
const { level } = await once(stream, 'data')
equal(level, 60)
})

test('accepts capital letter for ERROR level', async ({ equal }) => {
const stream = sink()
const logger = pino({
level: 'ERROR'
}, stream)

logger.error('test')
const { level } = await once(stream, 'data')
equal(level, 50)
})

test('accepts capital letter for WARN level', async ({ equal }) => {
const stream = sink()
const logger = pino({
level: 'WARN'
}, stream)

logger.warn('test')
const { level } = await once(stream, 'data')
equal(level, 40)
})

test('accepts capital letter for DEBUG level', async ({ equal }) => {
const stream = sink()
const logger = pino({
level: 'DEBUG'
}, stream)

logger.debug('test')
const { level } = await once(stream, 'data')
equal(level, 20)
})

test('accepts capital letter for TRACE level', async ({ equal }) => {
const stream = sink()
const logger = pino({
level: 'TRACE'
}, stream)

logger.trace('test')
const { level } = await once(stream, 'data')
equal(level, 10)
})

0 comments on commit 74fc0db

Please sign in to comment.