prettifies ndjson from wzrd and similar tools
npm install garnish
Prettifies ndjson or bole logs from budo, wzrd and other tools.
Example with budo, which uses this under the hood.

``sh`
npm install garnish [-g|--save-dev]
Pipe a ndjson emitter into garnish like so:
`sh
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.
#### garnish([opt])
Returns a duplexer that parses input as ndjson, and writes a pretty-printed result. Options:
- level (String)'debug'
- the minimum log level to print (default )debug
- the order is as follows: , info, warn, errorname
- (String)name
- the default name for your logger; a message's field will not be printed when it matches this default name, to reduce redundant/obvious information in the logs.
Typically, you would use bole or ndjson to write the content to garnish. You can also write ndjson to stdout like so:
`js
// a log message
console.log({
name: 'myApp',
level: 'warn',
message: 'not found'
})
// a typical server message
console.log({
name: 'myApp',
type: 'generated',
level: 'info',
url: '/foo.png',
statusCode: 200,
contentLength: 12800, // in bytes
elapsed: 120 // in milliseconds
})
`
Currently garnish styles the following:
- leveldebug
- the log level e.g. , info, warn, error (default debug) - only shown if message is presentname
- message
- an optional event or application name. It's recommended to always have a name.
- url
- an event message.
- statusCode
- a url (stripped to pathname), useful for router logging.
- >=400
- an HTTP statusCode. Codes are displayed in red.contentLength
- number
- the response size; if a , bytes are assumedelapsed
- number
- time elapsed since the previous related event; if a , milliseconds are assumedtype
- colors
- the type of event logged
-
- 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:
`js
function logTime (msg) {
var now = Date.now()
var time = now - lastTime
lastTime = now
console.log({
name: 'app',
message: msg,
elapsed: time + ' ms',
colors: {
elapsed: time > 1000 ? 'yellow' : 'green'
}
})
}
``
- bistre
MIT, see LICENSE.md for details.