Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})