🚀. Socket Launch Week Day 2:Introducing Manifest Alerts.Learn more
Sign In

@edirect/logger

Package Overview
Dependencies
Maintainers
29
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@edirect/logger

Structured logging module for eDirect NestJS applications. Built on top of [Pino](https://github.com/pinojs/pino), providing high-performance JSON logging to stdout/stderr, configurable log levels, and correlation ID tracking (sessionId / quoteId).

npmnpm
Version
11.0.56
Version published
Maintainers
29
Created
Source

@edirect/logger

Structured logging module for eDirect NestJS applications. Built on top of Pino, providing high-performance JSON logging to stdout/stderr, configurable log levels, and correlation ID tracking (sessionId / quoteId).

Features

  • Structured JSON logs with consistent field names (message, level, timestamp, name, version)
  • Outputs to stdout/stderr
  • Configurable log level via environment variable or module options
  • Tracks sessionId and quoteId as correlation context in all log entries
  • Global module — register once, inject LoggerService anywhere
  • Supports both sync (register) and async (registerAsync) configuration

Installation

pnpm add @edirect/logger
# or
npm install @edirect/logger

Usage

Simple registration (static options)

import { Module } from '@nestjs/common';
import { LoggerModule } from '@edirect/logger';

@Module({
  imports: [
    LoggerModule.register({
      output: 'console',
      level: 'info',
      name: 'my-service',
    }),
  ],
})
export class AppModule {}

Async registration (with ConfigService)

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@edirect/config';
import { LoggerModule } from '@edirect/logger';

@Module({
  imports: [
    ConfigModule,
    LoggerModule.registerAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => ({
        level: (configService.get('LOGS_LEVEL') as any) ?? 'info',
        name: configService.get('APP_NAME') ?? 'app',
      }),
      inject: [ConfigService],
    }),
  ],
})
export class AppModule {}

Inject and use LoggerService

import { Injectable } from '@nestjs/common';
import { LoggerService } from '@edirect/logger';

@Injectable()
export class OrderService {
  constructor(private readonly logger: LoggerService) {}

  async processOrder(orderId: string, sessionId: string) {
    this.logger.setSessionId(sessionId);
    this.logger.setQuoteId(orderId);

    this.logger.info('Processing order', JSON.stringify({ orderId }));
    try {
      // business logic...
      this.logger.log('Order processed successfully');
    } catch (err) {
      this.logger.error('Order processing failed', (err as Error).stack ?? '');
    }
  }
}

API

LoggerService methods

MethodSignatureDescription
log(message: string, payload?: string): voidAlias for info
info(message: string, payload?: string): voidLog at INFO level
warn(message: string, payload?: string): voidLog at WARN level
error(message: string, trace: string): voidLog at ERROR level
debug(message: string): voidLog at DEBUG level
verbose(message: string): voidLog at VERBOSE level (maps to INFO internally)
setSessionId(sessionId: string): voidAttach a session ID to all subsequent log entries
setQuoteId(quoteId: string): voidAttach a quote/correlation ID to all subsequent log entries

LoggerModuleOptions

OptionTypeDefaultDescription
levelpino.Level'info'Minimum log level
namestringnpm_package_name | 'app'Service name in every log entry
versionstringnpm_package_version | '0.0.0'Service version in every log entry
hoststring'0.0.0.0'Host tag
protocolstring'http'Protocol tag

Environment Variables

When options are not passed explicitly, the logger reads from environment variables:

VariableDescriptionDefault
LOGS_LEVELLog level (trace, debug, info, warn, error, fatal)info
LOGS_HOSTHost tag in log entries0.0.0.0
LOGS_PROTOCOLProtocol tag in log entrieshttp
APP_NAMEService namenpm_package_name or app
APP_VERSIONService versionnpm_package_version or 0.0.0

Log Output Format

Every log entry is a JSON object:

{
  "level": "info",
  "timestamp": "2024-01-15T10:30:00.000Z",
  "name": "payment-gateway",
  "version": "1.2.3",
  "host": "pod-abc-123",
  "protocol": "http",
  "sessionId": "session-abc-123",
  "quoteId": "quote-xyz-456",
  "remote-address": "",
  "message": "Order created successfully",
  "payload": { "orderId": "ORD-789" }
}

FAQs

Package last updated on 19 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts