mirror of
https://github.com/mathew-kurian/Scribe.js
synced 2025-08-23 01:51:23 +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;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
function Extender(tag, opts) {
|
function Extender(tag, opts, mode) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.tag = tag;
|
self.tag = tag;
|
||||||
self.opts = opts;
|
self.opts = opts;
|
||||||
|
self.mode = mode;
|
||||||
|
|
||||||
self.do = self.invoke = self.should = function(actual) {
|
self.do = self.invoke = self.should = function(actual) {
|
||||||
|
|
||||||
|
@ -325,25 +326,50 @@ self.express.controlPanel = function() {
|
||||||
// Additional Features
|
// Additional Features
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
|
|
||||||
console.t = console.tag = function(n) {
|
console.t = function(n, _) {
|
||||||
return new Extender(n ? tag(n) : activeDefaultTag);
|
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) {
|
console.f = function(n, _) {
|
||||||
|
|
||||||
var _tag;
|
|
||||||
|
|
||||||
if (!n) {
|
if (!n) {
|
||||||
var st = stack()[1];
|
var st = stack()[1];
|
||||||
_tag = tag(path.basename(st.getFileName()) + ":" + st.getLineNumber());
|
n = path.basename(st.getFileName());
|
||||||
} else {
|
} 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]);
|
tag = tag ? tag : stackTag(stack()[1]);
|
||||||
return new Extender(tag, name, stack()[1]);
|
return new Extender(tag, name, stack()[1]);
|
||||||
};
|
};
|
||||||
|
@ -352,7 +378,12 @@ function addPipe(n) {
|
||||||
|
|
||||||
Extender.prototype[n] = function() {
|
Extender.prototype[n] = function() {
|
||||||
var args = Array.prototype.splice.call(arguments, 0);
|
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);
|
console[n].apply(this, args);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -426,4 +457,4 @@ try {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("SCRIBE WARNING: Express not installed - visual web logger is disabled.");
|
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('divider', ':::');
|
||||||
scribe.set('identation', 5); // Identation before console messages
|
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
|
// 30 characters will be ignored
|
||||||
|
|
||||||
// scribe.set('mainUser', 'root'); // Username of the account which is running
|
// scribe.set('mainUser', 'root'); // Username of the account which is running
|
||||||
|
@ -54,7 +54,7 @@ exports['read'] = {
|
||||||
|
|
||||||
// Basic logging
|
// 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.realtime("[Tagname] Your message"); // [Tagname] Your message
|
||||||
console.high("[Tagname] Your message "); // [Tagname] Your message
|
console.high("[Tagname] Your message "); // [Tagname] Your message
|
||||||
console.normal("[Tagname][]Your message"); // [Tagname] []Your message
|
console.normal("[Tagname][]Your message"); // [Tagname] []Your message
|
||||||
|
@ -82,10 +82,63 @@ exports['read'] = {
|
||||||
// -----------
|
// -----------
|
||||||
(function(console) {
|
(function(console) {
|
||||||
|
|
||||||
console.info("yeeha"); // [scoped-tag] yeeha
|
console.info("yeeha");
|
||||||
console.log("yeeha"); // [scoped-tag] 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.equal(true, true);
|
||||||
test.done();
|
test.done();
|
||||||
|
|
Loading…
Add table
Reference in a new issue