Add default tags

This commit is contained in:
Guillaume Wuip 2015-01-13 18:03:18 +01:00
parent 4335f713b6
commit 2849d7ca0e

View file

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