Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,523 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.git* | ||
examples/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(The MIT License) | ||
|
||
Copyright (c) 2012 Barret Schloerke <schloerke@gmail.com> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
|
||
clean: | ||
@ rm lib/*.js | ||
|
||
compile: | ||
@exec coffee --compile --bare -o lib/ lib/coffee/*.coffee | ||
|
||
watch: | ||
@exec coffee --compile --bare --watch -o lib/ lib/coffee/*.coffee & | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
reqLog | ||
=========== | ||
|
||
reqLog is a Node.js logging library that can | ||
|
||
* print log messages according to your own functions | ||
* be customized per module and per logging level | ||
* have any amount of logging levels | ||
* print statements in full color (background too!!!) | ||
* print statements with console qualities such as "italics" or "bold" | ||
* print messages with module name and current line number so you know from where it was called | ||
* be configured from file or by a module | ||
|
||
Usage | ||
----- | ||
Use npm or download. Then add to your code: | ||
|
||
var log = require('reqLog').with(module); | ||
|
||
*module* is object defined automatically by Node.js. If you don't want automatic module names, replace it with your desired string name. | ||
|
||
log.info(arg1, arg2, arg3); | ||
|
||
Strings arguments are not inspected unless the log level allows for printing of the statement. This avoids unnecessary JSON.stringify calls. | ||
|
||
Examples | ||
-------- | ||
|
||
var log = require('reqLog').with(module); | ||
log.info('Info message'); | ||
log.debug('Debug message'); | ||
log.warn('Warning message'); | ||
log.error('Error message'); | ||
log.trace('Trace message'); | ||
log.info('Array =', [1, 2, 3, 4], '; Object = ', {one: 1, two: 2}); | ||
|
||
|
||
Output samples | ||
-------------- | ||
|
||
2010-10-02 20:39:03.570 INFO main:5 - Info message | ||
2010-10-02 20:39:03.588 DEBUG main:6 - Debug message | ||
2010-10-02 20:39:03.589 WARN main:7 - Warning message | ||
2010-10-02 20:39:03.590 ERROR main:8 - Error message | ||
2010-10-02 20:39:03.590 TRACE main:9 - Trace message | ||
2010-10-02 20:39:03.590 INFO main:10 - Array = [ 1, 2, 3, 4 ], Object = { one: 1, two: 2 } | ||
|
||
Advance Example | ||
--------------- | ||
|
||
var log = require('./examples/max_utilization_helper').with(module); | ||
|
||
// qualifiers to make it a 'req' object | ||
var req = {session: { user: {email: jobs@metamarkets.com } } , route: {}, res: {}, next: {}}; | ||
var fourtyTwo = 42; | ||
log.info(req, "The answer to life the universe and everything: '", fourtyTwo, "'") | ||
// "2012-02-00T00:00:00.000Z; main; jobs@metamarkets.com; INFO ; main:18; The answer to life the universe and everything: '!¿!fourtyTwo!¿!'; 1" | ||
|
||
log.info(req, "Info counter should be at 2. Counter value:") | ||
// "2012-02-00T00:00:00.001Z; main; jobs@metamarkets.com; INFO ; main:21; Info counter should be at 2. Counter value:; 2" | ||
|
||
log.debug(req, "Debug counter should be at 1. Counter value:") | ||
// "2012-02-00T00:00:00.001Z; main; jobs@metamarkets.com; DEBUG; main:24; Debug counter should be at 1. Counter value:; 1" | ||
|
||
log.trace(req, "this should not execute. Level is not included (too low in stack)") | ||
// | ||
|
||
|
||
Take a look at the examples directory for different uses. | ||
|
||
|
||
Changes | ||
------- | ||
0.0.1 - First npm release | ||
|
||
|
||
License | ||
------- | ||
Released under MIT License. Enjoy and Fork! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
reqLog = require('../index.js').options({ | ||
file: "./file_utilization.json" | ||
}) | ||
|
||
|
||
// // ./file.utilization.json | ||
// { | ||
// "logLevels": | ||
// [ { "title": "test" , "color": "magenta"} | ||
// , { "title": "trace", "color": "cyan" } | ||
// , { "title": "debug", "color": "blue" } | ||
// , { "title": "info" , "color": "green" } | ||
// , { "title": "sql" , "color": "magenta"} | ||
// , { "title": "req" , "color": "white" } | ||
// , { "title": "warn" , "color": "yellow" } | ||
// , { "title": "error", "color": "red" , "background": "yellow", "attr": ["bold", "underline"] } | ||
// ] | ||
|
||
// , "fileLevels": | ||
// [ ["*", "error"] | ||
// ["main", "req"] | ||
// ["first_file", "trace"] | ||
// ["second_file", "info"] | ||
// ["custom_file", ["debug", "sql", "warn", "error"]] | ||
// ] | ||
// } | ||
|
||
// // Can produce output with the following levels | ||
// '*' : ['error'] | ||
// 'main' : ['req', 'warn', 'error'] | ||
// 'first_file' : ['trace', 'debug', 'info', 'sql', 'req' ,'warn', 'error'] | ||
// 'second_file': ['info', 'sql', 'req' ,'warn', 'error'] | ||
// 'custom_file': ['debug', 'sql', 'warn', 'error'] // <- does not follow traditional model!!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
{ | ||
"logLevels": | ||
[ { "title": "test" , "color": "magenta"} | ||
, { "title": "trace", "color": "cyan" } | ||
, { "title": "debug", "color": "blue" } | ||
, { "title": "info" , "color": "green" } | ||
, { "title": "sql" , "color": "magenta"} | ||
, { "title": "req" , "color": "white" } | ||
, { "title": "warn" , "color": "yellow" } | ||
, { "title": "error", "color": "red" , "background": "yellow", "attr": ["bold", "underline"] } | ||
] | ||
|
||
, "fileLevels": | ||
[ ["*", "error"] | ||
["main", "req"] | ||
["first_file", "trace"] | ||
["second_file", "info"] | ||
["custom_file", ["debug", "sql", "warn", "error"]] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
|
||
var log = require('./max_utilization_helper').with(module); | ||
|
||
// // Can produce output with the following file and levels | ||
// '*' : ['error'] | ||
// 'main' : ['debug', 'info', 'sql', req', 'warn', 'error'] | ||
// 'first_file' : ['trace', 'debug', 'info', 'sql', 'req' ,'warn', 'error'] | ||
// 'second_file': ['info', 'sql', 'req' ,'warn', 'error'] | ||
// 'custom_file': ['debug', 'sql', 'warn', 'error'] // <- does not follow traditional model!!! | ||
|
||
|
||
var iden = function(d) {return d;}; | ||
|
||
// qualifiers to make it a 'req' object | ||
var req = {session: { user: {email: "jobs@metamarkets.com" } } , route: {}, res: {}, next: iden}; | ||
var fourtyTwo = 42; | ||
log.info(req, "The answer to life the universe and everything: '", fourtyTwo, "'") | ||
// "2012-02-00T00:00:00.000Z; main; jobs@metamarkets.com; INFO ; main:18; The answer to life the universe and everything: '!¿!fourtyTwo!¿!'; 1" | ||
|
||
log.info(req, "Info counter should be at 2. Counter value:") | ||
// "2012-02-00T00:00:00.001Z; main; jobs@metamarkets.com; INFO ; main:21; Info counter should be at 2. Counter value:; 2" | ||
|
||
log.debug(req, "Debug counter should be at 1. Counter value:") | ||
// "2012-02-00T00:00:00.001Z; main; jobs@metamarkets.com; DEBUG; main:24; Debug counter should be at 1. Counter value:; 1" | ||
|
||
log.trace(req, "this should not execute. Level is not included (too low in stack)") | ||
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
var sys = require('sys'); | ||
|
||
function save_to_db(str) { | ||
// do stuff | ||
} | ||
function save_to_console(str) { | ||
sys.puts(str); | ||
// do stuff | ||
} | ||
function save_to_file(str) { | ||
// do stuff | ||
} | ||
|
||
|
||
function my_log_hook_fn(str) { | ||
save_to_db(str); | ||
save_to_console(str); | ||
save_to_file(str); | ||
} | ||
|
||
function my_custom_counter(mod) { | ||
var levelCounterMap = {}; | ||
function counter_by_level(level, args) { | ||
levelCounterMap[level] || (levelCounterMap[level] = 0); | ||
levelCounterMap[level]++; | ||
return levelCounterMap[level]; | ||
} | ||
return counter_by_level; | ||
} | ||
|
||
|
||
var reqLog = require('../index.js') | ||
reqLog.options( | ||
{ color : true // false // true; to force color | ||
, logger : my_log_hook_fn // console.log | ||
, loggerContext : null // console | ||
, seperator : '; ' | ||
, fnArr: | ||
[ reqLog.helper.iso_date() // no options | ||
, reqLog.helper.session_user_email() // no options | ||
, reqLog.helper.level() // no options | ||
, reqLog.helper.file_and_line() // no options | ||
, "-" // plain string to always be inserted | ||
, reqLog.helper.single_line_message_ignore_express_req_at_first({seperator: "!¿!"}) | ||
, my_custom_counter // must execute on function that takes args ['module'], then on a function that takes args ['level', 'args'] | ||
] | ||
|
||
, logLevels: | ||
[ { title: "silly", color: "red" , background: "cyan", attr: ["bold", "italic", "underline", "blink", "inverse", "hidden"]} | ||
, { title: "test" , color: "magenta"} | ||
, { title: "trace", color: "cyan" } | ||
, { title: "debug", color: "blue" } | ||
, { title: "info" , color: "green" } | ||
, { title: "sql" , color: "magenta"} | ||
, { title: "req" , color: "white" } | ||
, { title: "warn" , color: "yellow" } | ||
, { title: "error", color: "red" , background: "black", attr: ["bold", "underline"] } | ||
] | ||
, fileLevels: | ||
[ ["*", "error"] | ||
, ["main", "debug"] | ||
, ["first_file", "trace"] | ||
, ["second_file", "info"] | ||
, ["custom_file", ["debug", "sql", "warn", "error"] ] | ||
] | ||
} | ||
); | ||
|
||
|
||
exports.with = function(mod) { | ||
return reqLog.with(mod); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
reqLog = require('../index.js').options({ | ||
logLevels: | ||
[ { title: "test" , color: "magenta"} | ||
, { title: "trace", color: "cyan" } | ||
, { title: "debug", color: "blue" } | ||
, { title: "info" , color: "green" } | ||
, { title: "sql" , color: "magenta"} | ||
, { title: "req" , color: "white" } | ||
, { title: "warn" , color: "yellow" } | ||
, { title: "error", color: "red" , background: "black", attr: ["bold", "underline"] } | ||
] | ||
, fileLevels: | ||
[ ["*", "error"] | ||
, ["main", "req"] | ||
, ["first_file", "trace"] | ||
, ["second_file", "info"] | ||
// , ["main", ["debug", "sql", "warn", "error"]] // swith this in for main for custom logging! | ||
] | ||
|
||
}) | ||
|
||
var log = reqLog.with("main"); | ||
|
||
// // Can produce output with the following file and levels | ||
// '*' : ['error'] | ||
// 'main' : ['req', 'warn', 'error'] | ||
// 'first_file' : ['trace', 'debug', 'info', 'sql', 'req' ,'warn', 'error'] | ||
// 'second_file': ['info', 'sql', 'req' ,'warn', 'error'] | ||
// 'custom_file': ['debug', 'sql', 'warn', 'error'] // <- does not follow traditional model!!! | ||
log.test( "Test" , 0); | ||
log.trace("Trace" , 1); | ||
log.debug("Debug" , 2); | ||
log.info( "Info" , 3); | ||
log.sql( "Sql" , 4); | ||
log.req( "Req" , 5); | ||
log.warn( "Warn" , 6); | ||
log.error("Error" , 7); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
var log = require('../index.js').with(module); | ||
|
||
|
||
// // Uses the default log levels and file levels | ||
// config.defaultLogLevels = [ | ||
// { title: 'test' , color: 'magenta'} | ||
// { title: 'trace', color: 'cyan' } | ||
// { title: 'debug', color: 'blue' } | ||
// { title: 'info' , color: 'green' } | ||
// { title: 'warn' , color: 'yellow' } | ||
// { title: 'error', color: 'red' , background: 'yellow', attr: ['bold', 'underline']} | ||
// ] | ||
|
||
// config.defaultFileLevels = [ | ||
// ["*", "trace"] | ||
// ] | ||
|
||
|
||
// // All files will produce output with the following levels | ||
// '*': ['trace', 'debug', 'info', 'warn', 'error'] | ||
log.test( "Test" , 0); | ||
log.trace("Trace" , 1); | ||
log.debug("Debug" , 2); | ||
log.info( "Info" , 3); | ||
log.warn( "Warn" , 4); | ||
log.error("Error" , 5); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
module.exports = require('./lib/reqLog'); |
Oops, something went wrong.