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

Remove all mentions of final #1544

Merged
merged 1 commit into from Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 0 additions & 54 deletions docs/api.md
Expand Up @@ -24,7 +24,6 @@
* [Statics](#statics)
* [pino.destination()](#pino-destination)
* [pino.transport()](#pino-transport)
* [pino.final()](#pino-final)
* [pino.multistream()](#pino-multistream)
* [pino.stdSerializers](#pino-stdserializers)
* [pino.stdTimeFunctions](#pino-stdtimefunctions)
Expand Down Expand Up @@ -1150,59 +1149,6 @@ For more on transports, how they work, and how to create them see the [`Transpor
* `targets`: May be specified instead of `target`. Must be an array of transport configurations. Transport configurations include the aforementioned `options` and `target` options plus a `level` option which will send only logs above a specified level to a transport.
* `pipeline`: May be specified instead of `target`. Must be an array of transport configurations. Transport configurations include the aforementioned `options` and `target` options. All intermediate steps in the pipeline _must_ be `Transform` streams and not `Writable`.

<a id="pino-final"></a>

### `pino.final(logger, [handler]) => Function | FinalLogger`

__The use of `pino.final` is discouraged in Node.js v14+ and not required.
It will be removed in the next major version.__

The `pino.final` method can be used to acquire a final logger instance
or create an exit listener function. This is _not_ needed in Node.js v14+
as pino automatically can handle those.

The `finalLogger` is a specialist logger that synchronously flushes
on every write. This is important to guarantee final log writes,
when using `pino.destination({ sync: false })` target.

Since final log writes cannot be guaranteed with normal Node.js streams,
if the `destination` parameter of the `logger` supplied to `pino.final`
is a Node.js stream `pino.final` will throw.

The use of `pino.final` with `pino.destination` is not needed, as
`pino.destination` writes things synchronously.

#### `pino.final(logger, handler) => Function`

In this case the `pino.final` method supplies an exit listener function that can be
supplied to process exit events such as `exit`, `uncaughtException`,
`SIGHUP` and so on.

The exit listener function will call the supplied `handler` function
with an error object (or else `null`), a `finalLogger` instance followed
by any additional arguments the `handler` may be called with.

```js
process.on('uncaughtException', pino.final(logger, (err, finalLogger) => {
finalLogger.error(err, 'uncaughtException')
process.exit(1)
}))
```

#### `pino.final(logger) => FinalLogger`

In this case the `pino.final` method returns a finalLogger instance.

```js
var finalLogger = pino.final(logger)
finalLogger.info('exiting...')
```

* See [`destination` parameter](#destination)
* See [Exit logging help](/docs/help.md#exit-logging)
* See [Asynchronous logging ⇗](/docs/asynchronous.md)
* See [Log loss prevention ⇗](/docs/asynchronous.md#log-loss-prevention)

<a id="pino-multistream"></a>

### `pino.multistream(streamsArray, opts) => MultiStreamRes`
Expand Down
32 changes: 0 additions & 32 deletions docs/help.md
Expand Up @@ -269,35 +269,3 @@ log.info({ msg: 'mapped to originalMsg' }, 'a message')
// {"level":30,"time":1596313323106,"pid":63739,"hostname":"foo","msg":"no original message"}
// {"level":30,"time":1596313323107,"pid":63739,"hostname":"foo","msg":"a message","originalMsg":"mapped to originalMsg"}
```

<a id="exit-logging"></a>
## Exit logging (deprecated for Node v14+)

__In pino v7, The following piece of documentation is not needed in Node v14+ and it will
emit a deprecation notice.__

When a Node process crashes from uncaught exception, exits due to a signal,
or exits of it's own accord we may want to write some final logs – particularly
in cases of error.

Writing to a Node.js stream on exit is not necessarily guaranteed, and naively writing
to an asynchronous logger on exit will definitely lead to lost logs.

To write logs in an exit handler, create the handler with [`pino.final`](/docs/api.md#pino-final):

```js
process.on('uncaughtException', pino.final(logger, (err, finalLogger) => {
finalLogger.error(err, 'uncaughtException')
process.exit(1)
}))

process.on('unhandledRejection', pino.final(logger, (err, finalLogger) => {
finalLogger.error(err, 'unhandledRejection')
process.exit(1)
}))
```

The `finalLogger` is a special logger instance that will synchronously and reliably
flush every log line. This is important in exit handlers, since no more asynchronous
activity may be scheduled.

3 changes: 0 additions & 3 deletions lib/tools.js
Expand Up @@ -298,9 +298,6 @@ function createArgsNormalizer (defaultOptions) {
throw new Error('prettyPrint option is no longer supported, see the pino-pretty package (https://github.com/pinojs/pino-pretty)')
}

if ('onTerminated' in opts) {
throw Error('The onTerminated option has been removed, use pino.final instead')
}
const { enabled } = opts
if (enabled === false) opts.level = 'silent'
if (!stream) {
Expand Down
15 changes: 0 additions & 15 deletions pino.d.ts
Expand Up @@ -746,20 +746,6 @@ declare namespace pino {
streamsArray: (DestinationStream | StreamEntry)[] | DestinationStream | StreamEntry,
opts?: MultiStreamOptions
): MultiStreamRes

/**
* The pino.final method can be used to create an exit listener function.
* This listener function can be supplied to process exit events.
* The exit listener function will call the handler with
* @param [logger]: pino logger that serves as reference for the final logger
* @param [handler]: Function that will be called by the handler returned from this function
* @returns Exit listener function that can be supplied to process exit events and will call the supplied handler function
*/
export function final(
logger: Logger,
handler: (error: Error, finalLogger: Logger, ...args: any[]) => void,
): (error: Error | null, ...args: any[]) => void;
export function final(logger: Logger): Logger;
}

//// Callable default export
Expand All @@ -785,7 +771,6 @@ declare function pino<Options extends LoggerOptions>(options: Options, stream: D
export const destination: typeof pino.destination;
export const transport: typeof pino.transport;
export const multistream: typeof pino.multistream;
export const final: typeof pino.final;
export const levels: typeof pino.levels;
export const stdSerializers: typeof pino.stdSerializers;
export const stdTimeFunctions: typeof pino.stdTimeFunctions;
Expand Down
2 changes: 0 additions & 2 deletions test/types/pino-top-export.test-d.ts
Expand Up @@ -3,7 +3,6 @@ import type { SonicBoom } from "sonic-boom";

import {
destination,
final,
LevelMapping,
levels,
Logger,
Expand All @@ -20,7 +19,6 @@ import pino from "../../pino";

expectType<SonicBoom>(destination(""));
expectType<LevelMapping>(levels);
expectType<Logger>(final(pino()));
expectType<MultiStreamRes>(multistream(process.stdout));
expectType<SerializedError>(stdSerializers.err({} as any));
expectType<string>(stdTimeFunctions.isoTime());
Expand Down