-
Notifications
You must be signed in to change notification settings - Fork 157
Open
Description
Description
After restart node server:
-
The last time's newest log file is not archived.
-
The last time's oldest archived log file is not deleted when exceed maxFiles.
Version
4.5.0
Log settings
var transport = new winston.transports.DailyRotateFile({
filename: './logs/application-%DATE%.log',
datePattern: 'YYYY-MM-DD-HH-mm:ss',
zippedArchive: true,
maxFiles: 5 ,
maxSize: '1k'
});Test steps
- Use test script to generate 5 log files (one file per second).
node test.js 5- Check log files
Pin@ubuntu # ll -t -r logs/
-rw-r--r-- 1 root root 69 Oct 12 18:23 application-2020-10-12-18-23:01.log.gz
-rw-r--r-- 1 root root 69 Oct 12 18:23 application-2020-10-12-18-23:02.log.gz
-rw-r--r-- 1 root root 69 Oct 12 18:23 application-2020-10-12-18-23:03.log.gz
-rw-r--r-- 1 root root 50 Oct 12 18:23 application-2020-10-12-18-23:05.log
-rw-r--r-- 1 root root 69 Oct 12 18:23 application-2020-10-12-18-23:04.log.gz
-rw-r--r-- 1 root root 1039 Oct 12 18:23 .4fdb28c558b05eafd9ee9c1d1660cb8f60f66f53-audit.json
- Use test script to generate 3 log files (one file per second).
node test.js 34 Check log files
Pin@ubuntu # ll -t -r logs/
-rw-r--r-- 1 root root 69 Oct 12 18:23 application-2020-10-12-18-23:01.log.gz
-rw-r--r-- 1 root root 50 Oct 12 18:23 application-2020-10-12-18-23:05.log
-rw-r--r-- 1 root root 20 Oct 12 18:23 application-2020-10-12-18-23:08.log.gz
-rw-r--r-- 1 root root 69 Oct 12 18:23 application-2020-10-12-18-23:09.log.gz
-rw-r--r-- 1 root root 50 Oct 12 18:23 application-2020-10-12-18-23:11.log
-rw-r--r-- 1 root root 69 Oct 12 18:23 application-2020-10-12-18-23:10.log.gz
-rw-r--r-- 1 root root 1039 Oct 12 18:23 .4fdb28c558b05eafd9ee9c1d1660cb8f60f66f53-audit.json
Expected:
application-2020-10-12-18-23:05.logshould be archivedapplication-2020-10-12-18-23:01.log.gzshould be deleted
Test Script
test.js
var winston = require('winston');
require('winston-daily-rotate-file')
var transport = new winston.transports.DailyRotateFile({
filename: './logs/application-%DATE%.log',
datePattern: 'YYYY-MM-DD-HH-mm:ss',
zippedArchive: true,
maxFiles: 5 ,
maxSize: '1k'
});
var logger = winston.createLogger({
transports: [
transport
]
});
function makeid(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
function waitAndDo(times) {
if (times < 1) {
return;
}
setTimeout(function() {
logger.info(makeid(20));
waitAndDo(times-1);
}, 1000);
}
waitAndDo(process.argv[2]);Metadata
Metadata
Assignees
Labels
No labels