From 3a02270c463b8787b6d966e165a04b0528e6f4f2 Mon Sep 17 00:00:00 2001 From: Guillaume Wuip Date: Mon, 2 Feb 2015 18:01:15 +0100 Subject: [PATCH 1/4] Allow user to force location --- lib/console2.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/console2.js b/lib/console2.js index e28397e..bf08ddf 100644 --- a/lib/console2.js +++ b/lib/console2.js @@ -287,7 +287,7 @@ * * Should we log filename and line number ? * - * @type {Boolean} + * @type {Boolean|Object} */ this._location = false; @@ -362,9 +362,21 @@ * Console2.prototype.file * * Log the file name + line + * You could force the filename and line by passing args. + * + * @param {String} file Filename. Optional + * @param {String|Number} line Line. Optional */ - Console2.prototype.file = Console2.prototype.f = function () { - this._location = true; + Console2.prototype.file = Console2.prototype.f = function (file, line) { + + if (file || line) { + this._location = { + filename : file, + line : line + }; + } else { + this._location = true; + } return this; }; @@ -569,7 +581,10 @@ */ this[name] = function () { - var location = getLocation(); + //use this._location if it's an object (custom location) + //or build the location + var location = (this._location || this.opt.alwaysLocation) === true ? getLocation() : this._location; + var time = Date.now(); // Let's build the log object @@ -578,7 +593,7 @@ type : opt.type || name, show : { tags : this._tags.length > 0 || this.opt.alwaysTags || opt.defaultTags.length > 0, - location : this._location || this.opt.alwaysLocation, + location : this._location !== false || this.opt.alwaysLocation, time : this._time || this.opt.alwaysTime, date : this._date || this.opt.alwaysDate }, From 19728e4a2409726d71eaafee97abe2bb0c1d73c1 Mon Sep 17 00:00:00 2001 From: Guillaume Wuip Date: Mon, 2 Feb 2015 18:10:42 +0100 Subject: [PATCH 2/4] Add custom location example --- examples/console2.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/console2.js b/examples/console2.js index d66e39b..8108b9d 100644 --- a/examples/console2.js +++ b/examples/console2.js @@ -22,6 +22,7 @@ console.tag({msg : 'my-tag', colors : ['red', 'inverse']}).log("Use colors.js co //File and line number console.file().log("Print the file and the line of the call"); +console.file('myFile.js', 42).log("Custom filename and line"); //Object console.log({just : 'an object'}); From 2747cff88eea033694a4e2a45b355f1b221955f3 Mon Sep 17 00:00:00 2001 From: Guillaume Wuip Date: Mon, 2 Feb 2015 18:13:32 +0100 Subject: [PATCH 3/4] Allow custom time --- lib/console2.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/console2.js b/lib/console2.js index bf08ddf..65327ce 100644 --- a/lib/console2.js +++ b/lib/console2.js @@ -269,7 +269,7 @@ * * Log time (full date) ? * - * @type {Boolean} + * @type {Boolean|Number|String} */ this._time = false; @@ -325,9 +325,11 @@ * Console2.prototype.time * * Log the time + * + * @param {String|Number} time Optional time if need to override. */ - Console2.prototype.time = function () { - this._time = true; + Console2.prototype.time = function (time) { + this._time = time || true; return this; }; @@ -585,7 +587,7 @@ //or build the location var location = (this._location || this.opt.alwaysLocation) === true ? getLocation() : this._location; - var time = Date.now(); + var time = (typeof this._time !== 'boolean') ? this._time : Date.now(); // Let's build the log object @@ -594,7 +596,7 @@ show : { tags : this._tags.length > 0 || this.opt.alwaysTags || opt.defaultTags.length > 0, location : this._location !== false || this.opt.alwaysLocation, - time : this._time || this.opt.alwaysTime, + time : this._time !== false || this.opt.alwaysTime, date : this._date || this.opt.alwaysDate }, context : { From 0f8a327c893c95a71443ab2c033d4c88eb296f7e Mon Sep 17 00:00:00 2001 From: Guillaume Wuip Date: Mon, 2 Feb 2015 18:13:52 +0100 Subject: [PATCH 4/4] Example custom time --- examples/console2.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/console2.js b/examples/console2.js index 8108b9d..0a8320f 100644 --- a/examples/console2.js +++ b/examples/console2.js @@ -14,6 +14,8 @@ console.log("A string %s and a number %d", "hello", "123"); //you can use printf //Time console.time().log("Print the full time"); console.date().log("Just print the date"); +//custom time +console.time((new Date()).setFullYear(1999)).log("Custom time"); //Tags console.tag("My Tag").log("Add a tag");