X Enterprises
fastify-xlogger

getLoggerOptions(options?)

Build Pino logger options with xLogger's redaction, serializers, and transport configured.

getLoggerOptions(options?)

Named export from @xenterprises/fastify-xlogger. Returns a Pino configuration object pre-configured with xLogger's default secret redaction list, canonical request/response/error serializers, and environment-aware transport (pino-pretty in dev, JSON in prod). Pass the result directly to Fastify({ logger: ... }) before registering the plugin.

Signature

import { getLoggerOptions } from "@xenterprises/fastify-xlogger";

getLoggerOptions(options?: {
  level?: string
  redactPaths?: string[]
  pretty?: boolean
  serviceName?: string
  transport?: {
    target?: string
    options?: object
    targets?: object[]
  }
}): PinoLoggerOptions

Params

NameTypeRequiredDefaultDescription
levelstringNo"info" in prod, "debug" otherwisePino log level
redactPathsstring[]No[]Additional paths to redact (merged with defaults)
prettybooleanNofalse in prodForce pino-pretty even in production
serviceNamestringNoSERVICE_NAME env or "fastify-app"Service name on every log entry
transportobjectNopino-pretty in dev, none in prodCustom Pino transport (overrides default)
transport.targetstringNoTransport module (e.g. "@logtail/pino")
transport.optionsobjectNoOptions passed to the transport module
transport.targetsobject[]NoMultiple transport targets

Returns

A Pino-compatible logger options object. Pass directly to Fastify({ logger: ... }).

Throws

Never throws.

Examples

Standard setup

import Fastify from "fastify";
import xLogger, { getLoggerOptions } from "@xenterprises/fastify-xlogger";

const fastify = Fastify({
  logger: getLoggerOptions({ serviceName: "payments-api" }),
});

await fastify.register(xLogger, { serviceName: "payments-api" });

Custom transport — BetterStack (Logtail)

const fastify = Fastify({
  logger: getLoggerOptions({
    serviceName: "my-api",
    transport: {
      target: "@logtail/pino",
      options: { sourceToken: process.env.BETTERSTACK_SOURCE_TOKEN },
    },
  }),
});

Additional redact paths

const fastify = Fastify({
  logger: getLoggerOptions({
    redactPaths: ["req.headers['x-internal-token']", "*.creditCardLast4"],
  }),
});

See also

AI Context

package: "@xenterprises/fastify-xlogger"
export: getLoggerOptions(options?) — named export, NOT a decorator
use-when: Configure Pino at Fastify instantiation time (Fastify({ logger: getLoggerOptions(...) })) with default redaction, serializers, and transport
call-before: Fastify() constructor, before registering xLogger plugin
returns: Pino-compatible logger options object
Copyright © 2026