more linting
This commit is contained in:
parent
2de838bc76
commit
cc2e94cf11
@ -1,16 +1,17 @@
|
|||||||
var BaseRollingFileStream = require('./BaseRollingFileStream'),
|
"use strict";
|
||||||
format = require('../date_format'),
|
var BaseRollingFileStream = require('./BaseRollingFileStream')
|
||||||
async = require('async'),
|
, format = require('../date_format')
|
||||||
fs = require('fs'),
|
, async = require('async')
|
||||||
util = require('util');
|
, fs = require('fs')
|
||||||
|
, util = require('util');
|
||||||
|
|
||||||
module.exports = DateRollingFileStream;
|
module.exports = DateRollingFileStream;
|
||||||
|
|
||||||
var debug;
|
var debug;
|
||||||
if (process.env.NODE_DEBUG && /\blog4js\b/.test(process.env.NODE_DEBUG)) {
|
if (process.env.NODE_DEBUG && /\blog4js\b/.test(process.env.NODE_DEBUG)) {
|
||||||
debug = function(message) { console.error('LOG4JS: (DateRollingFileStream) %s', message); };
|
debug = function(message) { console.error('LOG4JS: (DateRollingFileStream) %s', message); };
|
||||||
} else {
|
} else {
|
||||||
debug = function() { };
|
debug = function() { };
|
||||||
}
|
}
|
||||||
|
|
||||||
function DateRollingFileStream(filename, pattern, options, now) {
|
function DateRollingFileStream(filename, pattern, options, now) {
|
||||||
@ -25,7 +26,7 @@ function DateRollingFileStream(filename, pattern, options, now) {
|
|||||||
this.lastTimeWeWroteSomething = format.asString(this.pattern, new Date(this.now()));
|
this.lastTimeWeWroteSomething = format.asString(this.pattern, new Date(this.now()));
|
||||||
this.baseFilename = filename;
|
this.baseFilename = filename;
|
||||||
this.alwaysIncludePattern = false;
|
this.alwaysIncludePattern = false;
|
||||||
|
|
||||||
if (options) {
|
if (options) {
|
||||||
if (options.alwaysIncludePattern) {
|
if (options.alwaysIncludePattern) {
|
||||||
this.alwaysIncludePattern = true;
|
this.alwaysIncludePattern = true;
|
||||||
@ -37,56 +38,57 @@ function DateRollingFileStream(filename, pattern, options, now) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug("this.now is " + this.now + ", now is " + now);
|
debug("this.now is " + this.now + ", now is " + now);
|
||||||
|
|
||||||
DateRollingFileStream.super_.call(this, filename, options);
|
DateRollingFileStream.super_.call(this, filename, options);
|
||||||
}
|
}
|
||||||
util.inherits(DateRollingFileStream, BaseRollingFileStream);
|
util.inherits(DateRollingFileStream, BaseRollingFileStream);
|
||||||
|
|
||||||
DateRollingFileStream.prototype.shouldRoll = function() {
|
DateRollingFileStream.prototype.shouldRoll = function() {
|
||||||
var lastTime = this.lastTimeWeWroteSomething,
|
var lastTime = this.lastTimeWeWroteSomething,
|
||||||
thisTime = format.asString(this.pattern, new Date(this.now()));
|
thisTime = format.asString(this.pattern, new Date(this.now()));
|
||||||
|
|
||||||
debug("DateRollingFileStream.shouldRoll with now = " + this.now() + ", thisTime = " + thisTime + ", lastTime = " + lastTime);
|
debug("DateRollingFileStream.shouldRoll with now = " +
|
||||||
|
this.now() + ", thisTime = " + thisTime + ", lastTime = " + lastTime);
|
||||||
this.lastTimeWeWroteSomething = thisTime;
|
|
||||||
this.previousTime = lastTime;
|
this.lastTimeWeWroteSomething = thisTime;
|
||||||
|
this.previousTime = lastTime;
|
||||||
return thisTime !== lastTime;
|
|
||||||
|
return thisTime !== lastTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
DateRollingFileStream.prototype.roll = function(filename, callback) {
|
DateRollingFileStream.prototype.roll = function(filename, callback) {
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
|
debug("Starting roll");
|
||||||
|
|
||||||
|
if (this.alwaysIncludePattern) {
|
||||||
|
this.filename = this.baseFilename + this.lastTimeWeWroteSomething;
|
||||||
|
async.series([
|
||||||
|
this.closeTheStream.bind(this),
|
||||||
|
this.openTheStream.bind(this)
|
||||||
|
], callback);
|
||||||
|
} else {
|
||||||
|
var newFilename = this.baseFilename + this.previousTime;
|
||||||
|
async.series([
|
||||||
|
this.closeTheStream.bind(this),
|
||||||
|
deleteAnyExistingFile,
|
||||||
|
renameTheCurrentFile,
|
||||||
|
this.openTheStream.bind(this)
|
||||||
|
], callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteAnyExistingFile(cb) {
|
||||||
|
//on windows, you can get a EEXIST error if you rename a file to an existing file
|
||||||
|
//so, we'll try to delete the file we're renaming to first
|
||||||
|
fs.unlink(newFilename, function (err) {
|
||||||
|
//ignore err: if we could not delete, it's most likely that it doesn't exist
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
debug("Starting roll");
|
function renameTheCurrentFile(cb) {
|
||||||
|
debug("Renaming the " + filename + " -> " + newFilename);
|
||||||
if (this.alwaysIncludePattern) {
|
fs.rename(filename, newFilename, cb);
|
||||||
this.filename = this.baseFilename + this.lastTimeWeWroteSomething;
|
}
|
||||||
async.series([
|
|
||||||
this.closeTheStream.bind(this),
|
|
||||||
this.openTheStream.bind(this)
|
|
||||||
], callback);
|
|
||||||
} else {
|
|
||||||
var newFilename = this.baseFilename + this.previousTime;
|
|
||||||
async.series([
|
|
||||||
this.closeTheStream.bind(this),
|
|
||||||
deleteAnyExistingFile,
|
|
||||||
renameTheCurrentFile,
|
|
||||||
this.openTheStream.bind(this)
|
|
||||||
], callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteAnyExistingFile(cb) {
|
|
||||||
//on windows, you can get a EEXIST error if you rename a file to an existing file
|
|
||||||
//so, we'll try to delete the file we're renaming to first
|
|
||||||
fs.unlink(newFilename, function (err) {
|
|
||||||
//ignore err: if we could not delete, it's most likely that it doesn't exist
|
|
||||||
cb();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function renameTheCurrentFile(cb) {
|
|
||||||
debug("Renaming the " + filename + " -> " + newFilename);
|
|
||||||
fs.rename(filename, newFilename, cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user