xnpmlog
v2.0.0
Published
Extend npmlog and allow child loggers
Downloads
6
Readme
xnpmlog
npmlog with the ability to create child loggers
xnpmlog only works on iojs and node v4+. To use xnpmlog with node 0.10 or 0.12,
install xnpmlog@1
.
Author
Evan Lucas
License
MIT
Installation
$ npm install --save xnpmlog
Tests
$ npm test
Coverage
$ npm run cover
API
Logger
Constructor
opts can contain:
| Name | Type | Description | | ---- | ---- | ----------- | | loglevel | String | Set the log level (info) | | prefixStyle | Object | Set prefix style ({ fg: 'magenta' }) | | headingStyle | Object | Set heading style ({ fg: 'white', bg: 'black' }) | | stream | Stream | The stream (process.stderr) | | timestamp | Boolean | Include timestamp in logs (true) | | heading | String | The log heading ('') |
Params
| Name | Type(s) | Description | | ---- | ------- | ----------- | | component | String | The component | | opts | Object | The opts |
Logger.createLogger()
Creates a logger
Example
var Logger = require('xnpmlog')
var log = Logger.createLogger('test')
Params
| Name | Type(s) | Description | | ---- | ------- | ----------- | | comp | String | The component | | opts | Object | The opts |
Logger.child()
Creates a child logger
Example
var logger = require('xnpmlog')('app')
var log = logger.child('users-controller')
Params
| Name | Type(s) | Description | | ---- | ------- | ----------- | | comp | String | The component | | opts | Object | The opts |
Logger.pause()
Pauses the log stream
Logger.resume()
Resumes the log stream
Logger.rmLevel()
Removes the given log level
Params
| Name | Type(s) | Description | | ---- | ------- | ----------- | | level | String | The log level to remove |
Logger.addLevel()
Adds a new log level
Params
| Name | Type(s) | Description | | ---- | ------- | ----------- | | level | String | The log level | | n | Number | The numeric level | | style | Object | The ansi style object | | disp | String | Optional replacement for level in the output |