diff --git a/index.js b/index.js index c4c20f8..97a4188 100644 --- a/index.js +++ b/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."); -} +} \ No newline at end of file diff --git a/package.json b/package.json index 53517e9..8c8765f 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,11 @@ "version": "0.1.0", "homepage": "https://github.com/bluejamesbond/Scribe.js", "keywords": [], - "author": "Mathew Kurian (https://github.com/bluejamesbond)", + "author": { + "name": "Mathew Kurian", + "email": "MathewKurian@utexas.edu", + "url": "https://github.com/bluejamesbond" + }, "repository": { "type": "git", "url": "git://github.com/bluejamesbond/Scribe.js.git" @@ -46,5 +50,11 @@ "grunt-contrib-watch": "^0.6.1", "mkdirp": "^0.5.0", "moment": "^2.8.0" - } + }, + "readme": "![Logo](__misc/scribejs design logo [a].png)\r\n=======\r\n**Lightweight NodeJS Logging**\r\nOverview\r\n=======\r\nUnlike many of the libraries out there, Scribe.js allows logging on multiple files and is divided into folders by date. And it is possibly the easiest logging you can implement. And it does everything you need a basic logger to do.\r\n- Save messages into log files organized by user, date, and type\r\n- Print messages into console using colors indicating level of importance\r\n\r\nOutput Methods (Web | Console | File)\r\n=======\r\nMethod#Web - Select Date\r\n---\r\n![Control Panel View 1](http://i.imgur.com/sXyDc09.png)\r\nMethod#Web - Select Log Type\r\n---\r\n![Control Panel View 1](http://i.imgur.com/NgCa8tR.png)\r\nMethod#Web - View Logs\r\n---\r\n![Control Panel View 1](http://i.imgur.com/ULkKn1X.png)\r\nMethod#Console - Command Prompt\r\n---\r\n![Command Prompt output](https://raw.github.com/bluejamesbond/Scribe.js/master/__misc/scribejs%20sample%20cmd%20%5Ba%5D.PNG)\r\nMethod#File - File\r\n---\r\n![Files output](https://raw.github.com/bluejamesbond/Scribe.js/master/__misc/scribejs%20sample%20file%20%5Ba%5D.PNG)\r\nMethod#File - Directory Layout\r\n---\r\n![Files Directory](https://raw.github.com/bluejamesbond/Scribe.js/master/__misc/scribejs%20sample%20directory%20%5Ba%5D.PNG)\r\n\r\nInstallation\r\n=======\r\n```\r\nnpm install git+https://github.com/bluejamesbond/Scribe.js.git\r\n```\r\nDocumentation\r\n=======\r\n```js\r\nvar scribe = require('scribe'); \r\n\r\n// Configuration\r\n// --------------\r\nscribe.configure(function(){\r\n scribe.set('app', 'MY_APP_NAME'); // NOTE Best way learn about these settings is\r\n scribe.set('logPath', './logs'); // Doublecheck // them out for yourself.\r\n scribe.set('defaultTag', 'DEFAULT_TAG');\r\n scribe.set('divider', ':::');\r\n scribe.set('identation', 5); // Identation before console messages\r\n \r\n scribe.set('maxTagLength', 30); // Any tags that have a length greather than\r\n // 30 characters will be ignored\r\n \r\n scribe.set('mainUser', 'root'); // Username of the account which is running\r\n // the NodeJS server\r\n});\r\n\r\n// Create Loggers\r\n// --------------\r\nscribe.addLogger(\"log\", true , true, 'green'); // (name, save to file, print to console,\r\nscribe.addLogger('realtime', true, true, 'underline'); // tag color)\r\nscribe.addLogger('high', true, true, 'magenta');\r\nscribe.addLogger('normal', true, true, 'white');\r\nscribe.addLogger('low', true, true, 'grey');\r\nscribe.addLogger('info', true, true, 'cyan');\r\n\r\n// Express.js\r\n// WARNING: ExpressJS must be installed for this to work\r\n// You also need to start an ExpressJS server in order for\r\n// this to work.\r\n// --------------\r\napp.use(scribe.express.logger(function(req, res){ // Express.js access log\r\n return true; // Filter out any Express messages\r\n}));\r\n\r\n// Control Panel\r\n// WARNING: ExpressJS must be installed for this to work\r\n// You also need to start an ExpressJS server in order for\r\n// this to work.\r\n// --------------\r\napp.get('/log', scribe.express.controlPanel()); // Enable web control panel\r\n\r\n// Basic logging\r\n// --------------\r\nconsole.log(\"[Tagname] Your message\"); // [Tagname] Your message \r\nconsole.realtime(\"[Tagname] Your message\"); // [Tagname] Your message\r\nconsole.high(\"[Tagname] Your message \"); // [Tagname] Your message\r\nconsole.normal(\"[Tagname][]Your message\"); // [Tagname] []Your message\r\nconsole.low(\"[Tagname]Your message\"); // [Tagname] Your message\r\n\r\n// Tagging function\r\n// ----------------\r\nconsole.t(\"Tagname\").log(\"Your message\"); // [Tagname] Your message\r\nconsole.t(\"Tagname\").log(\"Your message\"); // [Tagname] Your message\r\nconsole.t(\"Tagname\").log(\"Your message\"); // [Tagname] Your message\r\n\r\n// Force use default tag\r\n// ---------------------\r\nconsole.t().log(\"Your message\"); // [MY_APP_NAME] Your message\r\n\r\n// Pass in file name\r\n// -----------------\r\nconsole.f(__filename).log(\"Your message\"); // [file.js] Your message\r\n\r\n// Auto tagging\r\n// ------------\r\nconsole.log(\"Your message\"); // [invokedFrom.js:25] Your message\r\n\r\n// Tag Scoping\r\n// -----------\r\n(function(console){\r\n\r\n console.info(\"yeeha\"); // [scoped-tag] yeeha\r\n console.log(\"yeeha\"); // [scoped-tag] yeeha\r\n \r\n})(console.t('scoped-tag'));\r\n\r\n```\r\nExperimental\r\n=======\r\n```js\r\n// Simple Testing\r\n// --------------\r\nconsole.test(\"Test name\").should(5).be(5); // Pretty printed test results \r\n```\r\nContributors\r\n=======\r\n```\r\nbluejamesbond\r\n```\r\n", + "readmeFilename": "README.md", + "_id": "scribe@0.1.0", + "_shasum": "0c1760410b7b3bbcea562fd8ed1aba90d6cc06a3", + "_resolved": "git+https://github.com/bluejamesbond/Scribe.js.git#0ab884d6b39ce79a431a23f683358c50a0508812", + "_from": "git+https://github.com/bluejamesbond/Scribe.js.git" } diff --git a/test/usage.js b/test/usage.js index adfd1df..f18e7a3 100644 --- a/test/usage.js +++ b/test/usage.js @@ -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();