Merge pull request #32 from guillaumewuip/feature-defaultTags

Feature default tags
This commit is contained in:
Mathew Kurian 2015-01-13 11:09:37 -06:00
commit 61fc60303e
2 changed files with 20 additions and 4 deletions

View file

@ -29,7 +29,11 @@ myConfigConsole.addLogger('fun', ['rainbow', 'inverse', 'black']);
myConfigConsole.fun('Some rainbow in background !');
myConfigConsole.addLogger('log');
myConfigConsole.addLogger('log', null,
{
defaultTags : [{msg : 'Default tag', colors: 'cyan'}]
}
);
myConfigConsole.tag('A tag', 123).log('custom tags');
myConfigConsole.time().log('custom time');

View file

@ -218,6 +218,9 @@
* @param {Boolean} opt.alwaysLocation Always print location (even without file() ). Default false.
* @param {Boolean} opt.alwaysTime Always print time (even without time() ). Default false.
* @param {Boolean} opt.alwaysDate Always print date (even without date() ). Default false.
*
* @param {Array} opt.defaultTags Default tags to logs with each request. Default [].
* See this.tag()
*/
var Console2 = function (opt) {
@ -247,7 +250,9 @@
alwaysTags : opt.alwaysTags === true,
alwaysLocation : opt.alwaysLocation === true,
alwaysTime : opt.alwaysTime === true,
alwaysDate : opt.alwaysDate === true
alwaysDate : opt.alwaysDate === true,
defaultTags : opt.defaultTags || []
};
/**
@ -522,6 +527,9 @@
* @param {Boolean} opt.alwaysLocation Always print location (even without file() )
* @param {Boolean} opt.alwaysTime Always print time (even without time() )
* @param {Boolean} opt.alwaysDate Always print date (even without date() )
*
* @param {Array} opt.defaultTags Default tags to logs with each request. Default undefined.
* See this.tag()
*/
Console2.prototype.addLogger = function (name, colors, opt) {
@ -549,6 +557,10 @@
opt.alwaysTime = opt.alwaysTime || this.opt.alwaysTime;
opt.alwaysDate = opt.alwaysDate || this.opt.alwaysDate;
opt.defaultTags = Array.isArray(opt.defaultTags) ?
opt.defaultTags.concat(this.opt.defaultTags)
: this.opt.defaultTags;
/**
* this.[name]
*
@ -565,13 +577,13 @@
var log = {
type : opt.type || name,
show : {
tags : this._tags.length > 0 || this.opt.alwaysTags,
tags : this._tags.length > 0 || this.opt.alwaysTags || opt.defaultTags.length > 0,
location : this._location || this.opt.alwaysLocation,
time : this._time || this.opt.alwaysTime,
date : this._date || this.opt.alwaysDate
},
context : {
tags : this._tags,
tags : opt.defaultTags.concat(this._tags),
file : this._location,
time : time,
location : location