From 3a02270c463b8787b6d966e165a04b0528e6f4f2 Mon Sep 17 00:00:00 2001 From: Guillaume Wuip Date: Mon, 2 Feb 2015 18:01:15 +0100 Subject: [PATCH] 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 },