garnish
Prettifies ndjson or bole logs from budo, wzrd and other tools.
Example with budo, which uses this under the hood.
![](http://i.imgur.com/Pvus8vy.png)
Install
npm install garnish [-g|--save-dev]
Usage
CLI
Pipe a ndjson emitter into garnish
like so:
node app.js | garnish [opts] Options: --level, -l the minimum debug level, default 'debug' --name, -n the default app name
Where level
can be debug
, info
, warn
, error
.
API
garnish([opt])
Returns a duplexer that parses input as ndjson, and writes a pretty-printed result. Options:
level
(String)- the minimum log level to print (default
'debug'
) - the order is as follows:
debug
,info
,warn
,error
- the minimum log level to print (default
name
(String)- the default name for your logger; a message's
name
field will not be printed when it matches this default name, to reduce redundant/obvious information in the logs.
- the default name for your logger; a message's
format
Typically, you would use bole or ndjson to write the content to garnish. You can also write ndjson to stdout
like so:
// a log messageconsole // a typical server messageconsole
Currently garnish styles the following:
level
- the log level e.g.
debug
,info
,warn
,error
(defaultdebug
) - only shown ifmessage
is present
- the log level e.g.
name
- an optional event or application name. It's recommended to always have a name.
message
- an event message.
url
- a url (stripped to pathname), useful for router logging.
statusCode
- an HTTP statusCode. Codes
>=400
are displayed in red.
- an HTTP statusCode. Codes
contentLength
- the response size; if a
number
, bytes are assumed
- the response size; if a
elapsed
- time elapsed since the previous related event; if a
number
, milliseconds are assumed
- time elapsed since the previous related event; if a
type
- the type of event logged
colors
- an optional color mapping for custom styles
You can use the colors
field to override any of the default colors with a new ANSI style.
For example, the following will print elapsed
in yellow if it passes our threshold:
{ var now = Date var time = now - lastTime lastTime = now console}
See Also
License
MIT, see LICENSE.md for details.