26 lines
573 B
JavaScript
26 lines
573 B
JavaScript
|
const winston = require('winston');
|
||
|
|
||
|
const logger = winston.createLogger({
|
||
|
level: process.env.LOG_LEVEL || 'info',
|
||
|
format: winston.format.combine(
|
||
|
winston.format.timestamp(),
|
||
|
winston.format.json()
|
||
|
),
|
||
|
transports: [
|
||
|
new winston.transports.Console({
|
||
|
format: winston.format.simple()
|
||
|
})
|
||
|
]
|
||
|
});
|
||
|
|
||
|
if (process.env.NODE_ENV === 'production') {
|
||
|
logger.add(new winston.transports.File({
|
||
|
filename: 'error.log',
|
||
|
level: 'error'
|
||
|
}));
|
||
|
logger.add(new winston.transports.File({
|
||
|
filename: 'combined.log'
|
||
|
}));
|
||
|
}
|
||
|
|
||
|
module.exports = logger;
|