npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@infosel-sdk/logger

v0.1.0

Published

Logger SDK for Infosel financial services platform. Provides structured logging with Pino integration, optimized for Grafana/Loki visualization with service, context, and metadata support.

Readme

@infosel-sdk/logger

Logger SDK for Infosel financial services platform. Provides structured logging functionality powered by Pino for production-grade logging with Grafana integration.

Features

  • Multiple Log Levels: debug, info, warn, error
  • Structured Logging: Service, context, and metadata support
  • Pino Integration: High-performance JSON logging
  • Grafana Ready: Optimized for Loki/Grafana visualization
  • Context Tracking: Track events like login, reconnection, retransmission
  • TypeScript Support: Full type definitions included
  • Dual Output: Pretty print for development, JSON for production
  • Production Ready: Battle-tested logging for production environments

Installation

npm install @infosel-sdk/logger

Or install from a local .tgz file:

npm install ./infosel-sdk-logger-0.0.1.tgz

Usage

Production Usage (with Pino - For Grafana)

import InfoselLogger from '@infosel-sdk/logger';
import { LogLevel } from '@infosel-sdk/logger';

// Initialize logger with Pino for production
const logger = InfoselLogger.createLogger({
  usePino: true,
  prettyPrint: false,  // JSON output for Grafana/Loki
  minLevel: LogLevel.INFO,
  service: 'my-nextjs-app',
});

// Log with structured data
logger.log(LogLevel.INFO, 'User successfully logged in', {
  service: 'auth-service',
  context: 'login',
  metadata: {
    userId: '123',
    method: 'oauth',
    ip: '192.168.1.1'
  }
});

// Output (JSON for Grafana):
// {
//   "level": "INFO",
//   "time": "2024-11-27T10:30:45.123Z",
//   "service": "auth-service",
//   "context": "login",
//   "userId": "123",
//   "method": "oauth",
//   "ip": "192.168.1.1",
//   "msg": "User successfully logged in"
// }

Métodos Convenientes por Nivel

Cada nivel tiene su propio método para facilitar el uso:

const logger = InfoselLogger.createLogger({
  usePino: true,
  prettyPrint: true,  // Pretty print para desarrollo
  minLevel: LogLevel.DEBUG,
  service: 'my-app',
});

// ✅ logger.info() - Información general (más usado)
logger.info('User logged in', { 
  service: 'auth-service',
  context: 'login',
  metadata: { 
    userId: '123',
    email: '[email protected]',
    method: 'oauth'
  }
});

// ✅ logger.warn() - Advertencias (reconexiones, retransmisiones)
logger.warn('WebSocket reconnecting', { 
  service: 'websocket-service',
  context: 'reconnection',
  metadata: { 
    attempt: 1,
    maxAttempts: 5,
    reason: 'network_timeout'
  }
});

// ✅ logger.error() - Errores críticos
logger.error('Database connection failed', { 
  service: 'database-service',
  context: 'connection',
  metadata: { 
    errorMessage: 'Connection timeout',
    errorStack: error.stack,
    host: 'db.prod.com',
    retries: 3
  }
});

// ✅ logger.debug() - Debugging detallado (solo desarrollo)
logger.debug('Cache lookup performed', { 
  service: 'cache-service',
  context: 'cache-lookup',
  metadata: { 
    key: 'user:123',
    hit: true,
    ttl: 3600
  }
});

Configuration Options

interface LoggerConfig {
  minLevel?: LogLevel;          // Minimum log level: 'debug' | 'info' | 'warn' | 'error'
  enableTimestamps?: boolean;   // Include timestamps in logs
  enableColors?: boolean;       // Enable colored console output
  prefix?: string;              // Custom prefix for all log messages
  service?: string;             // Service or module name (e.g., 'auth-service')
  usePino?: boolean;            // Use Pino for logging (recommended for production)
  prettyPrint?: boolean;        // Pretty print output (for development)
  outputFn?: (msg: string) => void; // Custom output function
}

interface LogOptions {
  service?: string;             // Override service name
  context?: string;             // Event context (login, reconnection, etc.)
  metadata?: Record<string, unknown>; // Additional structured data
}

Log Levels

  • DEBUG: Detailed information for debugging
  • INFO: General informational messages
  • WARN: Warning messages for potentially harmful situations
  • ERROR: Error messages for serious problems

Log Structure

Each log includes:

  • Timestamp: ISO 8601 format
  • Level: Log level (INFO, WARN, ERROR, DEBUG)
  • Service: Service or module name
  • Context: Event context (login, reconnection, retransmission, etc.)
  • Message: Clear, descriptive message
  • Metadata: Additional structured data

Common Contexts

  • login: User authentication events
  • logout: User logout events
  • reconnection: WebSocket/connection reconnection attempts
  • retransmission: Message queue retransmission events
  • http-request: API request/response
  • connection: Database/service connections
  • data-fetch: Data fetching operations

Examples

Next.js Integration

See examples/nextjs-integration.ts for complete Next.js examples including:

  • API Routes logging
  • WebSocket reconnection tracking
  • Message queue retransmission
  • Error boundary logging

Log Output Examples

See examples/LOG_OUTPUT_EXAMPLES.md for:

  • JSON output examples (for Grafana)
  • Pretty print examples (for development)
  • Real-world use cases

Grafana Integration

See examples/GRAFANA_INTEGRATION.md for:

  • Docker Compose configuration
  • Loki setup
  • Grafana dashboards
  • LogQL queries
  • Alerts configuration

Building

Run nx build logger to build the library.

Running unit tests

Run nx test logger to execute the unit tests via Jest.

Creating a Package

To create a .tgz file for distribution:

nx build logger
cd dist/packages/logger
npm pack

This will create infosel-sdk-logger-0.0.1.tgz that you can install in other projects.

Documentation

License

MIT