Skip to content

API Reference & Compatibility

The inventory below is generated from the source entry points. The reference that follows describes the current source contract.

Functions

configureLogger

Source
configureLogger(options: LoggerOptions) => Logger

Exported from: @nexload-sdk/logger

Public function exported by @nexload-sdk/logger.

createTestLogger

Source
createTestLogger(options?: Partial<LoggerOptions>) => { logger: Logger; entries: LogEntry[]; clear(): void; }

Exported from: @nexload-sdk/logger/testing

Public function exported by @nexload-sdk/logger.

getLogContext

Source
getLogContext() => LogBindings

Exported from: @nexload-sdk/logger

Public function exported by @nexload-sdk/logger.

getPayloadLoggerConfig

Source
getPayloadLoggerConfig() => PayloadLoggerConfig

Exported from: @nexload-sdk/logger

Public function exported by @nexload-sdk/logger.

resolveTraceId

Source
resolveTraceId(headers: Headers | HeaderRecord) => string

Exported from: @nexload-sdk/logger

Public function exported by @nexload-sdk/logger.

traceHeaders

Source
traceHeaders() => Record<string, string>

Exported from: @nexload-sdk/logger

Public function exported by @nexload-sdk/logger.

withLogContext

Source
withLogContext<T>(bindings: LogBindings, fn: () => T) => T

Exported from: @nexload-sdk/logger

Public function exported by @nexload-sdk/logger.

Constants

DEFAULT_REDACT_PATHS

Source
DEFAULT_REDACT_PATHS: readonly string[]

Exported from: @nexload-sdk/logger

Public constant exported by @nexload-sdk/logger.

TRACE_HEADER

Source
TRACE_HEADER: "x-trace-id"

Exported from: @nexload-sdk/logger

Public constant exported by @nexload-sdk/logger.

logger

Source
logger: Logger

Exported from: @nexload-sdk/logger

Public constant exported by @nexload-sdk/logger.

Interfaces

Logger

Source
interface Logger {
  trace: LogMethod;
  debug: LogMethod;
  info: LogMethod;
  success: LogMethod;
  warn: LogMethod;
  error: LogMethod;
  fatal: LogMethod;
  child(bindings: LogBindings): Logger;
  isLevelEnabled(level: LogLevel): boolean;
}

Exported from: @nexload-sdk/logger

Public interface exported by @nexload-sdk/logger.

LoggerOptions

Source
interface LoggerOptions {
  service: string;
  level?: LogLevel;
  release?: string;
  instance?: string;
  environment?: string;
  redact?: { paths?: string[]; replaceDefaults?: boolean; censor?: string };
  pretty?: boolean;
  destination?: { write(line: string): void };
  base?: Record<string, string | number | boolean>;
  force?: boolean;
}

Exported from: @nexload-sdk/logger

Public interface exported by @nexload-sdk/logger.

Types

LogBindings

Source
type LogBindings = Record<string, unknown>;

Exported from: @nexload-sdk/logger

Public type exported by @nexload-sdk/logger.

LogEntry

Source
type LogEntry = {
  level: LogLevel;
  time: string;
  service: string;
  msg?: string;
  [key: string]: unknown;
};

Exported from: @nexload-sdk/logger

Public type exported by @nexload-sdk/logger.

LogLevel

Source
type LogLevel =
  | "trace"
  | "debug"
  | "info"
  | "success"
  | "warn"
  | "error"
  | "fatal";

Exported from: @nexload-sdk/logger

Public type exported by @nexload-sdk/logger.

PayloadLoggerConfig

Source
type PayloadLoggerConfig = {
  options: ReturnType<typeof buildPinoOptions>;
  destination?: LoggerOptions["destination"];
};

Exported from: @nexload-sdk/logger

Public type exported by @nexload-sdk/logger.


Import the following from @nexload-sdk/logger. The testing helper has its own subpath.

ExportSignatureExample and behavior
loggerconst logger: Loggerimport { logger } from "@nexload-sdk/logger". The lazy proxy resolves the current configuration on each call.
Default exportexport default loggerimport logger from "@nexload-sdk/logger". The default and named exports share the same proxy.
getPayloadLoggerConfiggetPayloadLoggerConfig(): { options: pino.LoggerOptions; destination?: { write(line: string): void } }Node.js Payload configuration bridge. Call configureLogger() before buildConfig(); rebuild Payload configuration after forced reconfiguration.
configureLoggerconfigureLogger(options: LoggerOptions): LoggerconfigureLogger({ service: "shop-api" }) configures the runtime.
withLogContextwithLogContext<T>(bindings: LogBindings, fn: () => T): TwithLogContext({ requestId: "req-123" }, handleRequest) runs the handler with request bindings where async context is supported.
getLogContextgetLogContext(): LogBindingsconst { requestId } = getLogContext() reads the current bindings.
TRACE_HEADERconst TRACE_HEADER: "x-trace-id"response.headers.set(TRACE_HEADER, traceId) sends the trace ID in the response.
resolveTraceIdresolveTraceId(headers: Headers | Record<string, string | undefined>): stringresolveTraceId(request.headers) reuses an incoming ID matching /^[A-Za-z0-9-]{8,64}$/ or generates a UUID.
traceHeaderstraceHeaders(): Record<string, string>const outbound = new Headers(traceHeaders()) copies the active trace header. With no active trace ID it returns an empty record.
DEFAULT_REDACT_PATHSconst DEFAULT_REDACT_PATHS: readonly string[]const paths = [...DEFAULT_REDACT_PATHS, "customer.nationalCode"] copies the defaults for inspection or reuse.
TypeSignatureExample
LogLevel"trace" | "debug" | "info" | "success" | "warn" | "error" | "fatal"const level: LogLevel = "warn"
LogBindingsRecord<string, unknown>const bindings: LogBindings = { module: "orders" }
LoggerSee methods below.const log: Logger = logger.child({ module: "orders" })
LoggerOptionsSee configuration signature below.const options: LoggerOptions = { service: "shop-api", level: "info" }
LogEntry{ level: LogLevel; time: string; service: string; msg?: string; [key: string]: unknown }const first: LogEntry | undefined = entries[0]

All level methods use the same signature.

interface Logger {
trace(objOrMsg?: object | Error | string, msg?: string): void;
debug(objOrMsg?: object | Error | string, msg?: string): void;
info(objOrMsg?: object | Error | string, msg?: string): void;
success(objOrMsg?: object | Error | string, msg?: string): void;
warn(objOrMsg?: object | Error | string, msg?: string): void;
error(objOrMsg?: object | Error | string, msg?: string): void;
fatal(objOrMsg?: object | Error | string, msg?: string): void;
child(bindings: LogBindings): Logger;
isLevelEnabled(level: LogLevel): boolean;
}

log.isLevelEnabled("debug") checks whether debug events will be emitted. Levels map to trace: 10, debug: 20, info: 30, success: 35, warn: 40, error: 50, and fatal: 60.

interface LoggerOptions {
service: string;
level?: LogLevel;
release?: string;
instance?: string;
environment?: string;
redact?: { paths?: string[]; replaceDefaults?: boolean; censor?: string };
pretty?: boolean;
destination?: { write(line: string): void };
base?: Record<string, string | number | boolean>;
force?: boolean;
}

On Node, pretty output defaults to enabled outside production; destination takes precedence. Browser and Edge use pino browser output and ignore these server stream options. Server log records include service, pid, and ISO time, plus configured release, instance, and environment fields.

function createTestLogger(options?: Partial<LoggerOptions>): {
logger: Logger;
entries: LogEntry[];
clear(): void;
};
import { createTestLogger } from "@nexload-sdk/logger/testing";
const { logger, entries, clear } = createTestLogger({ service: "test", level: "info" });
logger.success({ event: "order.lifecycle.placed", orderId: "123" }, "Order placed");
const event = entries[0]?.event;
clear();

The test logger captures parsed entries independently of global configuration. clear() empties the existing entries array.


Root export conditions browser, edge-light, and worker select the browser bundle; import and require select Node bundles. The ./testing subpath provides Node import and require bundles.

Default redaction covers the ten sensitive keys listed in the guide at the top level and one level below, plus the explicit header and body paths. It does not recursively redact deeper keys. The censor defaults to [REDACTED]. Error serialization includes type, a 500-character message, a matching uppercase code, at most two nested causes, and a stack outside production.

RuntimeLoggingRequest context
Node.js and BunServer output with configurable destinationAsync request bindings
Edge and browserSame root APIExplicit bindings and trace headers