From 93dd730bde04da0f7ca4de2bf2e7f0ca5d0825a7 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Mon, 29 Jul 2013 18:13:06 -0400 Subject: [PATCH] Add check to prevent write-after-end error --- logger.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/logger.js b/logger.js index 4bbc79fa..d2b2d391 100644 --- a/logger.js +++ b/logger.js @@ -17,6 +17,7 @@ function getTimeString() { } var Logger = function(filename) { + this.dead = false; this.filename = filename; this.writer = fs.createWriteStream(filename, { flags: "a", @@ -25,6 +26,10 @@ var Logger = function(filename) { } Logger.prototype.log = function () { + if(this.dead) { + Logger.errlog.log("WARNING: Attempted write to dead logger: ", this.filename); + return; + } var msg = ""; for(var i in arguments) msg += arguments[i]; @@ -33,7 +38,9 @@ Logger.prototype.log = function () { } Logger.prototype.close = function () { - this.writer.end(); + this.writer.end("", null, function () { + this.dead = true; + }); } var errlog = new Logger("error.log");