-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calling color_console instead of console from daily logger, so color …
…console configuration can work.
- Loading branch information
1 parent
ceaeeed
commit d28da8d
Showing
2 changed files
with
58 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,59 @@ | ||
var fs = require('fs'),dateFormat = require('dateformat'), tinytim = require('tinytim'), utils = require('./utils'); | ||
var fs = require('fs'), dateFormat = require('dateformat'), tinytim = require('tinytim'), utils = require('./utils'); | ||
var path = require('path'); | ||
|
||
module.exports = function(conf) { | ||
var _conf = { | ||
root : '.', | ||
logPathFormat : '{{root}}/{{prefix}}.{{date}}.log', | ||
splitFormat : 'yyyymmdd' | ||
}; | ||
_conf = utils.union(_conf, [conf]); | ||
function LogFile(prefix, date) { | ||
this.date = date; | ||
this.prefix = prefix; | ||
this.path = tinytim.tim(_conf.logPathFormat, {root:_conf.root, prefix:prefix, date:date}); | ||
(function mkdirSync_p(dir) { | ||
if (fs.existsSync(dir)) return; | ||
mkdirSync_p(path.dirname(dir)); | ||
fs.mkdirSync(dir); | ||
})(_conf.root); | ||
this.stream = fs.createWriteStream(this.path, { | ||
flags: "a", | ||
encoding: "utf8", | ||
mode: 0666 | ||
}); | ||
} | ||
|
||
LogFile.prototype.write = function(str) { | ||
this.stream.write(str+"\n"); | ||
}; | ||
|
||
LogFile.prototype.destroy = function() { | ||
if (this.stream) { | ||
this.stream.end(); | ||
this.stream.destroySoon(); | ||
this.stream = null; | ||
} | ||
}; | ||
|
||
var _logMap = {}; | ||
|
||
function _push2File(str, title) { | ||
var logFile = _logMap[title], now = dateFormat(new Date(), _conf.splitFormat) | ||
if(logFile && logFile.date != now) { | ||
logFile.destroy(); | ||
logFile = null; | ||
} | ||
if(!logFile) | ||
logFile = _logMap[title] = new LogFile(title, now); | ||
logFile.write(str); | ||
} | ||
|
||
return require('./console')({ | ||
transport : function(data) { | ||
_push2File(data.output, data.title); | ||
} | ||
}, conf); | ||
}; | ||
module.exports = function (conf) { | ||
var _conf = { | ||
root: '.', | ||
logPathFormat: '{{root}}/{{prefix}}.{{date}}.log', | ||
splitFormat: 'yyyymmdd' | ||
}; | ||
|
||
_conf = utils.union(_conf, [conf]); | ||
|
||
function LogFile(prefix, date) { | ||
this.date = date; | ||
this.prefix = prefix; | ||
this.path = tinytim.tim(_conf.logPathFormat, {root: _conf.root, prefix: prefix, date: date}); | ||
(function mkdirSync_p(dir) { | ||
if (fs.existsSync(dir)) return; | ||
mkdirSync_p(path.dirname(dir)); | ||
fs.mkdirSync(dir); | ||
})(_conf.root); | ||
this.stream = fs.createWriteStream(this.path, { | ||
flags: "a", | ||
encoding: "utf8", | ||
mode: 0666 | ||
}); | ||
} | ||
|
||
LogFile.prototype.write = function (str) { | ||
this.stream.write(str + "\n"); | ||
}; | ||
|
||
LogFile.prototype.destroy = function () { | ||
if (this.stream) { | ||
this.stream.end(); | ||
this.stream.destroySoon(); | ||
this.stream = null; | ||
} | ||
}; | ||
|
||
var _logMap = {}; | ||
|
||
function _push2File(str, title) { | ||
var logFile = _logMap[title], now = dateFormat(new Date(), _conf.splitFormat); | ||
if (logFile && logFile.date != now) { | ||
logFile.destroy(); | ||
logFile = null; | ||
} | ||
if (!logFile) | ||
logFile = _logMap[title] = new LogFile(title, now); | ||
logFile.write(str); | ||
} | ||
|
||
return require('./color_console')({ | ||
transport: function (data) { | ||
_push2File(data.output, data.title); | ||
} | ||
}, conf); | ||
}; |