pino-http-send is a basic handler for Pino logs that facilitates sending batches of structured log data to a desired HTTP or HTTPS endpoint. Currently at version 0.4.2, it is pre-v1, meaning minor version changes may introduce breaking changes. The library supports configurable HTTP methods (POST, PUT, PATCH, GET), two body types (JSON array wrapped in a 'logs' object or newline-delimited JSON), and includes basic authentication and retry mechanisms for failed sends. It can be used either as a command-line interface tool, piping `pino` output directly, or programmatically via its `createWriteStream` API, which acts as a Pino destination. Its key differentiators include its simplicity in setting up a direct HTTP log sink, batching capabilities to optimize network requests, and built-in retry logic, making it a robust, low-overhead option for forwarding Pino logs.
npm install pino-http-sendVerified import paths — ran on the pinned version, not inferred.
Demonstrates programmatic usage of `pino-http-send` by creating a dummy HTTP server to receive logs and configuring Pino to send logs to it via `createWriteStream`.
Always pin to exact minor versions (e.g., `~0.4.0` or `0.4.2`) and review release notes carefully before upgrading minor versions.
For custom headers, use the `createWriteStream` API and pass a `headers` object in the options. Example: `createWriteStream({ url: '...', headers: { 'Authorization': 'Bearer YOUR_TOKEN' } })`.Ensure your log ingestion endpoint is aware of and correctly parses the specific `bodyType` used by `pino-http-send`. If `json` is used, it should expect an object with a `logs` property containing the array. If `ndjson` is used, it should parse each line as a separate JSON object.
Specify the target URL using `--url` or `-u` flag. Example: `pino-http-send --url=http://your-log-endpoint.com/logs`.
Ensure `createWriteStream` is imported as a named export. For ESM: `import { createWriteStream } from 'pino-http-send';`. For CommonJS: `const { createWriteStream } = require('pino-http-send');`.Verify that the `bodyType` option (`json` or `ndjson`) passed to `createWriteStream` or the CLI `--bodyType` flag matches the format your log ingestion endpoint is designed to consume. Adjust either the client configuration or the server's parsing logic accordingly.