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) {
|
||||||
@ -43,50 +44,51 @@ function DateRollingFileStream(filename, pattern, options, now) {
|
|||||||
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.lastTimeWeWroteSomething = thisTime;
|
||||||
this.previousTime = lastTime;
|
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");
|
debug("Starting roll");
|
||||||
|
|
||||||
if (this.alwaysIncludePattern) {
|
if (this.alwaysIncludePattern) {
|
||||||
this.filename = this.baseFilename + this.lastTimeWeWroteSomething;
|
this.filename = this.baseFilename + this.lastTimeWeWroteSomething;
|
||||||
async.series([
|
async.series([
|
||||||
this.closeTheStream.bind(this),
|
this.closeTheStream.bind(this),
|
||||||
this.openTheStream.bind(this)
|
this.openTheStream.bind(this)
|
||||||
], callback);
|
], callback);
|
||||||
} else {
|
} else {
|
||||||
var newFilename = this.baseFilename + this.previousTime;
|
var newFilename = this.baseFilename + this.previousTime;
|
||||||
async.series([
|
async.series([
|
||||||
this.closeTheStream.bind(this),
|
this.closeTheStream.bind(this),
|
||||||
deleteAnyExistingFile,
|
deleteAnyExistingFile,
|
||||||
renameTheCurrentFile,
|
renameTheCurrentFile,
|
||||||
this.openTheStream.bind(this)
|
this.openTheStream.bind(this)
|
||||||
], callback);
|
], callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteAnyExistingFile(cb) {
|
function deleteAnyExistingFile(cb) {
|
||||||
//on windows, you can get a EEXIST error if you rename a file to an existing file
|
//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
|
//so, we'll try to delete the file we're renaming to first
|
||||||
fs.unlink(newFilename, function (err) {
|
fs.unlink(newFilename, function (err) {
|
||||||
//ignore err: if we could not delete, it's most likely that it doesn't exist
|
//ignore err: if we could not delete, it's most likely that it doesn't exist
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function renameTheCurrentFile(cb) {
|
function renameTheCurrentFile(cb) {
|
||||||
debug("Renaming the " + filename + " -> " + newFilename);
|
debug("Renaming the " + filename + " -> " + newFilename);
|
||||||
fs.rename(filename, newFilename, cb);
|
fs.rename(filename, newFilename, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user