{"_id":"custom-logger","_rev":"900643","name":"custom-logger","description":"Simple yet highly customizable console logger for node.js. Supports templating output, custom log levels, custom log types, and colored output.","dist-tags":{"latest":"0.3.1"},"maintainers":[{"name":"felixmc","email":"felixmilea@gmail.com"}],"time":{"modified":"2021-09-18T10:23:17.000Z","created":"2012-05-21T21:40:55.298Z","0.3.1":"2015-06-11T05:46:00.858Z","0.3.0":"2014-08-08T03:15:51.223Z","0.2.1":"2012-05-22T05:46:40.842Z","0.2.0":"2012-05-22T05:37:07.445Z","0.1.0":"2012-05-21T21:40:55.298Z"},"users":{"johnsmithcoder":true,"tunnckocore":true,"felixmc":true,"f124275809":true},"author":{"name":"Felix Milea-Ciobanu","email":"felixmilea@gmail.com","url":"http://felixmc.com/"},"repository":{"type":"git","url":"http://github.com/felixmc/custom-logger.git"},"versions":{"0.3.1":{"name":"custom-logger","description":"Simple yet highly customizable console logger for node.js. Supports templating output, custom log levels, custom log types, and colored output.","version":"0.3.1","author":{"name":"Felix Milea-Ciobanu","email":"felixmilea@gmail.com","url":"http://felixmc.com/"},"repository":{"type":"git","url":"http://github.com/felixmc/custom-logger.git"},"main":"logger","engines":{"node":">=0.1.90"},"dependencies":{"colors":"0.6.0-1","dateformat":"1.0.2-1.2.3"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/MIT"}],"keywords":["log","logger","logging","color","colour","timestamp","custom","console","warning","error","debug","template"],"gitHead":"7e4539369079de19c9bb418f642c5a0cdac9276f","bugs":{"url":"https://github.com/felixmc/custom-logger/issues"},"homepage":"https://github.com/felixmc/custom-logger","_id":"custom-logger@0.3.1","scripts":{},"_shasum":"0844d44c9435631c38d7239724db8af6f0baee64","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"felixmc","email":"felixmilea@gmail.com"},"maintainers":[{"name":"felixmc","email":"felixmilea@gmail.com"}],"dist":{"shasum":"0844d44c9435631c38d7239724db8af6f0baee64","size":10362,"noattachment":false,"key":"/custom-logger/-/custom-logger-0.3.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/custom-logger/download/custom-logger-0.3.1.tgz"},"directories":{},"publish_time":1434001560858,"_cnpm_publish_time":1434001560858,"_hasShrinkwrap":false},"0.3.0":{"name":"custom-logger","description":"Simple yet highly customizable console logger for node.js. Supports templating output, custom log levels, custom log types, and colored output.","version":"0.3.0","author":{"name":"Felix Milea-Ciobanu","email":"felixmilea@gmail.com","url":"http://felixmc.com/"},"repository":{"type":"git","url":"http://github.com/felixmc/custom-logger.git"},"main":"logger","engines":{"node":">=0.1.90"},"dependencies":{"colors":"0.6.0-1","dateformat":"1.0.2-1.2.3"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/MIT"}],"keywords":["log","logger","logging","color","colour","timestamp","custom","console","warning","error","debug","template"],"gitHead":"e65e0ff4ef3e8f6c24eeff726d9bcf7ef538038c","bugs":{"url":"https://github.com/felixmc/custom-logger/issues"},"homepage":"https://github.com/felixmc/custom-logger","_id":"custom-logger@0.3.0","scripts":{},"_shasum":"b8e567c28d4672cc1feab1f424d93c8111673734","_from":".","_npmVersion":"1.4.13","_npmUser":{"name":"felixmc","email":"felixmilea@gmail.com"},"maintainers":[{"name":"felixmc","email":"felixmilea@gmail.com"}],"dist":{"shasum":"b8e567c28d4672cc1feab1f424d93c8111673734","size":12726,"noattachment":false,"key":"/custom-logger/-/custom-logger-0.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/custom-logger/download/custom-logger-0.3.0.tgz"},"directories":{},"publish_time":1407467751223,"_cnpm_publish_time":1407467751223,"_hasShrinkwrap":false},"0.2.1":{"name":"custom-logger","description":"Simple yet highly customizable console logger for node.js. Supports templating output, custom log levels, custom log types, and colored output.","version":"0.2.1","author":{"name":"Felix Milea-Ciobanu","email":"felixmilea@gmail.com","url":"http://felixmc.com/"},"repository":{"type":"git","url":"git://github.com/felixmc/custom-logger.git"},"main":"logger","engines":{"node":">=0.1.90"},"dependencies":{"colors":"0.6.0-1","dateformat":"1.0.2-1.2.3"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/MIT"}],"keywords":["log","logger","logging","color","colour","timestamp","custom","console","warning","error","debug","template"],"_npmUser":{"name":"felixmc","email":"felixmilea@gmail.com"},"_id":"custom-logger@0.2.1","devDependencies":{},"optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.1","_nodeVersion":"v0.6.11","_defaultsLoaded":true,"dist":{"shasum":"8c45801908e9a6195564a425b56cb5bba93f7b5c","size":9193,"noattachment":false,"key":"/custom-logger/-/custom-logger-0.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/custom-logger/download/custom-logger-0.2.1.tgz"},"maintainers":[{"name":"felixmc","email":"felixmilea@gmail.com"}],"directories":{},"publish_time":1337665600842,"_cnpm_publish_time":1337665600842,"_hasShrinkwrap":false},"0.2.0":{"name":"custom-logger","description":"Simple yet highly customizable console logger for node.js. Supports templating output, custom log levels, custom log types, and colored output.","version":"0.2.0","author":{"name":"Felix Milea-Ciobanu","email":"felixmilea@gmail.com","url":"http://felixmc.com/"},"repository":{"type":"git","url":"git://github.com/felixmc/custom-logger.git"},"main":"logger","engines":{"node":">=0.1.90"},"dependencies":{"colors":"0.6.0-1","dateformat":"1.0.2-1.2.3"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/MIT"}],"keywords":["log","logger","logging","color","colour","timestamp","custom","console","warning","error","debug","template"],"_npmUser":{"name":"felixmc","email":"felixmilea@gmail.com"},"_id":"custom-logger@0.2.0","devDependencies":{},"optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.1","_nodeVersion":"v0.6.11","_defaultsLoaded":true,"dist":{"shasum":"b14e5d7c9876f652eeea687a9c9e35dd42883310","size":9262,"noattachment":false,"key":"/custom-logger/-/custom-logger-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/custom-logger/download/custom-logger-0.2.0.tgz"},"maintainers":[{"name":"felixmc","email":"felixmilea@gmail.com"}],"directories":{},"publish_time":1337665027445,"_cnpm_publish_time":1337665027445,"_hasShrinkwrap":false},"0.1.0":{"name":"custom-logger","description":"Highly customizable console logger for node.js. Supports templating of logged output, custom levels, custom log types, colored output, and custom date formatting. Really simple to set up and use.","version":"0.1.0","author":{"name":"Felix Milea-Ciobanu","email":"felixmilea@gmail.com","url":"http://felixmc.com/"},"repository":{"type":"git","url":"git://github.com/felixmc/custom-logger.git"},"main":"logger","engines":{"node":">=0.1.90"},"dependencies":{"colors":"0.6.0-1","dateformat":"1.0.2-1.2.3"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/MIT"}],"keywords":["log","logger","logging","color","colour","timestamp","custom","console","warning","error","debug","template"],"_npmUser":{"name":"felixmc","email":"felixmilea@gmail.com"},"_id":"custom-logger@0.1.0","devDependencies":{},"optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.1","_nodeVersion":"v0.6.11","_defaultsLoaded":true,"dist":{"shasum":"f96a94390da24840a5b65d50d522b048f8c1f2bf","size":1526,"noattachment":false,"key":"/custom-logger/-/custom-logger-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/custom-logger/download/custom-logger-0.1.0.tgz"},"maintainers":[{"name":"felixmc","email":"felixmilea@gmail.com"}],"directories":{},"publish_time":1337636455298,"_cnpm_publish_time":1337636455298,"_hasShrinkwrap":false}},"readme":"# custom-logger [![npm version](https://badge.fury.io/js/custom-logger.svg)](http://badge.fury.io/js/custom-logger)\r\n\r\n`custom-logger` is a simple, highly customizable logging plugin for node.js.\r\n\r\nTo install this module simply run:\r\n\r\n```bash\r\nnpm install custom-logger\r\n```\r\n\r\nI'm still very much still learning node.js, and this is my first \"official\" module. If you notice any unusual or depracated coding behaviors be sure to let me know, like I said, I'm still learning! (:\r\n\r\nIf you have any questions or feedback, or need any help using this module, please contact <a href=\"http://twitter.com/#!/felix_mc\" target=\"_blank\">@felix_mc</a>.\r\n\r\n\r\n## Basic Usage\r\n\r\n```javascript\r\nvar log = require('custom-logger').config({ level: 0 });\r\n\r\nlog.debug( 'hello?' );\r\n\r\nlog.info( 'hello world!' );\r\n\r\nlog.warn( 'carefule there, world!' );\r\n\r\nlog.error( 'WHOA WHOA WHOA world?!' );\r\n\r\nlog.config({\r\n\tmessageFormatting: true\r\n});\r\n\r\nlog.info(\"I see %d %s!\", 3, \"bananas\");\r\n```\r\n\r\nThe above code will render to:\r\n\r\n![basic output snapshot](snapshots/basic.png)\r\n\r\n`custom-logger` uses logging levels and different event types to determine what is being outputed at any given time. Below are the default events and their respective logging levels:\r\n\r\n\t0 => debug\r\n\t1 => info\r\n\t2 => warn\r\n\t3 => error\r\n\r\nAs you can see above, you can use the level parameter in the config method to set the current logging level. You can call on the config method on the log object at any time throughout your code to change the log level or other options.\r\n\r\n`custom-log` will only show events whose level is **equal to or higher** than the one set. For example a level of `0` will show all event types, whereas a level of `2` will only show the event types `warning` and `error`. By default the logging level is `0`.\r\n\r\nYou can pass any number of parameters to logging methods (like log.info() or log.error), regardless of whether they are a default method or one that you created (see below). custom-logger will join all parameters together in one string, converting JSON and other non-string parameters to strings automatically.\r\n\r\n## Customizing Events Types\r\n\r\nOne cool thing you can do with `custom-logger` is you easily create your own additional event types:\r\n\r\n```javascript\r\nlog.new({\r\n\tfatal: { level: 5, event: \"fatal\", color: \"rainbow\" }\r\n});\r\n\r\nlog.fatal( \"program is dead\" ); //outputs \"fatal:  program is dead\"\r\n```\r\n\r\nIn the parameters passed to the `new` method, the key (`debugger`) is the method to be added to the module, where as the `event` property is what is going to be displayed in the log as the event type. Don't the get two confused!\r\n\r\nYou can also overwrite the default events (`info`, `warn`, `error`) with your own if you'd like to:\r\n\r\n```javascript\r\nlog.new({\r\n\tinfo: { color: 'cyan', level: 0, event: 'info' },\r\n\tnotice: { color: 'yellow', level: 1, event: 'notice' },\r\n\twarn: { color: 'yellow', level: 2, event: 'warning' },\r\n\terror: { color: 'red', level: 3, event: 'ERROR' }\r\n});\r\n```\r\n\r\nHowever, if all you you want to do is change some of the properties, you can also do the following:\r\n\r\n```javascript\r\nlog.info().config({ color: 'cyan' });\r\n\r\nlog.info('Hello World!'); //output should be cyan now\r\n```\r\n\r\nMake sure not to pass anything to the `info` method when you are configuring it, otherwise you'll probably get an error. This is the only *ugly* part of the syntax (hopefully!), I will probably fix it at a later time.\r\n\r\n## Log Formatting\r\n\r\n### Template\r\n\r\nUsing `custom-logger` you can also configure how the console output will look like. It uses some simple templating patterns to do so:\r\n\r\n\t%event%     => the type of event being logged, such as \"info\" or \"warning\"\r\n\t%message%   => the message to be displayed, such as \"server started!\"\r\n\t%timestamp% => customizable datetime (see below) for when the event occured\r\n\t%padding%   => space characters that help align the current %event%. See details sections below for more\r\n\r\nBy default the format string is:\r\n\r\n\t%timestamp% - %event%:%padding%  %message%\r\n\r\nWhich produces the output:\r\n\r\n\t01:08:24 - debug:     hello?\r\n\t01:08:24 - info:      hello world!\r\n\t01:08:24 - warning:   carefule there, world!\r\n\t01:08:24 - error:     WHOA WHOA WHOA world?!\r\n\r\nYou can specify the output format like so:\r\n\r\n```javascript\r\nvar log = require('custom-logger').config({ format: \"%event% %padding%[%timestamp%]: %message%\" });\r\n```\r\n\r\nWhich would output to:\r\n\r\n\tdebug   [01:06:26]:  hello?\r\n\tinfo    [01:06:26]:  hello world!\r\n\twarning [01:06:26]:  carefule there, world!\r\n\terror   [01:06:26]:  WHOA WHOA WHOA world?!\r\n\r\nIf you were to remove `%padding%` from the format string, the output would be:\r\n\r\n\tdebug [01:10:12]:  hello?\r\n\tinfo [01:10:12]:  hello world!\r\n\twarning [01:10:12]:  carefule there, world!\r\n\terror [01:10:12]:  WHOA WHOA WHOA world?!\r\n\r\nI hope this helps illustrate the purpose of `%padding%`.\r\n\r\n### Timestamp\r\n\r\nYou can also modify the format of the actual `%timestamp%`. By default it's `HH:MM:ss`. You can change it as follows:\r\n\r\n```javascript\r\nvar log = require('custom-logger').config({ timestamp: \"h:MM:ss TT\" });\r\n```\r\n\r\nWhich should look familiar to those familiar with date formatting in other programming languages. For more information on formatting the timestamp, see <a href=\"http://blog.stevenlevithan.com/archives/date-time-format\" target=\"_blank\">this</a>. Since this modules relies on the `dateFormat` library, any values valid for `dateFormat` should be valid here too.\r\n\r\n## Overwriting Global Config\r\n\r\nYou can also overwrite global settings for log template and timestamp format based on individual event types, either when you create them or by modifying existing ones:\r\n\r\n```javascript\r\nlog.new({\r\n\talert: { level: 3, color: 'red', event: 'alert', format: '!!!!!%event% : %message% !!!!!' }\r\n});\r\n\r\nlog.error().config({ timestamp: \"HH:MM:ss\" });\r\n```\r\n\r\n## Further Details\r\n\r\n### Colors\r\n\r\nIf you'd like to further customize colors or formatting of your events, take a look at the <a href=\"https://github.com/Marak/colors.js\" target=\"_blank\">colors</a> modules that this module depends on. Any color/formatting value that's valid for that module, should be fine to pass to the `color` parameter when creating/configuring an event type.\r\n\r\n### Padding\r\n\r\nSay you have three event types with the `event` properties as follows: `info`, `warning`, `error`.\r\n\r\nThe `%padding%` value is going to be different for each of the events when they are displayed. The way it's calculated is that it finds the string length of the longest event, and subtracts it from the string length of the current event, and then returns a string containg that many spaces.\r\n\r\nFor examples, the longest string of the above events is `warning`, with 7 characters. Here's how it's being worked out:\r\n\r\n\tinfo.length = 4     ===>  7 - 4 = 3  ===> \"   \"\r\n\twarning.length = 7  ===>  7 - 7 = 0  ===> \"\"\r\n\terror.length = 5    ===>  7 - 5 = 2  ===> \"  \"\r\n\r\nIf this confuses you, don't worry much about it, you don't have to use it. I simply included it to make outputing to the console prettier.\r\n\r\n### Message Formatting\r\n\r\nMessages can be formatted using `util.format` by setting the config option `messageFormatting` to `true`. This defaults to `false` to ensure backward compatibility with versions prior to 0.3.1.\r\n\r\nFor example:\r\n\r\n```javascript\r\nlog.info(\"I see\", \"3\", \"bananas!\") // Outputs \"I see 3 bananas!\"\r\n\r\nlog.config({\r\n\tmessageFormatting: true\r\n});\r\n\r\nlog.info(\"I see %d %s!\", 3, \"bananas\"); // Outputs \"I see 3 bananas!\"\r\n```\r\n","_attachments":{},"homepage":"https://github.com/felixmc/custom-logger","bugs":{"url":"https://github.com/felixmc/custom-logger/issues"}}