Skip to content

jamestalton/pino-zen

Repository files navigation

pino-zen

Colored log formatter for Pino JSON logs. Works as a Pino transport or a CLI pipe.

pino-zen output

Install

npm install pino-zen        # project dependency
npm install -g pino-zen     # global CLI
npx pino-zen                # run without installing

Pino Transport

import pino from "pino"

const logger = pino({
  transport: {
    target: "pino-zen",
  },
})

Multiple Targets

const logger = pino({
  level: "debug",
  transport: {
    targets: [
      { target: "pino/file", options: { destination: "app.log" } },
      { target: "pino-zen" },
    ],
  },
})

Custom Destination

By default the transport writes to stdout. Pass a file path or file descriptor via destination:

{ target: "pino-zen", options: { destination: "/var/log/app.log" } }

CLI

Pipe any Pino NDJSON output through the CLI:

node app.js | pino-zen
node app.js | npx pino-zen
Flag Short Description
--module <field> -m Use a field as the module prefix

Options

These options work with both the transport and the CLI.

Module Mode

Prepends a color-coded, right-aligned module name to each log line. Useful for distinguishing logs from different components.

Transport:

const logger = pino({
  transport: {
    target: "pino-zen",
    options: { module: "name" },
  },
})

logger.info({ name: "api" }, "request processed")
logger.info({ name: "auth" }, "user verified")

CLI:

node app.js | pino-zen -m name

Output:

 [api] INFO request processed
[auth] INFO user verified

Module names are automatically color-cycled and right-aligned to the longest name seen.

Field Suppression

Hide specific fields from output with the formatter option:

{
  target: "pino-zen",
  options: { formatter: { pid: false, hostname: false } },
}

License

MIT