visionmedia/jog — pull request #16 by cpsubrian (2012-10-25 22:28:18+00:00)
Title: Formatters

Introduces the concept of 'formatters' and ALL CLI output runs through a formatter.

A formatter is merely a commonjs module that exports an object. The object should follow the following signature:

```js
module.exports = {
// Required. Outputs lines.
output: function(lines) {
// console.log, or write to a file, or whatever.
},

// Optional. Map function.
map: function(obj) {
return obj.type;
},

// Optional. Select function.
select: function(obj) {
return obj.level === 'error';
},

// Optional. Reduce function.
reduce: function(lines) {
// return reduced lines.
}
};
```

Formatters can live in three possible locations:

- `lib/formatters`
- `$HOME/.jog/formatters`
- `$CWD/.jog/formatters`

This allows someone to maintain formatters that they like to use on either a per-machine, or per-project basis. Awesome! Also, the formatters are loaded in that order, so project formatters can override machine ones, or core ones.

Four core formatters are included:

- json
- color
- short
- default

You use the formatters via the `--output` command-line option.

```
jog -F /tmp/logs.log -f --output short

jog -F /tmp/logs.log -f -o short
```

`-j --json` is aliased to `--output json`

`-c --color` is aliased to `--output color`

I think this is a really flexible approach. For example you could create a formatter that saves images, or a formatter that renders a CLI bar chart, or whatever.