From b556376cbe882b62fab6225f12f61b00c410814c Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 21 Aug 2013 11:50:10 -0400 Subject: [PATCH] Readme.md: Edited for formatting, grammar, phrasing, and clarity --- Readme.md | 122 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 70 insertions(+), 52 deletions(-) diff --git a/Readme.md b/Readme.md index ce07ed2..1d34c8b 100644 --- a/Readme.md +++ b/Readme.md @@ -1,78 +1,96 @@ - # Log.js - Light-weight logging for [NodeJS](http://nodejs.org), including a - streaming log reader. +Lightweight logging for [NodeJS](http://nodejs.org). Includes a streaming log reader. + ## Installation - $ npm install log +```bash +$ npm install log +``` + ## Example -Log level defaults to __DEBUG__ however here we specify __info__, and the stream defaults to _stdout_: +By default, a Log’s stream is `stdout`, and its log level defaults is `DEBUG`. - var Log = require('log') - , log = new Log('info'); +Instead of `DEBUG`, let’s create a log with the `info` level: - log.debug('preparing email'); - log.info('sending email'); - log.error('failed to send email'); +```javascript +var Log = require('log') + , log = new Log('info'); -Specifying a specific stream: +log.debug('preparing email'); +log.info('sending email'); +log.error('failed to send email'); +``` - var fs = require('fs') - , Log = require('log') - , log = new Log('debug', fs.createWriteStream('my.log')); +Specifying a specific stream: -Instead of the log level constants, you may also supply a string: +```javascript +var fs = require('fs') + , Log = require('log') + , log = new Log('debug', fs.createWriteStream('my.log')); +``` - var Log = require('log') - , log = new Log('warning'); +Instead of the log level constants, you can just supply a string: - We can also use `%s` much like `console.log()` to pass arguments: +```javascript +var Log = require('log') + , log = new Log('warning'); +``` + +You can use `%s` to pass arguments (much like `console.log()`): - log.error('oh no, failed to send mail to %s.', user.email); +```javascript +log.error('oh no, failed to send mail to %s.', user.email); +``` -## Reader - To stream a log, simply pass a readable stream instead of a writable: - - var Log = require('log') - , fs = require('fs') - , stream = fs.createReadStream(__dirname + '/file.log') - , log = new Log('debug', stream); - - log.on('line', function(line){ - console.log(line); - }); - - __Note: log.js assumes utf8 encoded data.__ -Example stdout: - - { date: Sun, 26 Sep 2010 01:26:14 GMT - , level: 1 - , levelString: 'ALERT' - , msg: 'a alert message' - } - { date: Sun, 26 Sep 2010 01:26:14 GMT - , level: 0 - , levelString: 'EMERGENCY' - , msg: 'a emergency message' - } +## Reader +To stream a log, simply pass a readable stream instead of a writable: + +```javascript +var Log = require('log') + , fs = require('fs') + , stream = fs.createReadStream(__dirname + '/file.log') + , log = new Log('debug', stream); + +log.on('line', function(line){ + console.log(line); +}); +``` + +(**Note:** `log.js` assumes utf8 encoded data.) + +Example output: + +```javascript +{ date: Sun, 26 Sep 2010 01:26:14 GMT +, level: 1 +, levelString: 'ALERT' +, msg: 'a alert message' +} +{ date: Sun, 26 Sep 2010 01:26:14 GMT +, level: 0 +, levelString: 'EMERGENCY' +, msg: 'a emergency message' +} +``` + ## Log Levels Mirror that of syslog: - - 0 __EMERGENCY__ system is unusable - - 1 __ALERT__ action must be taken immediately - - 2 __CRITICAL__ the system is in critical condition - - 3 __ERROR__ error condition - - 4 __WARNING__ warning condition - - 5 __NOTICE__ a normal but significant condition - - 6 __INFO__ a purely informational message - - 7 __DEBUG__ messages to debug an application + - `0` `EMERGENCY` system unusable + - `1` `ALERT` immediate action required + - `2` `CRITICAL` condition critical + - `3` `ERROR` condition error + - `4` `WARNING` condition warning + - `5` `NOTICE` condition normal, but significant + - `6` `INFO` a purely informational message + - `7` `DEBUG` debugging information ## License