Fix logger being closed inappropriately

This commit is contained in:
calzoneman 2013-07-29 19:59:52 -04:00
parent 687a561079
commit ba26d9abbb
3 changed files with 12 additions and 11 deletions

View File

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

View File

@ -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";
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");

View File

@ -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);