Registry / observability / pino-http-print

pino-http-print

JSON →
library4.0.0jsnpmunverified

pino-http-print is a specialized utility for formatting and printing HTTP request and response logs generated by Pino-compatible HTTP loggers (such as pino-http, express-pino-logger, restify-pino-logger, or koa-pino-logger) into a concise, human-readable, `curl`-like output. It functions primarily as a Pino transport, transforming raw JSON log lines into an easily digestible format suitable for console debugging or integration with other output streams. The current stable version is v4.0.0. As part of the pinojs ecosystem, releases typically align with broader Pino updates, ensuring compatibility with current Node.js versions and core Pino features. Its key differentiation lies in its dedicated focus on structuring HTTP log data for rapid analysis, while also capable of leveraging `pino-pretty` to format general application logs when the `all` option is enabled, providing a cohesive debugging experience.

npm install pino-http-print
INSTALL
IMPORT
SIG · PINO-HTTP-PRINT
P
pino-http-print
observabilityjavascriptv4.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

httpPrintFactory
import { httpPrintFactory } from 'pino-http-print'
import pinoHttpPrint from 'pino-http-print'
When using pino-http-print directly as a module, for instance, to pass a printer stream to `pino-http`, `express-pino-logger`, etc., `httpPrintFactory` is a named export.
httpPrintFactory
const { httpPrintFactory } = require('pino-http-print')
const pinoHttpPrint = require('pino-http-print')
For CommonJS environments, `httpPrintFactory` is accessed as a named property of the module export. The module does not provide a default export.
'pino-http-print'
const transport = pino.transport({ target: 'pino-http-print', options: { ... } })
const transport = pino.transport('pino-http-print', { ... })
When configured as a Pino transport, the package name is provided as a string value to the `target` property within the transport configuration object.

Demonstrates `pino-http-print` configured as a Pino transport. It logs both HTTP requests (via `pino-http`) and general application messages from a simple Node.js HTTP server, showcasing its formatting capabilities for debugging.

const pino = require('pino'); const http = require('http'); const pinoHttp = require('pino-http'); // Configure pino-http-print as a Pino transport const transport = pino.transport({ target: 'pino-http-print', options: { destination: 1, // Output to stdout all: true, // Also print non-HTTP logs using pino-pretty colorize: true, translateTime: 'SYS:HH:MM:ss', // Custom time format prettyOptions: { ignore: 'pid,hostname', // Example pino-pretty option to ignore fields } } }); // Create a Pino logger instance using the configured transport const logger = pino(transport); // Integrate pino-http with the logger const httpLogger = pinoHttp({ logger }); const server = http.createServer((req, res) => { httpLogger(req, res); // Attach pino-http to the request if (req.url === '/') { logger.info('Handling root request.'); res.end('Hello, World!'); } else if (req.url === '/error') { logger.error('An example error log for internal server error.'); res.statusCode = 500; res.end('Internal Server Error'); } else { logger.warn('Unknown path accessed.'); res.statusCode = 404; res.end('Not Found'); } }); server.listen(3000, () => { logger.info('Server listening on http://localhost:3000'); console.log('To test, run this script and then use curl in another terminal:'); console.log(' curl http://localhost:3000'); console.log(' curl http://localhost:3000/error'); console.log(' curl http://localhost:3000/unknown'); });
Debug
Known issues
breakingVersion 4.0.0 of `pino-http-print` officially dropped support for Node.js 12. Running on unsupported Node.js versions may lead to unexpected behavior or failures.
fix
Upgrade your Node.js environment to version 14 or higher. Node.js 18+ is explicitly supported and recommended for v4.x.
affects: >=4.0.0
gotchaOptions specific to `pino-pretty` (e.g., `ignore`, `sync`) must be encapsulated within the `prettyOptions` object when passed to `pino-http-print`, especially when `all: true` is enabled.
fix
Always nest `pino-pretty` options under `prettyOptions`, for example: `{ all: true, prettyOptions: { ignore: 'pid,hostname' } }`.
affects: >=3.0.0
gotchaThe `destination` option defaults to `1`, representing standard output (stdout). If you intend to redirect logs to a file or another custom stream, this option must be explicitly set.
fix
To write to a file, provide a writeable stream such as `destination: fs.createWriteStream('./http.log')` or a numeric file descriptor if applicable.
affects: >=3.0.0
Errors
Common errors & fixes
Error: Cannot find module 'pino-http-print'
The `pino-http-print` package is not installed as a dependency in your project or globally for CLI usage.
fix
Install the package using npm: `npm install pino-http-print` for local use, or `npm install -g pino-http-print` if planning to use it via the CLI as a legacy Pino transport.
TypeError: pino is not a function
This error often occurs when `pino.transport` is called incorrectly, or when the returned transport configuration is not properly passed to the `pino()` constructor to create a logger instance.
fix
Ensure you are creating your logger by passing the transport *configuration object* to `pino()`: `const transport = pino.transport({ target: 'pino-http-print', ... }); const logger = pino(transport);`
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies
pinorequiredCore logging library that this package extends as a transport, necessary for its primary function.
pino-prettyoptionalUsed internally for formatting non-HTTP log messages when the 'all' option is enabled, and for processing the 'prettyOptions' configuration.
Agent activity
26 hits · last 30 days
node
24
OpenAI (training)
2
Resources
pino-http-print — npm install pino-http-print · libregistry