# @onivoro/server-pino

> A thin wrapper around `nestjs-pino` for NestJS applications, providing a configuration class and console patching functionality.

Latest version **24.39.0** (published 2026-09-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @onivoro/server-pino
pnpm add @onivoro/server-pino
yarn add @onivoro/server-pino
bun add @onivoro/server-pino
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 24.39.0 |
| Published | 2026-09-23 |
| First published | 2024-11-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 15.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | icedlee337 |

## Links

- npm: https://www.npmjs.com/package/@onivoro/server-pino
- Repository: https://github.com/onivoro/monorepo
- Homepage: https://github.com/onivoro/monorepo#readme
- Issues: https://github.com/onivoro/monorepo/issues
- npm.io page: https://npm.io/package/@onivoro/server-pino

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0
- [@onivoro/server-common](https://npm.io/package/@onivoro/server-common.md) 24.39.0

## Recent versions

- 24.39.0 (latest) — 2026-09-23
- 24.38.2 — 2026-05-15
- 24.38.1 — 2026-05-12
- 24.38.0 — 2026-05-10
- 24.37.0 — 2026-05-10
- 24.36.0 — 2026-05-09
- 24.35.4 — 2026-05-09
- 24.35.3 — 2026-05-09
- 24.35.2 — 2026-04-27
- 24.35.1 — 2026-04-24
- 24.35.0 — 2026-04-23
- 24.34.2 — 2026-04-22
- 24.34.1 — 2026-04-22
- 24.34.0 — 2026-04-22
- 24.33.21 — 2026-04-19
- … 96 more at https://npm.io/package/@onivoro/server-pino/versions

## README

# @onivoro/server-pino

A thin wrapper around `nestjs-pino` for NestJS applications, providing a configuration class and console patching functionality.

## Installation

```bash
npm install @onivoro/server-pino nestjs-pino
```

## Overview

This library provides:
- A configuration class for `nestjs-pino` with sensible defaults
- A console patching function to redirect console methods to Pino logger
- A module that integrates with NestJS

## Usage

### Module Setup

```typescript
import { ServerPinoModule, ServerPinoConfig } from '@onivoro/server-pino';

const config = new ServerPinoConfig({
  excludeUrls: ['/api/health', /^\/api\/metrics/]
});

@Module({
  imports: [
    ServerPinoModule.configure(config)
  ]
})
export class AppModule {}
```

### Configuration Class

The `ServerPinoConfig` class extends `nestjs-pino` Params interface with default settings:

```typescript
const config = new ServerPinoConfig({
  excludeUrls: ['/api/health'],  // URLs to exclude from auto-logging
  useExisting: true,             // Use existing logger instance
  renameContext: 'app'           // Rename context property
});
```

Default configuration includes:
- Auto-generated request IDs using `randomUUID()`
- Redaction of sensitive headers (authorization, cookies, API keys, etc.)
- Info level logging
- Exclusion of specified URLs from auto-logging

### Console Patching

Replace console methods with Pino logger:

```typescript
import { patchConsole } from '@onivoro/server-pino';
import { PinoLogger } from 'nestjs-pino';

const logger = new PinoLogger(config);
const { restore } = patchConsole(logger);

// Now console methods use Pino
console.log('This goes to Pino');
console.error('This is an error');

// Restore original console if needed
restore();
```

Patched methods:
- `console.debug` → `logger.debug`
- `console.error` → `logger.error`
- `console.info` → `logger.info`
- `console.log` → `logger.info`
- `console.trace` → `logger.trace`
- `console.warn` → `logger.warn`

## API Reference

### ServerPinoConfig

Constructor options:
- `excludeUrls?: (string | RegExp)[]` - URLs to exclude from auto-logging (default: `['/api/health']`)
- All standard `nestjs-pino` Params options

### ServerPinoModule

```typescript
ServerPinoModule.configure(config: ServerPinoConfig, patchConsoleInstance?: boolean)
```

- `config` - ServerPinoConfig instance
- `patchConsoleInstance` - Whether to patch console methods (default: `false`)

### patchConsole

```typescript
function patchConsole(logger: PinoLogger): {
  _console: PinoLogger;
  restore: () => void;
}
```

## Complete Example

```typescript
import { Module } from '@nestjs/common';
import { ServerPinoModule, ServerPinoConfig } from '@onivoro/server-pino';

const pinoConfig = new ServerPinoConfig({
  excludeUrls: ['/api/health', '/api/metrics'],
  pinoHttp: {
    level: process.env.LOG_LEVEL || 'info',
    transport: process.env.NODE_ENV === 'development' ? {
      target: 'pino-pretty',
      options: {
        colorize: true
      }
    } : undefined
  }
});

@Module({
  imports: [
    ServerPinoModule.configure(pinoConfig, true) // Enable console patching
  ]
})
export class AppModule {}
```

## Dependencies

This library depends on:
- `nestjs-pino` - The underlying Pino integration for NestJS
- `@nestjs/common` - NestJS common utilities
- `@onivoro/server-common` - For the `moduleFactory` function

## License

MIT

---
_Source: https://npm.io/package/@onivoro/server-pino · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
