question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rotating log file with size, maxFiles and path options

See original GitHub issue

In 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 image

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
painkkillercommented, Dec 7, 2022

@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.

0reactions
icciccicommented, Dec 15, 2022

The only thing which matters is: you was able to solve the probelm! 😄 Thank you

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found