I\'m trying to set up an access log and an error log for my express server using Winston, but I seem to be doing something wrong.
Here is my attempt at a config file:
1 Logger + console logging for development purpose:
logger.js
var logPath = '';
var log_level = '';
const log = winston.createLogger({
level: log_level,
format: winston.format.json(),
transports: [
new winston.transports.File({
filename: path.join(logPath, 'access.log'),
timestamp: tsFormat,
level: log_level
}),
new winston.transports.File({
filename: path.join(logPath, 'error.log'),
timestamp: tsFormat,
level: 'error'
}),
]
});
if (process.env.NODE_ENV !== 'production') {
log.add(new winston.transports.Console({
format: winston.format.simple()
}));
}
module.exports = {
log: log
};
app.js
const logger = require('./logger');
logger.log.info("starting application..");