mirror of
https://github.com/mathew-kurian/Scribe.js
synced 2025-08-23 18:11:24 +00:00
Scoping tag functionality improved
Please refer to /test/usage.js for examples
This commit is contained in:
parent
0ab884d6b3
commit
0f73347841
3 changed files with 113 additions and 19 deletions
55
index.js
55
index.js
|
@ -123,12 +123,13 @@ var validate = function() {
|
|||
return false;
|
||||
};
|
||||
|
||||
function Extender(tag, opts) {
|
||||
function Extender(tag, opts, mode) {
|
||||
|
||||
var self = this;
|
||||
|
||||
self.tag = tag;
|
||||
self.opts = opts;
|
||||
self.mode = mode;
|
||||
|
||||
self.do = self.invoke = self.should = function(actual) {
|
||||
|
||||
|
@ -325,25 +326,50 @@ self.express.controlPanel = function() {
|
|||
// Additional Features
|
||||
// ---------------------------------
|
||||
|
||||
console.t = console.tag = function(n) {
|
||||
return new Extender(n ? tag(n) : activeDefaultTag);
|
||||
console.t = function(n, _) {
|
||||
n = _ ? _ + ":" + n : n;
|
||||
var _tag = n;
|
||||
var ext = new Extender(n ? tag(n) : activeDefaultTag);
|
||||
ext.t = function() {
|
||||
return console.t.call(console, arguments[0], _tag);
|
||||
};
|
||||
|
||||
ext.t = function() {
|
||||
return console.t.call(console, arguments[0], _tag);
|
||||
};
|
||||
|
||||
return ext;
|
||||
};
|
||||
|
||||
console.f = console.file = function(n) {
|
||||
|
||||
var _tag;
|
||||
console.f = function(n, _) {
|
||||
|
||||
if (!n) {
|
||||
var st = stack()[1];
|
||||
_tag = tag(path.basename(st.getFileName()) + ":" + st.getLineNumber());
|
||||
n = path.basename(st.getFileName());
|
||||
} else {
|
||||
_tag = tag(path.basename(n));
|
||||
n = path.basename(n);
|
||||
}
|
||||
|
||||
return new Extender(_tag);
|
||||
(n = _ ? _ + ":" + n : n);
|
||||
|
||||
var _tag = n;
|
||||
var ext = new Extender(n ? n : activeDefaultTag, undefined, "f");
|
||||
|
||||
ext.f = function() {
|
||||
return console.f.call(console, arguments[0], _tag);
|
||||
};
|
||||
|
||||
ext.t = function() {
|
||||
return console.t.call(console, arguments[0], _tag);
|
||||
};
|
||||
|
||||
return ext;
|
||||
};
|
||||
|
||||
console.assert = console.test = function(name, tag) {
|
||||
Extender.prototype.test =
|
||||
Extender.prototype.asset =
|
||||
console.assert =
|
||||
console.test = function(name, tag) {
|
||||
tag = tag ? tag : stackTag(stack()[1]);
|
||||
return new Extender(tag, name, stack()[1]);
|
||||
};
|
||||
|
@ -352,7 +378,12 @@ function addPipe(n) {
|
|||
|
||||
Extender.prototype[n] = function() {
|
||||
var args = Array.prototype.splice.call(arguments, 0);
|
||||
args.unshift(this.tag + args.shift());
|
||||
if (this.mode === "f") {
|
||||
var st = stack()[1];
|
||||
args.unshift(tag(this.tag + ":" + st.getLineNumber()) + args.shift());
|
||||
} else {
|
||||
args.unshift(this.tag + args.shift());
|
||||
}
|
||||
console[n].apply(this, args);
|
||||
};
|
||||
|
||||
|
@ -426,4 +457,4 @@ try {
|
|||
}
|
||||
} catch (e) {
|
||||
console.warn("SCRIBE WARNING: Express not installed - visual web logger is disabled.");
|
||||
}
|
||||
}
|
14
package.json
14
package.json
File diff suppressed because one or more lines are too long
|
@ -35,7 +35,7 @@ exports['read'] = {
|
|||
scribe.set('divider', ':::');
|
||||
scribe.set('identation', 5); // Identation before console messages
|
||||
|
||||
scribe.set('maxTagLength', 30); // Any tags that have a length greather than
|
||||
scribe.set('maxTagLength', 50); // Any tags that have a length greather than
|
||||
// 30 characters will be ignored
|
||||
|
||||
// scribe.set('mainUser', 'root'); // Username of the account which is running
|
||||
|
@ -54,7 +54,7 @@ exports['read'] = {
|
|||
|
||||
// Basic logging
|
||||
// --------------
|
||||
console.log("[Tagname] Your message"); // [Tagname] Your message
|
||||
console.log("[Tagname] Your message"); // [Tagname] Your message
|
||||
console.realtime("[Tagname] Your message"); // [Tagname] Your message
|
||||
console.high("[Tagname] Your message "); // [Tagname] Your message
|
||||
console.normal("[Tagname][]Your message"); // [Tagname] []Your message
|
||||
|
@ -82,10 +82,63 @@ exports['read'] = {
|
|||
// -----------
|
||||
(function(console) {
|
||||
|
||||
console.info("yeeha"); // [scoped-tag] yeeha
|
||||
console.log("yeeha"); // [scoped-tag] yeeha
|
||||
console.info("yeeha");
|
||||
console.log("yeeha");
|
||||
|
||||
})(console.t('scoped-tag'));
|
||||
// Tag Scoping
|
||||
// -----------
|
||||
(function(console) {
|
||||
|
||||
// Tag Scoping
|
||||
// -----------
|
||||
(function(console) {
|
||||
|
||||
console.info("yeeha");
|
||||
console.log("yeeha");
|
||||
|
||||
})(console.t('l3'));
|
||||
|
||||
console.info("yeeha");
|
||||
console.log("yeeha");
|
||||
|
||||
})(console.t('l2'));
|
||||
|
||||
})(console.t('l1'));
|
||||
|
||||
|
||||
// File Scoping
|
||||
// -----------
|
||||
(function(console) {
|
||||
|
||||
console.info("yeeha");
|
||||
console.log("yeeha");
|
||||
|
||||
// File Scoping
|
||||
// -----------
|
||||
(function(console) {
|
||||
|
||||
// File Scoping
|
||||
// -----------
|
||||
(function(console) {
|
||||
|
||||
// Note: a use of console.t(...) resets the
|
||||
console.t("LOL").info("yeeha");
|
||||
|
||||
console.info("yeeha");
|
||||
console.log("yeeha");
|
||||
|
||||
})(console.f());
|
||||
|
||||
console.info("yeeha");
|
||||
console.log("yeeha");
|
||||
|
||||
})(console.f());
|
||||
|
||||
})(console.f());
|
||||
|
||||
// Simple Testing
|
||||
// --------------
|
||||
console.test("Test name").should(5).be(5); // Pretty printed test results
|
||||
|
||||
test.equal(true, true);
|
||||
test.done();
|
||||
|
|
Loading…
Add table
Reference in a new issue