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
|
//Time
|
||||||
console.time().log("Print the full time");
|
console.time().log("Print the full time");
|
||||||
console.date().log("Just print the date");
|
console.date().log("Just print the date");
|
||||||
|
//custom time
|
||||||
|
console.time((new Date()).setFullYear(1999)).log("Custom time");
|
||||||
|
|
||||||
//Tags
|
//Tags
|
||||||
console.tag("My Tag").log("Add a tag");
|
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
|
//File and line number
|
||||||
console.file().log("Print the file and the line of the call");
|
console.file().log("Print the file and the line of the call");
|
||||||
|
console.file('myFile.js', 42).log("Custom filename and line");
|
||||||
|
|
||||||
//Object
|
//Object
|
||||||
console.log({just : 'an object'});
|
console.log({just : 'an object'});
|
||||||
|
|
|
@ -269,7 +269,7 @@
|
||||||
*
|
*
|
||||||
* Log time (full date) ?
|
* Log time (full date) ?
|
||||||
*
|
*
|
||||||
* @type {Boolean}
|
* @type {Boolean|Number|String}
|
||||||
*/
|
*/
|
||||||
this._time = false;
|
this._time = false;
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -325,9 +325,11 @@
|
||||||
* Console2.prototype.time
|
* Console2.prototype.time
|
||||||
*
|
*
|
||||||
* Log the time
|
* Log the time
|
||||||
|
*
|
||||||
|
* @param {String|Number} time Optional time if need to override.
|
||||||
*/
|
*/
|
||||||
Console2.prototype.time = function () {
|
Console2.prototype.time = function (time) {
|
||||||
this._time = true;
|
this._time = time || true;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
@ -362,9 +364,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,8 +583,11 @@
|
||||||
*/
|
*/
|
||||||
this[name] = function () {
|
this[name] = function () {
|
||||||
|
|
||||||
var location = getLocation();
|
//use this._location if it's an object (custom location)
|
||||||
var time = Date.now();
|
//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
|
// Let's build the log object
|
||||||
|
|
||||||
|
@ -578,8 +595,8 @@
|
||||||
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 !== false || this.opt.alwaysTime,
|
||||||
date : this._date || this.opt.alwaysDate
|
date : this._date || this.opt.alwaysDate
|
||||||
},
|
},
|
||||||
context : {
|
context : {
|
||||||
|
|
Loading…
Add table
Reference in a new issue