diff --git a/channel.js b/channel.js index a212b364..8881597b 100644 --- a/channel.js +++ b/channel.js @@ -268,7 +268,6 @@ Channel.prototype.saveDump = function() { }; var text = JSON.stringify(dump); fs.writeFileSync("chandump/" + this.name, text); - this.logger.close(); } // Save channel dumps every 5 minutes, in case of crash diff --git a/logger.js b/logger.js index 7d83fe9b..85d5748d 100644 --- a/logger.js +++ b/logger.js @@ -17,7 +17,6 @@ function getTimeString() { } var Logger = function(filename) { - this.dead = false; this.filename = filename; this.writer = fs.createWriteStream(filename, { flags: "a", @@ -31,23 +30,25 @@ Logger.prototype.log = function () { msg += arguments[i]; if(this.dead) { - errlog.log("WARNING: Attempted write to dead logger: ", this.filename); - errlog.log("Message was: ", msg); return; } var str = "[" + getTimeString() + "] " + msg + "\n"; - this.writer.write(str); + try { + this.writer.write(str); + } catch(e) { + errlog.log("WARNING: Attempted logwrite failed: " + this.filename); + errlog.log("Message was: " + msg); + errlog.log(e); + } } Logger.prototype.close = function () { - if(this.dead) { - errlog.log("WARNING: Attempted closure on dead logger: ", this.filename); - return; + try { + this.writer.end(); + } catch(e) { + errlog.log("Log close failed: " + this.filename); } - this.writer.end("", null, function () { - this.dead = true; - }.bind(this)); } var errlog = new Logger("error.log"); diff --git a/server.js b/server.js index 308dc9d1..4c82a298 100644 --- a/server.js +++ b/server.js @@ -55,6 +55,7 @@ var Server = { if(chan.registered) chan.saveDump(); chan.playlist.die(); + chan.logger.close(); for(var i in this.channels) { if(this.channels[i].canonical_name == chan.canonical_name) { this.channels.splice(i, 1);