Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "custom" output for CLI #191

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Add "custom" output for CLI #191

wants to merge 4 commits into from

Conversation

Neamar
Copy link

@Neamar Neamar commented Nov 20, 2014

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:

{{ _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

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

dotlouis added a commit to dotlouis/soon that referenced this pull request Mar 6, 2016
Log properties are important to filter logs later, if you want to clean
up the CLI, look at trentm/node-bunyan#191
@nblasgen
Copy link

If I were to update this pull request, would it be accepted? I'm in need of any other kind of console display than the default options, and I prefer this implementation (though via a config file rather than a very long string) than writing multiple static output modes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants