|
@ -1,14 +1,7 @@ |
|
|
const path = require('path'); |
|
|
const path = require('path'); |
|
|
|
|
|
|
|
|
const getLogger = (winston, logsDirectory, serviceName) => { |
|
|
const getLogger = (winston, logsDirectory, serviceName) => { |
|
|
const logger = winston.createLogger({ |
|
|
const transports = [ |
|
|
level: process.env.NODE_ENV === 'production' ? 'info' : 'silly', |
|
|
|
|
|
format: winston.format.combine( |
|
|
|
|
|
winston.format.timestamp(), |
|
|
|
|
|
winston.format.json(), |
|
|
|
|
|
), |
|
|
|
|
|
defaultMeta: { service: serviceName }, |
|
|
|
|
|
transports: [ |
|
|
|
|
|
new winston.transports.File({ |
|
|
new winston.transports.File({ |
|
|
filename: path.join(logsDirectory, 'error.log'), |
|
|
filename: path.join(logsDirectory, 'error.log'), |
|
|
level: 'error', |
|
|
level: 'error', |
|
@ -16,14 +9,22 @@ const getLogger = (winston, logsDirectory, serviceName) => { |
|
|
new winston.transports.File({ |
|
|
new winston.transports.File({ |
|
|
filename: path.join(logsDirectory, 'combined.log'), |
|
|
filename: path.join(logsDirectory, 'combined.log'), |
|
|
}), |
|
|
}), |
|
|
], |
|
|
]; |
|
|
exceptionHandlers: [ |
|
|
|
|
|
|
|
|
const exceptionHandlers = [ |
|
|
new winston.transports.File({ filename: path.join(logsDirectory, 'exceptions.log') }), |
|
|
new winston.transports.File({ filename: path.join(logsDirectory, 'exceptions.log') }), |
|
|
], |
|
|
]; |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'production') { |
|
|
if (process.env.NODE_ENV !== 'production') { |
|
|
logger.add(new winston.transports.Console({ |
|
|
transports.push(new winston.transports.Console({ |
|
|
|
|
|
format: winston.format.combine( |
|
|
|
|
|
winston.format.colorize(), |
|
|
|
|
|
winston.format.timestamp(), |
|
|
|
|
|
winston.format.simple(), |
|
|
|
|
|
), |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
exceptionHandlers.push(new winston.transports.Console({ |
|
|
format: winston.format.combine( |
|
|
format: winston.format.combine( |
|
|
winston.format.colorize(), |
|
|
winston.format.colorize(), |
|
|
winston.format.timestamp(), |
|
|
winston.format.timestamp(), |
|
@ -32,7 +33,16 @@ const getLogger = (winston, logsDirectory, serviceName) => { |
|
|
})); |
|
|
})); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return logger; |
|
|
return winston.createLogger({ |
|
|
|
|
|
level: process.env.NODE_ENV === 'production' ? 'info' : 'silly', |
|
|
|
|
|
format: winston.format.combine( |
|
|
|
|
|
winston.format.timestamp(), |
|
|
|
|
|
winston.format.json(), |
|
|
|
|
|
), |
|
|
|
|
|
defaultMeta: { service: serviceName }, |
|
|
|
|
|
transports, |
|
|
|
|
|
exceptionHandlers, |
|
|
|
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
module.exports = getLogger; |
|
|
module.exports = getLogger; |
|
|