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

@x-developer/unified-logger

v1.0.15

Published

Unified logging SDK for Node.js services with Winston, supporting Console, Papertrail, and UDP transports

Downloads

320

Readme

Implementation Guide - Unified Logger (@x-developer/unified-logger)

A comprehensive guide for developers to implement and integrate the unified logger into their Node.js applications.

📚 Table of Contents

  1. Quick Start
  2. Installation Methods
  3. Configuration Setup
  4. Papertrail Integration
  5. Express/Fastify Integration
  6. Environment Variables
  7. TypeScript Setup
  8. UDP Relay Transport
  9. Production Deployment
  10. Troubleshooting
  11. Examples

🚀 Quick Start

1. Install the Package

npm install @x-developer/unified-logger

2. Create Configuration File

Create logger.json in your project root:

{
  "service": "your-service-name",
  "env": "development",
  "level": "DEBUG",
  "transports": {
    "console": { "enabled": true },
    "papertrail": {
      "enabled": false,
      "host": "logs.papertrailapp.com",
      "port": 12345,
      "program": "your-service"
    },
    "udpRelay": {
      "enabled": false,
      "host": "127.0.0.1",
      "port": 9999,
      "maxPacketBytes": 1400
    }
  },
  "sampling": { "debug": 1.0, "info": 1.0 },
  "redact": {
    "headers": ["authorization", "cookie"],
    "queryParams": ["password", "token"]
  }
}

3. Initialize in Your Application

import { initLogger, logger } from "@x-developer/unified-logger";

// Initialize once at application start
initLogger("./logger.json");

// Use anywhere in your application
logger.info("Application started");
logger.error("Error occurred", { userId: 123, action: "login" });

📦 Installation Methods

Node.js Version Requirements

  • Minimum: Node.js v18.0.0
  • Recommended: Node.js v22.x.x (LTS)
  • ESM Support: Full ES module support

Package Manager Options

# NPM
npm install @x-developer/unified-logger

# Yarn
yarn add @x-developer/unified-logger

# PNPM
pnpm add @x-developer/unified-logger

Package Configuration

For ESM (recommended):

{
  "type": "module",
  "dependencies": {
    "@x-developer/unified-logger": "^1.0.10"
  }
}

For CommonJS:

{
  "dependencies": {
    "@x-developer/unified-logger": "^1.0.10"
  }
}

⚙️ Configuration Setup

Basic Configuration

{
  "service": "my-api",
  "env": "production",
  "level": "INFO",
  "transports": {
    "console": { "enabled": true },
    "papertrail": { "enabled": false },
    "udpRelay": { "enabled": false, "host": "", "port": 0 }
  }
}

Advanced Configuration

{
  "service": "my-api",
  "env": "production",
  "level": "INFO",
  "transports": {
    "console": { "enabled": true, "colorize": true },
    "papertrail": {
      "enabled": true,
      "host": "logs.collector.eu-01.cloud.solarwinds.com",
      "port": 443,
      "program": "my-api-prod",
      "disableTlsVerify": false
    },
    "udpRelay": {
      "enabled": true,
      "host": "log-relay.internal",
      "port": 5140,
      "maxPacketBytes": 65000
    }
  },
  "sampling": { "debug": 0.1, "info": 0.5 },
  "redact": {
    "headers": ["authorization", "cookie", "x-api-key"],
    "queryParams": ["password", "token", "secret"],
    "bodyKeys": ["creditCard", "ssn"]
  },
  "correlation": { "enabled": true, "header": "X-Request-ID" }
}

📄 Papertrail Integration

  1. Login to Papertrail and get host/port/program
  2. Configure the papertrail transport
  3. Optionally set PAPERTRAIL_TOKEN for HTTP transport auth

🌐 Express/Fastify Integration

Express:

import express from "express";
import {
  initLogger,
  logger,
  createRequestLogger,
  createCorrelationId,
} from "@x-developer/unified-logger";

initLogger("./logger.json");
const app = express();
app.use(createCorrelationId());
app.use(createRequestLogger());

Fastify:

import fastify from "fastify";
import {
  initLogger,
  logger,
  createRequestLoggerHook,
  createCorrelationIdHook,
} from "@x-developer/unified-logger";

initLogger("./logger.json");
const server = fastify();
server.addHook("onRequest", createCorrelationIdHook());
server.addHook("onRequest", createRequestLoggerHook());

🌍 Environment Variables

Key overrides:

LOG_LEVEL=INFO
LOG_TRANSPORTS_CONSOLE_ENABLED=true
LOG_TRANSPORTS_PAPERTRAIL_ENABLED=true
LOG_SAMPLING_DEBUG=0.1
LOG_SAMPLING_INFO=0.5
LOG_REDACT_HEADERS=authorization,cookie
LOG_REDACT_QUERYPARAMS=password,token

Note: WARN and ERROR levels are always logged (100% sampling) regardless of configuration.


📘 TypeScript Setup

tsconfig.json essentials:

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "strict": true,
    "skipLibCheck": true
  }
}

Type-safe config example:

import { ILoggerConfig, LogLevel } from "@x-developer/unified-logger";
const config: ILoggerConfig = {
  service: "my-api",
  env: "production",
  level: "INFO" as LogLevel,
  transports: {
    console: { enabled: true },
    papertrail: {
      enabled: true,
      host: "logs.papertrailapp.com",
      port: 12345,
      program: "my-api",
    },
    udpRelay: { enabled: false, host: "", port: 0 },
  },
  sampling: { verbose: 0.05, debug: 0.1, info: 1.0 },
  redact: { headers: ["authorization"], queryParams: ["token"] },
};

🔌 UDP Relay Transport

Fire-and-forget UDP logging for low-latency pipelines.

  • maxPacketBytes: configurable (default 65000)
  • Oversized messages are truncated
  • Internal counters: sent, dropped, errors

Example:

{
  "transports": {
    "udpRelay": {
      "enabled": true,
      "host": "log-relay.internal",
      "port": 5140,
      "maxPacketBytes": 65000
    }
  }
}

🚀 Production Deployment

Dockerfile, compose, and Kubernetes examples provided. Expose /metrics for Prometheus.


🔧 Troubleshooting

Common issues and fixes for module resolution, ESM/CJS, Papertrail connectivity, and TypeScript.


📋 Examples

See examples/ and TEST/ for end-to-end usage and ready-to-run setups.


📚 Documentation & Resources

  • Complete Guide (Simple): SIMPLE_COMPLETE_GUIDE.md
  • Auto-Correlation ID Guide: AUTO_CORRELATION_GUIDE.md
  • Developer Checklist: DEVELOPER_CHECKLIST.md
  • Quick Reference: QUICK_REFERENCE.md
  • API/Integration/Env/Deployment under docs/

Happy Logging! 🪵