0.1.0 • Published 8 months ago

@vevkit/saga-pino v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@vevkit/saga-pino

Pino transport for @vevkit/saga logger.

Installation

npm install @vevkit/saga-pino pino pino-pretty

Usage

Basic Usage

import { Logger } from '@vevkit/saga';
import { PinoTransport } from '@vevkit/saga-pino';

const logger = new Logger({
  transports: [
    new PinoTransport()
  ]
});

logger.info('Hello from VevKit!');

Pretty Printing

Enable pretty printing for development:

const logger = new Logger({
  transports: [
    new PinoTransport({
      pretty: true // Uses default pretty printing options
    })
  ]
});

Customize pretty printing:

const logger = new Logger({
  transports: [
    new PinoTransport({
      pretty: {
        colorize: true,
        translateTime: 'UTC:yyyy-mm-dd HH:MM:ss',
        ignore: 'hostname,pid'
      }
    })
  ]
});

Custom Serializers

Add custom serializers for specific properties:

const logger = new Logger({
  transports: [
    new PinoTransport({
      serializers: {
        user: (user) => ({
          id: user.id,
          role: user.role
          // Omit sensitive information
        })
      }
    })
  ]
});

logger.info('User action', { 
  user: { 
    id: 123, 
    role: 'admin',
    password: 'secret' // Will be omitted by serializer
  }
});

Custom Pino Instance

Use your own Pino instance:

import pino from 'pino';

const pinoInstance = pino({
  // Your custom Pino configuration
});

const logger = new Logger({
  transports: [
    new PinoTransport({
      instance: pinoInstance
    })
  ]
});

API Reference

PinoTransportConfig

interface PinoTransportConfig {
  // Optional custom Pino instance
  instance?: pino.Logger;
  
  // Custom serializers
  serializers?: {
    [key: string]: (value: any) => any;
  };
  
  // Pretty printing configuration
  pretty?: boolean | PinoPrettyOptions;
}

interface PinoPrettyOptions {
  colorize?: boolean;
  levelFirst?: boolean;
  translateTime?: boolean | string;
  ignore?: string;
  messageKey?: string;
  customPrettifiers?: Record<string, (input: any) => string>;
}

Log Level Mapping

VevKit Saga levels are mapped to Pino levels as follows:

Saga LevelPino Level
criticalfatal
errorerror
warningwarn
infoinfo
debugdebug
tracetrace

License

MIT

0.1.0

8 months ago