23 lines
751 B
JavaScript
23 lines
751 B
JavaScript
const { createLogger, format, transports } = require('winston');
|
|
const path = require('path');
|
|
const env = process.env.NODE_ENV || 'development';
|
|
const logger = createLogger({
|
|
level: env === 'production' ? 'info' : 'debug',
|
|
format: format.combine(
|
|
format.label({ label: path.basename(process.mainModule.filename) }),
|
|
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' })
|
|
),
|
|
transports: [
|
|
new transports.Console({
|
|
format: format.combine(
|
|
format.colorize(),
|
|
format.printf(
|
|
info =>
|
|
`${info.timestamp} ${info.level} [${info.label}]: ${info.message}`
|
|
)
|
|
)
|
|
}),
|
|
]
|
|
});
|
|
module.exports = logger;
|