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

On unix, forced to write in file to trigger rolling #63

Closed
lblackwings opened this issue Jul 3, 2020 · 1 comment
Closed

On unix, forced to write in file to trigger rolling #63

lblackwings opened this issue Jul 3, 2020 · 1 comment

Comments

@lblackwings
Copy link

Actually I have this :

var loaderErrorLogMaxSize = 10485760;
var rollLoaderError = function () {
  var roller = new streamroller.RollingFileStream('./log/loader-error.log', loaderErrorLogMaxSize, 10);
  roller.end(function () {
        logger.info('Loader -', 'loader-error.log checked for roll.');
  });
};

This works on windows and each time I invoke this code, the file is normally rolled.
But on unix I have to add a write('') call to trigger the roll.

var loaderErrorLogMaxSize = 10485760;
var rollLoaderError = function () {
    var roller = new streamroller.RollingFileStream('./log/loader-error.log', loaderErrorLogMaxSize, 10);
    roller.write('');
    roller.end(function () {
        logger.info('Loader -', 'loader-error.log checked for roll.');
    });
};

I use this function in the callback of a fs.watch because the file is managed by pm2 and cannot roll by itself.
So each time this file change, I check the size then I invoke the rollLaoderError function then I have to write something in the file...

@lamweili
Copy link
Contributor

lamweili commented May 12, 2022

Seems like a Node.js OS implementation issue.
I'm not so sure if we should fiddle with that.

You can always do the following API for both OSes:

writable.end([chunk[, encoding]][, callback])
https://nodejs.org/api/stream.html#writableendchunk-encoding-callback

=  var loaderErrorLogMaxSize = 10485760;
=  var rollLoaderError = function () {
=      var roller = new streamroller.RollingFileStream('./log/loader-error.log', loaderErrorLogMaxSize, 10);
-      roller.write('');
-      roller.end(function () {
+      roller.end('', function () {
=          logger.info('Loader -', 'loader-error.log checked for roll.');
=      });
=  };

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

No branches or pull requests

2 participants