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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
level | string | No | "info" in prod, "debug" otherwise | Pino log level |
redactPaths | string[] | No | [] | Additional paths to redact (merged with defaults) |
pretty | boolean | No | false in prod | Force pino-pretty even in production |
serviceName | string | No | SERVICE_NAME env or "fastify-app" | Service name on every log entry |
transport | object | No | pino-pretty in dev, none in prod | Custom Pino transport (overrides default) |
transport.target | string | No | — | Transport module (e.g. "@logtail/pino") |
transport.options | object | No | — | Options passed to the transport module |
transport.targets | object[] | No | — | Multiple 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
- logEvent(params) — log events after the plugin is registered
- logBoundary(params) — log external API calls
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
