Rotating log file with size, maxFiles and path options
See original GitHub issueIn my app path to logs is set by the kibernetes option and looks like path: '/opt/app/logs/backend.log'
. I have the requirement to rotate the log file, the file should not exceed 20 Mb, and only one file should be kept. So I am splitting this path with code:
const path = require('path');
const fileName = path.basename(process.env.log_file);
const logPath = path.dirname(process.env.log_file);
and create a rotating file stream with these options:
const stream = rfs.createStream(fileName, {
size: "20M", // rotate every 20 MegaBytes written
maxFiles: 1, // only 1 rotated file is allowed
path: logPath
});
And I found that in this case rotation doesn’t work. During the test, I am getting a lot of files with names
Issue Analytics
- State:
- Created 9 months ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Centos/Linux setting logrotate to maximum file size for all logs
As mentioned by Zeeshan, the logrotate options size , minsize , maxsize are triggers for rotation. To better explain it.
Read more >A Guide to Rolling File Appenders - Baeldung
We'll demonstrate how to roll log files based on size, date/time, and a combination of size and date/time. We'll also explore how to...
Read more >How to use Winston Daily Rotate File Logger in NodeJs
maxSize — set to 20 mb. to set the log file maximum size. maxFiles — set to 14 days. how long log file...
Read more >rotating-file-stream - npm
Writable to a file rotated by interval and/or size. A logrotate ... maxFiles; maxSize; mode; omitExtension; path; rotate; size; teeToStdout.
Read more >Controlling wrapper.log file size and rotation in CA ...
The wrapper.log file(s) in CA Performance Manager (CAPM) can potentiallygrowto a size that is going to impact the systems functionality.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@iccicci thanks for very quick reply, I’ll try it today. But the option
maxFiles: 1
worked as I expected (It created 1 rotated file) before I added path. But anyway I’ll try and write about result here.The only thing which matters is: you was able to solve the probelm! 😄 Thank you