From 2849d7ca0e3fe0f75bdd60bcc7d29da9870fe659 Mon Sep 17 00:00:00 2001 From: Guillaume Wuip Date: Tue, 13 Jan 2015 18:03:18 +0100 Subject: [PATCH] Add default tags --- lib/console2.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/console2.js b/lib/console2.js index cecc263..e28397e 100644 --- a/lib/console2.js +++ b/lib/console2.js @@ -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