or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

browser.mdchild-loggers.mdindex.mdlogger-configuration.mdlogger-methods.mdserializers.mdstreams.mdtransports.md
tile.json

tessl/npm-pino

Super fast, all natural JSON logger with exceptional performance for structured logging applications.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/pino@9.9.x

To install, run

npx @tessl/cli install tessl/npm-pino@9.9.0

index.mddocs/

Pino

Pino 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.

Package Information

  • Package Name: pino
  • Package Type: npm
  • Language: JavaScript (with TypeScript definitions)
  • Installation: npm install pino

Core Imports

const pino = require('pino');

For ES modules:

import pino from 'pino';

TypeScript imports:

import pino, { Logger, LoggerOptions } from 'pino';

Basic Usage

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');

Architecture

Pino is built around several key components:

  • Core Logger: Main logging interface with configurable levels and output formatting
  • Child Loggers: Inherit settings from parent while adding specific bindings
  • Transport System: Worker thread-based log processing for high performance
  • Stream Management: Optimized destination streams with sonic-boom for throughput
  • Serialization: Custom object serializers and automatic redaction capabilities
  • Browser Support: Compatible logging interface for browser environments

Capabilities

Core Logging Methods

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;
}

Logger Methods

Logger Configuration

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
}

Logger Configuration

Child Loggers

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>;

Child Loggers

Transport System

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;
}

Transports

Stream Management

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;
}

Streams

Serializers and Redaction

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;
}

Serializers

Browser Compatibility

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;
  };
}

Browser Support

Static Properties

Standard Serializers

const stdSerializers: {
  req: SerializerFn;  // HTTP request serializer
  res: SerializerFn;  // HTTP response serializer
  err: SerializerFn;  // Error object serializer
};

Log Levels

const levels: {
  values: { [level: string]: number };
  labels: { [level: number]: string };
};

Time Functions

const stdTimeFunctions: {
  epochTime: TimeFn;   // Default timestamp format
  nullTime: TimeFn;    // No timestamp
  isoTime: TimeFn;     // ISO 8601 format
  unixTime: TimeFn;    // Unix timestamp
};

Internal Symbols

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;
};

Version Information

const version: string;  // Package version

Types

type 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>;

TypeScript Support

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');