From e44dc5d38638e726018639c1c8516836f04d105a Mon Sep 17 00:00:00 2001 From: Matt Palmerlee Date: Sun, 5 May 2013 10:47:11 -0700 Subject: [PATCH] Added more information to README.md --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index 6d8f033..27aa5ff 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,28 @@ LEVELS = { }; ``` +Overridden Console Functions +---------------------------- +The above log levels correspond to the following console functions: +```javascript +console.error +console.warn +console.log +console.info +console.debug +``` + +Unit testing and console.debug +------------------------------ +Since console.debug is not a standard NodeJS function, you may run into problems in situations (such as in unit testing) where you do not want to initialize the Console-TEN module, yet your code may call console.debug. To work around this, simply create a dummy console.debug function in a file such as console_init.js: +```javascript +console.debug = function(){}; +``` +Unit testing frameworks such as Mocha allow you to "--require" additional scripts when executing from the command line: +```bash +mocha -r "console_init" unit_test_file.js +``` + Custom log format ----------------- You can easily override or customize the format and the information appended to the console.log functions by passing a format function to the init method: @@ -64,6 +86,14 @@ After applying this new format function our output looks more like this: > [Sat Mar 30 2013 15:54:08 GMT-0700 (PDT)] [error] Hello Node! { i: 'love', json: '!' } ``` +Modify Express logs to match Console-TEN +---------------------------------------- +If you use the Express web application framework, you'll want to modify the default log format for Express to match the format in Console-TEN so that your log files are readily parsable, this can easily be done with the following code: + +```javascript +express.logger.token('zdate', function() { return new Date().toISOString(); }); +app.use(express.logger('[:zdate] [WEBLOG] :remote-addr - - ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"')); +``` License -------