# garnish

> prettifies ndjson from wzrd and similar tools

Latest version **5.2.0** (published 2016-04-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install garnish
pnpm add garnish
yarn add garnish
bun add garnish
```

Provides the command `garnish`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.2.0 |
| Published | 2016-04-07 |
| First published | 2015-02-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 84 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl, yoshuawuyts |
| Keywords | prettify, pretty, print, pretty-print, ndjson, bundle, bundler, browserify, wzrd, beefy, wizz |

## Links

- npm: https://www.npmjs.com/package/garnish
- Repository: https://github.com/mattdesl/garnish
- Issues: https://github.com/mattdesl/garnish/issues
- npm.io page: https://npm.io/package/garnish

## Dependencies (10)

- [chalk](https://npm.io/package/chalk.md) ^0.5.1
- [split2](https://npm.io/package/split2.md) ^0.2.1
- [minimist](https://npm.io/package/minimist.md) ^1.1.0
- [pad-left](https://npm.io/package/pad-left.md) ^2.0.0
- [url-trim](https://npm.io/package/url-trim.md) ^1.0.0
- [pad-right](https://npm.io/package/pad-right.md) ^0.2.2
- [pretty-ms](https://npm.io/package/pretty-ms.md) ^2.1.0
- [right-now](https://npm.io/package/right-now.md) ^1.0.0
- [stdout-stream](https://npm.io/package/stdout-stream.md) ^1.4.0
- [prettier-bytes](https://npm.io/package/prettier-bytes.md) ^1.0.3

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 5.2.0 (latest) — 2016-04-07
- 5.1.1 — 2016-03-29
- 5.1.0 — 2016-03-22
- 5.0.2 — 2016-03-09
- 5.0.1 — 2015-12-13
- 5.0.0 — 2015-12-02
- 4.1.1 — 2015-11-02
- 4.1.0 — 2015-11-02
- 4.0.0 — 2015-10-29
- 3.2.2 — 2015-10-29
- 3.2.1 — 2015-09-24
- 3.2.0 — 2015-09-10
- 3.1.0 — 2015-09-10
- 3.0.0 — 2015-09-06
- 2.3.0 — 2015-08-19
- … 15 more at https://npm.io/package/garnish/versions

## README

# garnish

[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

Prettifies [ndjson](http://ndjson.org/) or [bole](https://github.com/rvagg/bole) logs from [budo](https://github.com/mattdesl/budo), [wzrd](https://github.com/maxogden/wzrd/) and other tools. 

Example with [budo](https://github.com/mattdesl/budo), which uses this under the hood.

<img src="http://i.imgur.com/Pvus8vy.png" width="75%" />

## Install

```sh
npm install garnish [-g|--save-dev]
```

## Usage

### CLI

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`.

### 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`
- `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.

## format

Typically, you would use [bole](https://github.com/rvagg/bole) or [ndjson](https://www.npmjs.com/package/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:

- `level`
  - the log level e.g. `debug`, `info`, `warn`, `error` (default `debug`) - only shown if `message` is present
- `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.
- `contentLength`
  - the response size; if a `number`, bytes are assumed
- `elapsed`
  - time elapsed since the previous related event; if a `number`, milliseconds are assumed
- `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](https://github.com/chalk/ansi-styles).

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'
    }
  })
}
```

## See Also

- [bistre](https://github.com/hughsk/bistre)

## License

MIT, see [LICENSE.md](http://github.com/mattdesl/garnish/blob/master/LICENSE.md) for details.

---
_Source: https://npm.io/package/garnish · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
