forked from mirrors/Scribe.js
Merge pull request #38 from guillaumewuip/feature-customTimeLocation
Feature custom time and location
This commit is contained in:
commit
108d5f0072
2 changed files with 30 additions and 10 deletions
|
@ -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");
|
||||
|
@ -22,6 +24,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'});
|
||||
|
|
|
@ -269,7 +269,7 @@
|
|||
*
|
||||
* Log time (full date) ?
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @type {Boolean|Number|String}
|
||||
*/
|
||||
this._time = false;
|
||||
|
||||
|
@ -287,7 +287,7 @@
|
|||
*
|
||||
* Should we log filename and line number ?
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @type {Boolean|Object}
|
||||
*/
|
||||
this._location = 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;
|
||||
};
|
||||
|
@ -362,9 +364,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,8 +583,11 @@
|
|||
*/
|
||||
this[name] = function () {
|
||||
|
||||
var location = getLocation();
|
||||
var time = Date.now();
|
||||
//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 = (typeof this._time !== 'boolean') ? this._time : Date.now();
|
||||
|
||||
// Let's build the log object
|
||||
|
||||
|
@ -578,8 +595,8 @@
|
|||
type : opt.type || name,
|
||||
show : {
|
||||
tags : this._tags.length > 0 || this.opt.alwaysTags || opt.defaultTags.length > 0,
|
||||
location : this._location || this.opt.alwaysLocation,
|
||||
time : this._time || this.opt.alwaysTime,
|
||||
location : this._location !== false || this.opt.alwaysLocation,
|
||||
time : this._time !== false || this.opt.alwaysTime,
|
||||
date : this._date || this.opt.alwaysDate
|
||||
},
|
||||
context : {
|
||||
|
|
Loading…
Add table
Reference in a new issue