Skip to content

Commit

Permalink
Added more information to README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mpalmerlee committed May 5, 2013
1 parent 15f4265 commit e44dc5d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
-------
Expand Down

0 comments on commit e44dc5d

Please sign in to comment.