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

@caregenix/sumo-logger

v1.0.1

Published

A production-ready TypeScript logger for Sumo Logic with request tracking, batching, and improved error handling.

Readme

@caregenix/sumo-logger

A production-ready, TypeScript-first logging library for shipping logs to Sumo Logic HTTP Sources. Optimized for Node.js (18+) and Next.js backends.

🚀 Features

  • High Performance: Built-in batching and buffering to minimize network overhead.
  • Request Tracking: Automatic requestId tracing using AsyncLocalStorage.
  • TypeScript Native: Full typing support for a superior developer experience.
  • Smart Error Handling: Automatically preserves and formats stack traces for Error objects.
  • Isomorphic: Works seamlessly in Node.js, Next.js (API routes & Middleware), and Edge functions.
  • Flexible: Supports both Singleton and Instance-based usage for better testability.

📦 Installation

npm install @caregenix/sumo-logger

🛠️ Usage Guide

1. Initialization (Best Practices)

Is a Singleton right for me? Yes, for most applications, initializing once globally is the correct approach. It ensures all parts of your app share the same connection pool, batching queue, and configuration.

Step A: Create a logger configuration file

Create a file like lib/logger.ts in your project.

import SumoLogger from '@caregenix/sumo-logger';

// Initialize once
SumoLogger.initialize({
  httpSourceUrl: process.env.SUMO_LOGIC_URL!,
  sourceName: 'my-production-app',
  defaultMetadata: {
    env: process.env.NODE_ENV,
    version: '1.0.0'
  },
  batchInterval: 5000, // Batch every 5 seconds
  batchSize: 100,      // Or every 100 logs
});

// Export the instance for use throughout your app
export const logger = SumoLogger.getInstance();

Step B: Use it anywhere

import { logger } from './lib/logger';

logger.info('User logged in', { userId: '123' });

2. Advanced Usage

Request Tracing (Next.js/Node.js Middleware)

To correlate all logs within a single request, wrap your handler:

import { runWithRequestId } from '@caregenix/sumo-logger';
import { logger } from './lib/logger';

export default async function handler(req, res) {
  const requestId = req.headers['x-request-id'] || 'gen-' + Date.now();
  
  return runWithRequestId(requestId, async () => {
    logger.info('Processing API request'); // Will include requestId in Sumo Logic
    // ... logic
  });
}

Error Logging

try {
  throw new Error('Database connection failed');
} catch (err) {
  // Automatically captures error message and stack trace
  logger.error('Critical Error', err);
}

Graceful Shutdown

To ensure pending logs are sent before the process exits:

process.on('SIGTERM', async () => {
  await logger.flush();
  process.exit(0);
});

3. Instance-based Usage (DI)

Useful for unit testing or if you need multiple distinct loggers.

import { SumoLogger, SumoTransport } from '@caregenix/sumo-logger';

const transport = new SumoTransport({ httpSourceUrl: '...' });
const logger = new SumoLogger({ httpSourceUrl: '...' }, transport);

⚙️ Configuration Options

| Option | Type | Default | Description | | :--- | :--- | :--- | :--- | | httpSourceUrl | string | - | Required. Sumo Logic HTTP Source URL. | | sourceName | string | - | X-Sumo-Name header. | | sourceCategory| string | - | X-Sumo-Category header. | | defaultMetadata| object | {} | Metadata included in every log. | | batchInterval | number | 5000 | Batching interval in ms (0 to disable). | | batchSize | number | 100 | Max messages per batch. | | internalLogger| object | console | Logger for internal library health. |


📜 License

MIT