Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"maxDays" option doing nothing #91

Closed
CnApTaK opened this issue Sep 20, 2017 · 4 comments
Closed

"maxDays" option doing nothing #91

CnApTaK opened this issue Sep 20, 2017 · 4 comments
Labels

Comments

@CnApTaK
Copy link

CnApTaK commented Sep 20, 2017

i got options like
{
"name": "DailyRotateFile",
"options": {
"datePattern": "yyyy-MM-dd.",
"prepend": true,
"zippedArchive": false,
"level": "debug",
"colorize": false,
"timestamp": true,
"filename": "./logs/log.txt",
"maxsize": 10485760,
"maxFiles": 5,
"maxDays": 10,
"json": false
}
}
and i get files in /logs
2017-09-08.log.txt
2017-09-09.log.txt
2017-09-10.log.txt
2017-09-11.log.txt
2017-09-12.log.txt
2017-09-13.log.txt
2017-09-14.log.txt
2017-09-15.log.txt
2017-09-16.log.txt
2017-09-17.log.txt
2017-09-18.log.txt
2017-09-19.log.txt
2017-09-20.log.txt
and each day i got +1 file.. why "maxDays" is not working? I did not find any mention in the code

@CnApTaK CnApTaK changed the title "maxDays" option doing notjing "maxDays" option doing nothing Sep 20, 2017
@CnApTaK
Copy link
Author

CnApTaK commented Sep 27, 2017

can you put somthing like this.. if maxDays > 0
const maxDays = 10;
fs.watch('./logs', function (type, filename) {
if (type !== 'rename') return;
const filenameFull = './logs/'.concat(filename);
if (!fs.existsSync(filenameFull)) return;
const stat = fs.statSync(filenameFull);
const now = new Date();
if (stat.ctime.getTime() + maxDays * 86400 * 1000 < now.getTime()) fs.unlinkSync(filenameFull);
});

@mattberther mattberther added the bug label Oct 6, 2017
@mattberther
Copy link
Member

Some long-overdue refactoring of the transport has occurred. A PR is available at #107. Also, a pre-release version has been published to npm. With the new version, you can use maxFiles: '10d' (for example) to keep 10 days of log files. Review the list of updated options on the README.md at #107.

Please npm install [email protected] and reopen this issue if the problem remains.

@ChanchalChandanbatwe
Copy link

maxFiles not working for me

It is not even generating log file

`var winston = require('winston');
require('winston-daily-rotate-file');

const transport = new winston.transports.DailyRotateFile({
filename: 'debug.log',
datePattern: 'YYYY-MM-DD-HH',
zippedArchive: true,
maxFiles: 4,
maxSize: '1m',
json: false
});`

@mattberther
Copy link
Member

@ChanchalChandanbatwe Can you please post a complete example, including the logging statements, that reproduce this issue? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants