strong-tie/inbound-calls
0
1# Asynchronous Logging2 3Asynchronous logging enables the minimum overhead of Pino.4Asynchronous logging works by buffering log messages and writing them in larger chunks.5 6```js7const pino = require('pino')8const logger = pino(pino.destination({9 dest: './my-file', // omit for stdout10 minLength: 4096, // Buffer before writing11 sync: false // Asynchronous logging12}))13```14 15It's always possible to turn on synchronous logging by passing `sync: true`. 16In this mode of operation, log messages are directly written to the17output stream as the messages are generated with a _blocking_ operation.18 19* See [`pino.destination`](/docs/api.md#pino-destination)20* `pino.destination` is implemented on [`sonic-boom` ⇗](https://github.com/mcollina/sonic-boom).21 22### AWS Lambda23 24Asynchronous logging is disabled by default on AWS Lambda or any other environment25that modifies `process.stdout`. If forcefully turned on, we recommend calling `dest.flushSync()` at the end26of each function execution to avoid losing data.27 28## Caveats29 30Asynchronous logging has a couple of important caveats:31 32* As opposed to the synchronous mode, there is not a one-to-one relationship between33 calls to logging methods (e.g. `logger.info`) and writes to a log file34* There is a possibility of the most recently buffered log messages being lost35 in case of a system failure, e.g. a power cut.36 37See also:38 39* [`pino.destination` API](/docs/api.md#pino-destination)40* [`destination` parameter](/docs/api.md#destination)41 