Super fast, all natural JSON logger with exceptional performance for structured logging applications.
npx @tessl/cli install tessl/npm-pino@9.9.0Pino is a very low overhead Node.js JSON logger that provides exceptional performance for structured logging applications. It offers comprehensive logging features including child loggers, custom serializers, redaction capabilities, and transport systems for processing logs in separate processes or threads. Designed with minimal resource consumption in mind, Pino delivers over 5x better performance than many alternatives while maintaining rich functionality for production logging needs.
npm install pinoconst pino = require('pino');For ES modules:
import pino from 'pino';TypeScript imports:
import pino, { Logger, LoggerOptions } from 'pino';const logger = pino();
// Basic logging
logger.info('hello world');
logger.error('this is at error level');
logger.info('the answer is %d', 42);
logger.info({ obj: 42 }, 'hello world');
// Child loggers
const child = logger.child({ a: 'property' });
child.info('hello child!');
// Level control
logger.level = 'debug';
logger.debug('this is a debug statement');Pino is built around several key components:
Essential logging functionality with standard severity levels and structured output formatting.
interface Logger {
fatal(obj?: object, msg?: string, ...args: any[]): void;
error(obj?: object, msg?: string, ...args: any[]): void;
warn(obj?: object, msg?: string, ...args: any[]): void;
info(obj?: object, msg?: string, ...args: any[]): void;
debug(obj?: object, msg?: string, ...args: any[]): void;
trace(obj?: object, msg?: string, ...args: any[]): void;
silent(obj?: object, msg?: string, ...args: any[]): void;
}Comprehensive configuration system for customizing logger behavior, output format, and performance characteristics.
function pino(options?: LoggerOptions): Logger;
function pino(options: LoggerOptions, stream?: DestinationStream): Logger;
interface LoggerOptions {
level?: string;
name?: string;
timestamp?: boolean | TimeFn;
serializers?: { [key: string]: SerializerFn };
redact?: string[] | RedactOptions;
transport?: TransportOptions;
formatters?: FormattersOptions;
// ... additional options
}Create specialized logger instances that inherit parent settings while adding contextual bindings.
interface Logger {
child(bindings: Bindings, options?: ChildLoggerOptions): Logger;
bindings(): Bindings;
setBindings(bindings: Bindings): void;
}
type Bindings = Record<string, any>;High-performance log processing system using worker threads for handling log output without blocking the main thread.
function transport(options: TransportSingleOptions | TransportMultiOptions | TransportPipelineOptions): ThreadStream;
interface TransportSingleOptions {
target: string;
options?: Record<string, any>;
worker?: WorkerOptions;
}Optimized destination streams and multistream functionality for directing logs to multiple outputs.
function destination(dest?: number | string | object | DestinationStream): SonicBoom;
function multistream(streams: StreamEntry[], opts?: MultiStreamOptions): MultiStreamRes;
interface StreamEntry {
stream: DestinationStream;
level?: string;
}Custom object serialization and sensitive data redaction for secure and structured log output.
interface LoggerOptions {
serializers?: { [key: string]: SerializerFn };
redact?: string[] | RedactOptions;
}
type SerializerFn = (value: any) => any;
interface RedactOptions {
paths: string[];
censor?: string | ((value: any, path: string[]) => any);
remove?: boolean;
}Browser-compatible logging with console output and transmit functionality for client-side applications.
// Browser-specific options
interface BrowserOptions {
asObject?: boolean;
write?: WriteFn | { [level: string]: WriteFn };
serialize?: boolean | string[];
transmit?: {
level?: string;
send: (level: string, logEvent: LogEvent) => void;
};
}const stdSerializers: {
req: SerializerFn; // HTTP request serializer
res: SerializerFn; // HTTP response serializer
err: SerializerFn; // Error object serializer
};const levels: {
values: { [level: string]: number };
labels: { [level: number]: string };
};const stdTimeFunctions: {
epochTime: TimeFn; // Default timestamp format
nullTime: TimeFn; // No timestamp
isoTime: TimeFn; // ISO 8601 format
unixTime: TimeFn; // Unix timestamp
};const symbols: {
readonly setLevelSym: unique symbol;
readonly getLevelSym: unique symbol;
readonly levelValSym: unique symbol;
readonly useLevelLabelsSym: unique symbol;
readonly mixinSym: unique symbol;
readonly lsCacheSym: unique symbol;
readonly chindingsSym: unique symbol;
readonly parsedChindingsSym: unique symbol;
readonly asJsonSym: unique symbol;
readonly writeSym: unique symbol;
readonly serializersSym: unique symbol;
readonly redactFmtSym: unique symbol;
readonly timeSym: unique symbol;
readonly timeSliceIndexSym: unique symbol;
readonly streamSym: unique symbol;
readonly stringifySym: unique symbol;
readonly stringifySafeSym: unique symbol;
readonly stringifiersSym: unique symbol;
readonly endSym: unique symbol;
readonly formatOptsSym: unique symbol;
readonly messageKeySym: unique symbol;
readonly errorKeySym: unique symbol;
readonly nestedKeySym: unique symbol;
readonly wildcardFirstSym: unique symbol;
readonly needsMetadataGsym: unique symbol;
readonly useOnlyCustomLevelsSym: unique symbol;
readonly formattersSym: unique symbol;
readonly hooksSym: unique symbol;
};const version: string; // Package versiontype Level = "fatal" | "error" | "warn" | "info" | "debug" | "trace";
type LevelWithSilent = Level | "silent";
type TimeFn = () => string;
type SerializerFn = (value: any) => any;
type WriteFn = (obj: object) => void;
interface Bindings {
[key: string]: any;
}
interface DestinationStream {
write(msg: string): void;
}
// TypeScript Generic Support for Custom Levels
type Logger<CustomLevels extends string = never, UseOnlyCustomLevels extends boolean = boolean> = BaseLogger & LoggerExtras<CustomLevels> & CustomLevelLogger<CustomLevels, UseOnlyCustomLevels>;Pino provides comprehensive TypeScript support including generic types for custom logging levels:
// Standard logger
const logger: Logger = pino();
// Logger with custom levels
const customLogger: Logger<'audit' | 'security'> = pino({
customLevels: { audit: 35, security: 45 }
});
// Type-safe custom level usage
customLogger.audit('Audit event'); // TypeScript knows this method exists
customLogger.security('Security alert');