Skip to content

Instantly share code, notes, and snippets.

@andersonbosa
Last active June 27, 2024 13:02
Show Gist options
  • Save andersonbosa/90b305d464fd535f0c193e892ebb08c6 to your computer and use it in GitHub Desktop.
Save andersonbosa/90b305d464fd535f0c193e892ebb08c6 to your computer and use it in GitHub Desktop.
import winston from 'winston'
const createWinstonLogger = () => winston.createLogger({
levels: winston.config.syslog.levels,
transports: [
new winston.transports.Console({
level: 'info',
format: winston.format.combine(
winston.format.colorize({ all: true }),
winston.format.timestamp({ format: 'YYYY-MM-DD hh:mm:ss.SSS A', }),
winston.format.align(),
winston.format.printf((info) => `[${info.timestamp}] ${info.level.toUpperCase()}: ${info.message}`)
)
}),
new winston.transports.File({
filename: 'winston.log',
level: 'debug',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json(),
)
})
]
})
export const LOGGER = createWinstonLogger() // this is not a singleton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment