From cc2e94cf1113fce4deca05b164ce7bd91ae009d7 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Thu, 30 May 2013 07:58:09 +1000 Subject: [PATCH] more linting --- lib/streams/DateRollingFileStream.js | 102 ++++++++++++++------------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/lib/streams/DateRollingFileStream.js b/lib/streams/DateRollingFileStream.js index 69d6668..1007e4d 100644 --- a/lib/streams/DateRollingFileStream.js +++ b/lib/streams/DateRollingFileStream.js @@ -1,16 +1,17 @@ -var BaseRollingFileStream = require('./BaseRollingFileStream'), - format = require('../date_format'), - async = require('async'), - fs = require('fs'), - util = require('util'); +"use strict"; +var BaseRollingFileStream = require('./BaseRollingFileStream') +, format = require('../date_format') +, async = require('async') +, fs = require('fs') +, util = require('util'); module.exports = DateRollingFileStream; var 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 { - debug = function() { }; + debug = function() { }; } 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.baseFilename = filename; this.alwaysIncludePattern = false; - + if (options) { if (options.alwaysIncludePattern) { this.alwaysIncludePattern = true; @@ -37,56 +38,57 @@ function DateRollingFileStream(filename, pattern, options, now) { } } debug("this.now is " + this.now + ", now is " + now); - + DateRollingFileStream.super_.call(this, filename, options); } util.inherits(DateRollingFileStream, BaseRollingFileStream); DateRollingFileStream.prototype.shouldRoll = function() { - var lastTime = this.lastTimeWeWroteSomething, - thisTime = format.asString(this.pattern, new Date(this.now())); - - debug("DateRollingFileStream.shouldRoll with now = " + this.now() + ", thisTime = " + thisTime + ", lastTime = " + lastTime); - - this.lastTimeWeWroteSomething = thisTime; - this.previousTime = lastTime; - - return thisTime !== lastTime; + var lastTime = this.lastTimeWeWroteSomething, + thisTime = format.asString(this.pattern, new Date(this.now())); + + debug("DateRollingFileStream.shouldRoll with now = " + + this.now() + ", thisTime = " + thisTime + ", lastTime = " + lastTime); + + this.lastTimeWeWroteSomething = thisTime; + this.previousTime = lastTime; + + return thisTime !== lastTime; }; DateRollingFileStream.prototype.roll = function(filename, callback) { - 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(); - }); - } + 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(); + }); + } - function renameTheCurrentFile(cb) { - debug("Renaming the " + filename + " -> " + newFilename); - fs.rename(filename, newFilename, cb); - } + function renameTheCurrentFile(cb) { + debug("Renaming the " + filename + " -> " + newFilename); + fs.rename(filename, newFilename, cb); + } };