Skip to content

Commit

Permalink
Correct documentation and add tstamp function test
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners committed Apr 29, 2017
1 parent c0b1670 commit 7455cd9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
13 changes: 7 additions & 6 deletions docs/API.md
Expand Up @@ -44,10 +44,11 @@
property name is logged objects.
* `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
representation of the time, e.g. `"time":1493426328206 (which is the default).
representation of the time, e.g. `,"time":1493426328206 (which is the default).
If set to `false`, no timestamp will be included in the output.
See [stdTimeFunctions](#stdTimeFunctions) for more information.
Caution: any sort of formatted time will significantly slow down Pino's performance.
See [stdTimeFunctions](#stdTimeFunctions) for a set of available functions
for passing in as a value for this option. Caution: any sort of formatted
time will significantly slow down Pino's performance.
* `extreme` (boolean): Enables extreme mode, yields an additional 60% performance
(from 250ms down to 100ms per 10000 ops). There are trade-off's should be
understood before usage. See [Extreme mode explained](extreme.md). Default: `false`.
Expand Down Expand Up @@ -549,17 +550,17 @@ format. Alternatively, you can specify your own time function.

A time function must synchronously return a string that would be a valid
component of a JSON string. For example, the default function returns
a string like `"time":1493426328206`.
a string like `,"time":1493426328206`.

<a id="epochTimeFunction"></a>
### .epochTime

The default time function for Pino. Returns a string like `"time":1493426328206`.
The default time function for Pino. Returns a string like `,"time":1493426328206`.

<a id="slowTimeFunction"></a>
### .slowTime

Returns an ISO formatted string like `"time":"2017-04-29T00:47:49.354Z". It is
Returns an ISO formatted string like `,"time":"2017-04-29T00:47:49.354Z". It is
highly recommended that you avoid this function. It incurs a significant
performance penalty.

Expand Down
14 changes: 14 additions & 0 deletions test/timestamp.test.js
Expand Up @@ -12,6 +12,20 @@ test('pino exposes standard time functions', function (t) {
t.ok(pino.stdTimeFunctions.nullTime)
})

test('pino accepts external time functions', function (t) {
t.plan(2)
var opts = {
timestamp: function () {
return ',"time":"none"'
}
}
var instance = pino(opts, sink(function (chunk, enc, cb) {
t.equal(chunk.hasOwnProperty('time'), true)
t.equal(chunk.time, 'none')
}))
instance.info('foobar')
})

test('inserts timestamp by default', function (t) {
var instance = pino(sink(function (chunk, enc, cb) {
t.equal(chunk.hasOwnProperty('time'), true)
Expand Down

0 comments on commit 7455cd9

Please sign in to comment.