mirror of https://github.com/calzoneman/sync.git
Add check to prevent write-after-end error
This commit is contained in:
parent
1df015b839
commit
93dd730bde
|
@ -17,6 +17,7 @@ function getTimeString() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var Logger = function(filename) {
|
var Logger = function(filename) {
|
||||||
|
this.dead = false;
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
this.writer = fs.createWriteStream(filename, {
|
this.writer = fs.createWriteStream(filename, {
|
||||||
flags: "a",
|
flags: "a",
|
||||||
|
@ -25,6 +26,10 @@ var Logger = function(filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.prototype.log = function () {
|
Logger.prototype.log = function () {
|
||||||
|
if(this.dead) {
|
||||||
|
Logger.errlog.log("WARNING: Attempted write to dead logger: ", this.filename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
var msg = "";
|
var msg = "";
|
||||||
for(var i in arguments)
|
for(var i in arguments)
|
||||||
msg += arguments[i];
|
msg += arguments[i];
|
||||||
|
@ -33,7 +38,9 @@ Logger.prototype.log = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.prototype.close = function () {
|
Logger.prototype.close = function () {
|
||||||
this.writer.end();
|
this.writer.end("", null, function () {
|
||||||
|
this.dead = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var errlog = new Logger("error.log");
|
var errlog = new Logger("error.log");
|
||||||
|
|
Loading…
Reference in New Issue