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

@unidev-hub/logger

v1.0.2

Published

Reusable logging module for microservices

Readme

@unidev-hub/logger

A standardized logging package for TypeScript microservices, built on top of Pino.

Features

  • 🚀 High-performance logging using Pino
  • 🔍 Request ID tracking for service correlation
  • 🌐 Express middleware for request/response logging
  • 🛡️ Consistent error logging format
  • 🧩 Contextual child loggers

Installation

npm install @unidev-hub/logger

Usage

Basic Usage

import { createLogger } from '@unidev-hub/logger';

const logger = createLogger({
  serviceName: 'user-service',
  level: 'info',
  prettyPrint: process.env.NODE_ENV === 'development'
});

logger.info('Server started', { port: 3000 });
logger.error('Failed to connect to database', new Error('Connection timeout'));
// Or with additional context
logger.error('Failed to connect to database', new Error('Connection timeout'), { host: 'db-server-1' });

With Express

import express from 'express';
import { createLogger, createRequestLogger, getRequestLogger } from '@unidev-hub/logger';

const app = express();
const logger = createLogger({ serviceName: 'api-gateway' });

// Apply middleware
app.use(createRequestLogger(logger, {
  getUserId: (req) => req.user?.id,
  skipPaths: ['/health', '/metrics']
}));

// Use in route handlers
app.get('/users', (req, res) => {
  const requestLogger = getRequestLogger(req);
  
  requestLogger.info('Fetching users');
  
  // Your logic here
  
  res.json({ users: [] });
});

app.listen(3000, () => {
  logger.info('Server started', { port: 3000 });
});

Error Logging

// With Error object
logger.error('Failed to connect to database', new Error('Connection timeout'));

// With context object
logger.error('User validation failed', { userId: '123', reason: 'Invalid email' });

// With both Error and additional context
logger.error('Payment processing failed', new Error('Gateway timeout'), { orderId: 'ORD-123' });

Child Loggers

function processOrder(orderId: string, userId: string) {
  const orderLogger = logger.child({ orderId, userId });
  
  orderLogger.info('Processing order');
  
  // All logs from this logger will include orderId and userId
  orderLogger.debug('Validating payment');
  orderLogger.info('Order processed successfully');
}

Configuration

The logger accepts the following configuration options:

| Option | Type | Description | Default | |--------|------|-------------|---------| | serviceName | string | Name of the service | Required | | level | string | Minimum log level | 'info' or LOG_LEVEL env var | | prettyPrint | boolean | Format logs for human readability | true in development | | environment | string | Environment name | NODE_ENV or 'development' | | additionalFields | object | Extra fields to add to all logs | {} |

Request Logger Middleware Options

| Option | Type | Description | Default | |--------|------|-------------|---------| | getUserId | Function | Extract user ID from request | undefined | | logRequestBody | boolean | Include request body in logs | false | | logResponseBody | boolean | Include response body in logs | false | | skipPaths | string[] | Paths to exclude from logging | [] |

Best Practices

  1. Use child loggers to add context to related log entries
  2. Include error objects in error logs for stack traces
  3. Use appropriate log levels:
    • trace: Very detailed debugging
    • debug: Debugging information
    • info: Normal operations
    • warn: Warning conditions
    • error: Error conditions
    • fatal: Critical failures

License

MIT