Pino HTTP Debug Printer

4.0.0 · active · verified Tue Apr 21

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.

Common errors

Warnings

Install

Imports

Quickstart

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');
});

view raw JSON →