Allow user to force location

This commit is contained in:
Guillaume Wuip 2015-02-02 18:01:15 +01:00
parent 5c4e3b6c89
commit 3a02270c46

View file

@ -287,7 +287,7 @@
* *
* Should we log filename and line number ? * Should we log filename and line number ?
* *
* @type {Boolean} * @type {Boolean|Object}
*/ */
this._location = false; this._location = false;
@ -362,9 +362,21 @@
* Console2.prototype.file * Console2.prototype.file
* *
* Log the file name + line * 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 () { Console2.prototype.file = Console2.prototype.f = function (file, line) {
if (file || line) {
this._location = {
filename : file,
line : line
};
} else {
this._location = true; this._location = true;
}
return this; return this;
}; };
@ -569,7 +581,10 @@
*/ */
this[name] = function () { 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(); var time = Date.now();
// Let's build the log object // Let's build the log object
@ -578,7 +593,7 @@
type : opt.type || name, type : opt.type || name,
show : { show : {
tags : this._tags.length > 0 || this.opt.alwaysTags || opt.defaultTags.length > 0, 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, time : this._time || this.opt.alwaysTime,
date : this._date || this.opt.alwaysDate date : this._date || this.opt.alwaysDate
}, },