I want to log all of the messages from Console using Winston,
and use winston-daily-rotate-file to daily store and remove the logs.
In Console:
{"level":"info","message":"Feathers application started on localhost","timestamp":"5/26/2021, 10:44:36 AM"}
You will see this message every 60 second
You will see this message every 60 second
You will see this message every 60 second
When I view the log file application-2021-05-26.log,
{"level":"info","message":"Feathers application started on localhost","timestamp":"5/26/2021, 10:44:36 AM"}
You will see this message every 60 second is missing in the log file.
What's wrong here?
app.js
var CronJob = require('cron').CronJob;
const moment = require('moment');
new CronJob('10 * * * * *', function() {
console.log('You will see this message every 60 second');
}, null, true, 'Asia/Singapore');
logger.js
const { createLogger, format, transports } = require('winston');
const winston = require('winston');
require('winston-daily-rotate-file');
const timezoned = () => {
return new Date().toLocaleString('en-SG', {
timeZone: 'Asia/Singapore'
});
}
const logger = createLogger({
level: 'debug',
format: format.combine(
format.splat(),
format.simple(),
format.json()
),
transports: [
new transports.Console(),
new winston.transports.DailyRotateFile({
filename: 'application-%DATE%.log',
dirname: "logs",
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: '20m',
maxFiles: '2d',
format: winston.format.combine(
winston.format.timestamp({ format: timezoned }),
winston.format.json(),
),
})
],
});
module.exports = logger;