Log Rotation Problem with multiple appenders writing to same file #147

Open
homerlex opened this Issue Jul 24, 2013 · 4 comments

3 participants

@homerlex

Using log4js-node 0.6.6 and node v0.10.10

I saw a similar (or same) error mentioned in Issue #123. When I have multiple appenders writing to the same file and also have log rotation I get the following error from time to time:


throw er; // Unhandled 'error' event
              ^
Error: write after end
    at writeAfterEnd (_stream_writable.js:130:12)
    at WriteStream.Writable.write (_stream_writable.js:178:5)
    at writeTheChunk (D:\projects\Crisply\bitbucket\desktop\app\node_modules\log4js\lib\streams\BaseRollingFileStream.js:51:20)
    at D:\projects\Crisply\bitbucket\desktop\app\node_modules\log4js\node_modules\async\lib\async.js:199:13
    at D:\projects\Crisply\bitbucket\desktop\app\node_modules\log4js\node_modules\async\lib\async.js:120:21
    at D:\projects\Crisply\bitbucket\desktop\app\node_modules\log4js\node_modules\async\lib\async.js:196:17
    at D:\projects\Crisply\bitbucket\desktop\app\node_modules\log4js\node_modules\async\lib\async.js:499:34
    at D:\projects\Crisply\bitbucket\desktop\app\node_modules\log4js\node_modules\async\lib\async.js:120:21
    at Object.oncomplete (fs.js:107:15)

I can duplicate this with the script below. If I change the appenders to write to unique files I can run this script over and over and never error out:


var log4js = require("log4js");

var default_log_config = {
  "appenders": [
    { type: "console"  },
    { type: "file", filename: "app.log", backups: 10, maxLogSize: 20480, category: "options" },
    { type: "file", filename: "app.log", backups: 10, maxLogSize: 20480, category: "something" },
    { type: "file", filename: "app.log", backups: 10, maxLogSize: 20480, category: "demolition" },
    { type: "file", filename: "app.log", backups: 10, maxLogSize: 20480, category: "updater" }
  ]
}

var logger_o = log4js.getLogger("options");
var logger_s = log4js.getLogger("something");
var logger_d = log4js.getLogger("demolition");
var logger_u = log4js.getLogger("updater");

log4js.configure(default_log_config, {cwd: __dirname});

for (var i=0;i<1000;i++)
{
  logger_o.debug('ooo oooooooooooooooooo oooooooooo ooooooooooooooo oooooooooooooooooooo ooooooooooooooooooooooooo oooooooooooooooooo');
  logger_s.debug('sssssssssssssss ssssssssssssssssssssssss sssss sssssssssssssssssssss sssssssssss sssssssssssssssssssssssssssssssssssss');
  logger_d.debug('ddddddddddddddddddddddddddddddd dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd ddd dddddddddddddddddddddddddddd');
  logger_u.debug('uu uuuuuuuuu uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu');
}
@nomiddlename

Yep, all four appenders will try to rotate the log file. If you want them all to write to the same file, you might be able to get away with only configuring log rotation on one of the appenders (if you don't specify a log size, log rotation won't happen).

@nomiddlename
Owner

Did changing the config fix your problem, @homerlex ?

@homerlex

I simply went to using different files for each appender and don't have any issues with that. I did not try having the same file with only one appender doing the rotation

@mrFranklin

the same problem for me! I used the newest version: 0.6.14. i found the error occured,when the file is full!(when the data larger than the setting: 'maxLogSize'). please help~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment