winstonjs / winston-transport

Base stream implementations for winston@3 and up.
MIT License
62 stars 40 forks source link

Error formatted by Console transport is undefined #224

Open davelowndes opened 3 months ago

davelowndes commented 3 months ago

Environment: winston 3.13.0 Windows 11 node v20.5.1

If I use format inside new winston.transports.Console() the Error is undefined:

import winston from 'winston'

const logger = winston.createLogger({
    transports: [new winston.transports.Console()],
    format: winston.format.printf((info) => {
        return `${info.level}: ${info.message}`
    })
})

const logger2 = winston.createLogger({
    transports: [new winston.transports.Console({
        format: winston.format.printf((info) => {
            return `${info.level}: ${info.message}`
        })
    }
    )],
})

logger.info('test')
logger2.info('test')

try {
    throw new Error('oh no!')
} catch (err) {
    logger.error(err)
    logger2.error(err)
}

Output:

info: test
info: test
error: oh no!
error: undefined