trentm/node-bunyan — pull request #191 by Neamar (2014-11-20 18:07:28+00:00)
Title: Add "custom" output for CLI

Let the user choose its own templating scheme on the bunyan CLI.

Sample use:

```
... | bunyan -o custom --template "{{username}} {{error}}"
```

Arbitrary code can be injected:

```
... | bunyan -o custom --template "{{username}} {{error.toUpperCase()}}"
```

And colors are handled (not in the cleanest way) with _cS and _cE:
```
... | bunyan -o custom --template "{{ _cS('grey') }}{{ req.method }} {{ req.user || '???' }} {{ req.url }}{{ _cE('grey') }}"
```

(this use the default stylize function, and will revert to no-color on non ansi terminals)

Eventually, we can get to quite complex templates -- here is the one i'm using:

```html
{{ _cS('grey') }}{{ req.method }} {{ req.user || '???' }} {{ req.url }}{{ _cE('grey') }} {{ _cS(res.status > 500 ? 'red' : res.status > 400 ? 'yellow' : res.status > 300 ? 'cyan' : 'green')}}{{ res.status }}{{ _cE('green') }} {{ _cS(res.time > 800 ? 'bold': 'grey')}}{{ res.time }}ms{{ _cE(res.time > 800 ? 'bold': 'grey') }} {{ _cS('underline') }}{{ res.restCode }}{{ _cE('underline')}} {{ msg }}
```

For the following result:
![log](https://cloud.githubusercontent.com/assets/536844/5130118/46a4800a-70e8-11e4-8dd5-593f07044407.png)

Add an optional npm dependency (underscore) and use the built-in `_.template`.