Skip to content

Commit

Permalink
Remove CLI and add robust prettifier support
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners committed Apr 5, 2018
1 parent 0703597 commit d7d52a1
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 1,191 deletions.
49 changes: 23 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
# pino  [![Build Status](https://travis-ci.org/pinojs/pino.svg?branch=master)](https://travis-ci.org/pinojs/pino) [![Coverage Status](https://coveralls.io/repos/github/pinojs/pino/badge.svg?branch=master)](https://coveralls.io/github/pinojs/pino?branch=master) [![TypeScript definitions on DefinitelyTyped](http://definitelytyped.org/badges/standard.svg)](http://definitelytyped.org)

[Extremely fast](#benchmarks) node.js logger, inspired by Bunyan.
It also includes a shell utility to pretty-print its log files.

![cli](demo.png)

* [Installation](#install)
* [Usage](#usage)
* [Benchmarks](#benchmarks)
* [API ⇗](docs/API.md)
* [CLI ](docs/cli.md)
* [Pretty Printing ](docs/pretty.md)
* [Extreme mode explained ⇗](docs/extreme.md)
* [Pino Howtos ⇗](docs/howtos.md)
* [Transports with Pino](#transports)
Expand Down Expand Up @@ -194,7 +191,7 @@ By default, in the browser,
### Browser Options

Pino can be passed a `browser` object in the options object,
which can have the following properties:
which can have the following properties:

#### `asObject` (Boolean)

Expand Down Expand Up @@ -246,10 +243,10 @@ var pino = require('pino')({browser: {write: {

The serializers provided to `pino` are ignored by default in the browser, including
the standard serializers provided with Pino. Since the default destination for log
messages is the console, values such as `Error` objects are enhanced for inspection,
messages is the console, values such as `Error` objects are enhanced for inspection,
which they otherwise wouldn't be if the Error serializer was enabled.

We can turn all serializers on,
We can turn all serializers on,

```js
var pino = require('pino')({
Expand All @@ -273,7 +270,7 @@ var pino = require('pino')({
})
// following will apply myCustomSerializer to the custom property,
// but will not apply anotherSerizlier to another key
pino.info({custom: 'a', another: 'b'})
pino.info({custom: 'a', another: 'b'})
```

When `serialize` is `true` the standard error serializer is also enabled (see https://github.com/pinojs/pino/blob/master/docs/API.md#stdSerializers).
Expand All @@ -299,7 +296,7 @@ for how to set child-bound serializers).

Unlike server pino the serializers apply to every object passed to the logger method,
if the `asObject` option is `true`, this results in the serializers applying to the
first object (as in server pino).
first object (as in server pino).

For more info on serializers see https://github.com/pinojs/pino/blob/master/docs/API.md#parameters.

Expand All @@ -309,23 +306,23 @@ An object with `send` and `level` properties.

The `transmit.level` property specifies the minimum level (inclusive) of when the `send` function
should be called, if not supplied the `send` function be called based on the main logging `level`
(set via `options.level`, defaulting to `info`).
(set via `options.level`, defaulting to `info`).

The `transmit` object must have a `send` function which will be called after
writing the log message. The `send` function is passed the level of the log
message and a `logEvent` object.
The `transmit` object must have a `send` function which will be called after
writing the log message. The `send` function is passed the level of the log
message and a `logEvent` object.

The `logEvent` object is a data structure representing a log message, it represents
the arguments passed to a logger statement, the level
at which they were logged and the heirarchy of child bindings.
the arguments passed to a logger statement, the level
at which they were logged and the heirarchy of child bindings.

The `logEvent` format is structured like so:
The `logEvent` format is structured like so:

```js
{
{
ts = Number,
messages = Array,
bindings = Array,
messages = Array,
bindings = Array,
level: { label = String, value = Number}
}
```
Expand All @@ -336,21 +333,21 @@ logger method is called.
The `messages` array is all arguments passed to logger method, (for instance `logger.info('a', 'b', 'c')`
would result in `messages` array `['a', 'b', 'c']`).

The `bindings` array represents each child logger (if any), and the relevant bindings.
For instance given `logger.child({a: 1}).child({b: 2}).info({c: 3})`, the bindings array
The `bindings` array represents each child logger (if any), and the relevant bindings.
For instance given `logger.child({a: 1}).child({b: 2}).info({c: 3})`, the bindings array
would hold `[{a: 1}, {b: 2}]` and the `messages` array would be `[{c: 3}]`. The `bindings`
are ordered according to their position in the child logger heirarchy, with the lowest index
being the top of the heirarchy.

By default serializers are not applied to log output in the browser, but they will *always* be
applied to `messages` and `bindings` in the `logEvent` object. This allows us to ensure a consistent
applied to `messages` and `bindings` in the `logEvent` object. This allows us to ensure a consistent
format for all values between server and client.

The `level` holds the label (for instance `info`), and the corresponding numerical value
(for instance `30`). This could be important in cases where client side level values and
The `level` holds the label (for instance `info`), and the corresponding numerical value
(for instance `30`). This could be important in cases where client side level values and
labels differ from server side.

The point of the `send` function is to remotely record log messages:
The point of the `send` function is to remotely record log messages:

```js
var pino = require('pino')({
Expand All @@ -366,7 +363,7 @@ var pino = require('pino')({
// numerical value
if (logEvent.level.value >= 50) { // covers error and fatal

// send the logEvent somewhere
// send the logEvent somewhere
}
}
}
Expand Down
59 changes: 0 additions & 59 deletions bin.js

This file was deleted.

Binary file removed demo.png
Binary file not shown.
55 changes: 8 additions & 47 deletions docs/API.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Table of Contents

+ [pino](#constructor)
+ [pino.pretty](#pretty)
+ [Logger Instance](#logger)
* [.pino](#version)
* [.child](#child)
Expand Down Expand Up @@ -47,7 +46,7 @@
of objects. These functions should return an JSONifiable object and they
should never throw. When logging an object, each top-level property matching the exact key of a serializer
will be serialized using the defined serializer.

Alternatively, it is possible to register a serializer under the key `Symbol.for('pino.*')` which will act upon the complete log object, i.e. every property.
* `timestamp` (boolean|function): Enables or disables the inclusion of a timestamp in the
log message. If a function is supplied, it must synchronously return a JSON string
Expand All @@ -73,8 +72,13 @@
* `levelVal` (integer): when defining a custom log level via `level`, set to an
integer value to define the new level. Default: `undefined`.
* `messageKey` (string): the string key for the 'message' in the JSON object. Default `msg`.
* `prettyPrint` (boolean|object): enables [pino.pretty](#pretty). This is intended for non-production
configurations. This may be set to a configuration object as outlined in [pino.pretty](#pretty). Default: `false`.
* `prettyPrint` (boolean|object): enables pretty printing log logs. This is intended for non-production
configurations. This may be set to a configuration object as outlined in the
[`pino-pretty` documentation](https://github.com/pinojs/pino-pretty).
The options object may additionally contain a `prettifier` property to define
which prettifier module to use. When not present, `prettifier` defaults to
`'pino-pretty'`. Regardless of the value, the specified prettifier module
must be installed as a separate dependency. Default: `false`.
* `onTerminated` (function): this function will be invoked during process shutdown when `extreme` is set to `true`.
The signature of the function is `onTerminated(eventName, err)`. If you do not specify a function, Pino will
invoke `process.exit(0)` when no error has occurred, and `process.exit(1)` otherwise. If you do specify a function,
Expand Down Expand Up @@ -108,49 +112,6 @@ var logger = pino({
### Discussion:
Returns a new [logger](#logger) instance.

<a id="pretty"></a>
## .pretty([options])

### Parameters:
+ `options` (object):
* `timeTransOnly` (boolean): if set to `true`, it will only covert the unix
timestamp to ISO 8601 date format, and reserialize the JSON (equivalent to `pino -t`).
* `formatter` (function): a custom function to format the line. It's passed 2 arguments,
JSON object log data and an options object
that [exposes utility functions](https://github.com/pinojs/pino/blob/master/pretty.js#L110).
It should return a string value.
* `levelFirst` (boolean): if set to `true`, it will print the name of the log
level as the first field in the log line. Default: `false`.
* `messageKey` (string): the key in the JSON object to use as the highlighted
message. Default: `msg`.
* `forceColor` (boolean): if set to `true`, will add color information to the formatted output
message. Default: `false`.
* `crlf` (boolean): emit `\r\n` instead of `\n`. Default: `false`.
* `errorLikeObjectKeys` (array): error-like objects containing stack traces that should be prettified. Default: `['err', 'error']`.

### Example:
```js
'use strict'

var pino = require('pino')
var pretty = pino.pretty()
pretty.pipe(process.stdout)
var log = pino({
name: 'app',
safe: true
}, pretty)

log.child({ widget: 'foo' }).info('hello')
log.child({ widget: 'bar' }).warn('hello 2')
```

### Discussion:
Provides access to the [CLI](cli.md) log prettifier as an API.

This can also be enabled via the [constructor](#constructor) by setting the
`prettyPrint` option to either `true` or a configuration object described
in this section.

<a id="logger"></a>
# Logger

Expand Down

0 comments on commit d7d52a1

Please sign in to comment.