CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-pino

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

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

logger-methods.mddocs/

Logger Methods

Core logging functionality with standard severity levels and structured output formatting. Each method provides flexible parameter handling for objects, messages, and format strings.

Capabilities

Fatal Level Logging

Log at 'fatal' level for unrecoverable errors that cause application termination.

/**
 * Log at 'fatal' level the given message and optional object properties
 * @param obj - Object to be serialized into the log line
 * @param msg - Log message, can include format specifiers
 * @param args - Format string values when msg contains format specifiers
 */
fatal(obj?: object, msg?: string, ...args: any[]): void;
fatal(msg: string, ...args: any[]): void;

Usage Examples:

logger.fatal('Application crashed');
logger.fatal({ error: 'ENOMEM' }, 'Out of memory');
logger.fatal('Database connection failed: %s', errorMessage);
logger.fatal({ userId: 123, action: 'login' }, 'Authentication failed for user');

Error Level Logging

Log at 'error' level for recoverable errors and exceptions.

/**
 * Log at 'error' level the given message and optional object properties
 * @param obj - Object to be serialized into the log line
 * @param msg - Log message, can include format specifiers
 * @param args - Format string values when msg contains format specifiers
 */
error(obj?: object, msg?: string, ...args: any[]): void;
error(msg: string, ...args: any[]): void;

Usage Examples:

logger.error('Request validation failed');
logger.error({ statusCode: 400 }, 'Bad request received');
logger.error('Connection timeout after %d ms', timeout);
logger.error(new Error('Database error'), 'Query execution failed');

Warn Level Logging

Log at 'warn' level for warning conditions that don't prevent operation.

/**
 * Log at 'warn' level the given message and optional object properties
 * @param obj - Object to be serialized into the log line
 * @param msg - Log message, can include format specifiers
 * @param args - Format string values when msg contains format specifiers
 */
warn(obj?: object, msg?: string, ...args: any[]): void;
warn(msg: string, ...args: any[]): void;

Usage Examples:

logger.warn('Deprecated API endpoint used');
logger.warn({ endpoint: '/old-api' }, 'Using deprecated endpoint');
logger.warn('High memory usage: %d%%', memoryPercent);

Info Level Logging

Log at 'info' level for general informational messages about application operation.

/**
 * Log at 'info' level the given message and optional object properties
 * @param obj - Object to be serialized into the log line
 * @param msg - Log message, can include format specifiers
 * @param args - Format string values when msg contains format specifiers
 */
info(obj?: object, msg?: string, ...args: any[]): void;
info(msg: string, ...args: any[]): void;

Usage Examples:

logger.info('Application started');
logger.info({ port: 3000 }, 'Server listening on port');
logger.info('Processed %d records in %d ms', count, duration);
logger.info({ userId: 123, action: 'login' }, 'User logged in successfully');

Debug Level Logging

Log at 'debug' level for detailed diagnostic information, typically disabled in production.

/**
 * Log at 'debug' level the given message and optional object properties
 * @param obj - Object to be serialized into the log line
 * @param msg - Log message, can include format specifiers
 * @param args - Format string values when msg contains format specifiers
 */
debug(obj?: object, msg?: string, ...args: any[]): void;
debug(msg: string, ...args: any[]): void;

Usage Examples:

logger.debug('Processing request');
logger.debug({ requestId: 'abc123' }, 'Request details');
logger.debug('Cache hit ratio: %d%%', hitRatio);

Trace Level Logging

Log at 'trace' level for very detailed diagnostic information, including execution paths.

/**
 * Log at 'trace' level the given message and optional object properties
 * @param obj - Object to be serialized into the log line
 * @param msg - Log message, can include format specifiers
 * @param args - Format string values when msg contains format specifiers
 */
trace(obj?: object, msg?: string, ...args: any[]): void;
trace(msg: string, ...args: any[]): void;

Usage Examples:

logger.trace('Entering function parseRequest');
logger.trace({ functionName: 'validateInput' }, 'Function entry');
logger.trace('Variable state: %j', variableState);

Silent Level Logging

No-op function that discards all log messages, used when logging is completely disabled.

/**
 * No-op function that discards all log messages
 * @param obj - Ignored object parameter
 * @param msg - Ignored message parameter
 * @param args - Ignored additional arguments
 */
silent(obj?: object, msg?: string, ...args: any[]): void;
silent(msg: string, ...args: any[]): void;

Level Management

Level Property

Control the minimum logging level for the logger instance.

/**
 * Set or get the current logging level
 * Levels in order: trace(10), debug(20), info(30), warn(40), error(50), fatal(60), silent(Infinity)
 */
level: string;

Usage Examples:

// Set level
logger.level = 'debug';
logger.level = 'warn';
logger.level = 'silent'; // Disable all logging

// Get current level
console.log(logger.level); // 'info'

Level Value

Get the numeric value of the current logging level.

/**
 * Returns the numeric value for the logger instance's logging level
 * trace=10, debug=20, info=30, warn=40, error=50, fatal=60, silent=Infinity
 */
readonly levelVal: number;

Level Enabled Check

Check if a specific log level will produce output.

/**
 * Utility method for determining if a given log level will write to the destination
 * @param level - Level to check (string or number)
 * @returns true if the level is enabled, false otherwise
 */
isLevelEnabled(level: string | number): boolean;

Usage Examples:

if (logger.isLevelEnabled('debug')) {
  // Expensive debug computation only if debug is enabled
  const debugInfo = computeExpensiveDebugInfo();
  logger.debug({ debugInfo }, 'Debug information');
}

// Check numeric levels
if (logger.isLevelEnabled(20)) { // debug level
  logger.debug('Debug message');
}

Level Labels Output

Control whether levels are output as strings or numbers.

/**
 * When true, outputs level as string label instead of numeric value in log records
 * Default: false (outputs numeric values)
 */
useLevelLabels: boolean;

Usage Examples:

const logger = pino();
logger.useLevelLabels = true;

logger.info('Hello world');
// Output: {"level":"info","time":1531171074631,"msg":"hello world",...}

logger.useLevelLabels = false;
logger.info('Hello world');
// Output: {"level":30,"time":1531171074631,"msg":"hello world",...}

Logger Version

Access the Pino package version from the logger instance.

/**
 * Exposes the Pino package version (same as the static pino.version)
 */
readonly version: string;

Usage Examples:

const logger = pino();
console.log(logger.version); // "9.9.2"

Message Prefix

Get the current message prefix for the logger instance.

/**
 * Get the message prefix that will be prepended to all log messages
 * Set via the msgPrefix option during logger creation or child logger creation
 */
readonly msgPrefix: string | undefined;

Usage Examples:

const logger = pino({ msgPrefix: '[APP] ' });
console.log(logger.msgPrefix); // "[APP] "

const childLogger = logger.child({}, { msgPrefix: '[WORKER] ' });
console.log(childLogger.msgPrefix); // "[WORKER] "

Format Specifiers

Pino supports Node.js util.format() style format specifiers in log messages:

  • %s - String
  • %d - Number (integer or floating point)
  • %j - JSON (calls JSON.stringify)
  • %o - Object (Node.js object inspection)
  • %O - Object (Node.js object inspection with options)
  • %% - Literal percent sign

Usage Examples:

logger.info('User %s has %d points', username, points);
logger.debug('Request body: %j', requestBody);
logger.error('Error occurred at %s: %o', new Date().toISOString(), errorObj);

Log Output Format

All log methods produce structured JSON output with consistent fields:

{
  "level": 30,
  "time": 1531171074631,
  "msg": "hello world",
  "pid": 657,
  "hostname": "server-01"
}

Additional fields from the object parameter are merged into the log record:

{
  "level": 50,
  "time": 1531171074631,
  "msg": "Request failed",
  "pid": 657,
  "hostname": "server-01",
  "userId": 123,
  "requestId": "abc-def-456",
  "statusCode": 500
}

Install with Tessl CLI

npx tessl i tessl/npm-pino

docs

browser.md

child-loggers.md

index.md

logger-configuration.md

logger-methods.md

serializers.md

streams.md

transports.md

tile.json