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

logdrive

v1.0.9

Published

πŸš€ Minimal, production-grade Node.js logger with automatic request context tracking.

Readme

logdrive

πŸš€ Minimal, production-grade Node.js logger with automatic request context tracking.

Built for real-world apps β€” structured logs, request tracing, and zero headache setup.


✨ Why logdrive?

  • πŸ”— Automatic request context (requestId, IP, user, etc.)
  • πŸ“¦ Structured JSON logs (ready for Grafana / Loki)
  • ⚑ Zero-config start
  • 🧠 Handles errors, circular objects, deep data safely
  • πŸͺ΅ File rotation built-in

πŸ“¦ Install

npm install logdrive

πŸš€ Quick Example (Real-World Express App)

import express from 'express'
import {
  initLogger,
  requestContextMiddleware,
  Log,
  getContext
} from 'logdrive'

const app = express()

// MUST be first
app.use(requestContextMiddleware)

// Attach user to logs
app.use((req, _res, next) => {
  const ctx = getContext()
  if (ctx) {
    ctx.userId = req.headers['x-user-id'] as string
  }
  next()
})

// Initialize logger once
initLogger({
  defaultMeta: { service: 'user-service' },
  logDir: 'logs',
  enableConsole: true
})

app.get('/users', (_req, res) => {
  Log.info('fetch users', { success: true }, 'USR_2001')
  res.json({ ok: true })
})

app.listen(3000, () => {
  Log.notice('server started', { port: 3000 }, 'SRV_0001')
})

🧠 What You Get in Logs (Auto Context)

{
  "message": "fetch users",
  "requestId": "abc-123",
  "ip": "127.0.0.1",
  "method": "GET",
  "url": "/users",
  "userId": "u_42"
}

πŸ“š All Imports

import {
  initLogger,
  Log,
  requestContextMiddleware,
  getContext,
  contextStore
} from 'logdrive'

βš™οΈ initLogger(config)

initLogger({
  logLevel: 'debug',
  logDir: 'logs',
  maxSize: '20m',
  maxFiles: '1d',
  enableConsole: true,
  defaultMeta: { service: 'api' }
})

Config Options

| Field | Default | Description | | ------------- | --------- | ------------------------- | | logLevel | debug | Logging level | | logDir | logs | Log folder | | maxSize | 20m | File size before rotation | | maxFiles | 1d | Retention | | enableConsole | env-based | Console logs toggle | | defaultMeta | {} | Added to every log |


🧾 Logging API

Log.error('DB failed', new Error('timeout'), 'DB_5001')
Log.warning('Slow query', { ms: 800 }, 'PERF_1001')
Log.notice('Job started', { job: 'sync' }, 'JOB_0001')
Log.info('User login', { userId: 'u1' }, 'AUTH_2001')
Log.debug('Payload', { data: {} }, 'DBG_0001')

Signature

(message: string, data?: unknown, code?: string | number)

πŸ”— requestContextMiddleware

import { requestContextMiddleware } from 'logdrive'

app.use(requestContextMiddleware)

Auto Injected Fields

  • requestId (or generates one)
  • IP address
  • HTTP method
  • URL
  • userAgent

🧠 getContext()

import { getContext } from 'logdrive'

const ctx = getContext()
if (ctx) {
  ctx.userId = 'user_123'
}

Context Shape

interface RequestContext {
  requestId: string
  ip: string
  method: string
  url: string
  userId?: string
  userAgent?: string
}

πŸ§ͺ Advanced: contextStore

import { contextStore, Log } from 'logdrive'

contextStore.run(
  {
    requestId: 'manual-id',
    ip: '127.0.0.1',
    method: 'GET',
    url: '/test'
  },
  () => {
    Log.info('manual context log')
  }
)

⚠️ Important Rules

  1. Use requestContextMiddleware before routes
  2. Call initLogger() before logging
  3. Never log before initialization

If not initialized:

Logger not initialized. Call initLogger() first.

πŸ’₯ Error Handling Example

try {
  throw new Error('DB crashed')
} catch (err) {
  Log.error('critical failure', err, 'SYS_5000')
}

πŸ“ Log File Format

  • JSON logs
  • Rotated daily
  • File format: app-YYYY-MM-DD.log

🧠 Best Use Cases

  • Microservices
  • APIs
  • Backend systems
  • Observability pipelines (Loki / ELK)

πŸ‘¨β€πŸ’» Creator

Pratik Panchal πŸ“§ [email protected] πŸ”— https://github.com/Pratikpanchal25


πŸ“„ License (MIT)

MIT License

Copyright (c) 2026 Pratik Panchal

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:


🌟 Support

If you like this project:

  • ⭐ Star on GitHub
  • πŸ› Report issues
  • πŸ’‘ Suggest features

πŸš€ Roadmap

  • [ ] Express plugin (logdrive.express(app))
  • [ ] Loki direct transport
  • [ ] Log dashboard (SaaS πŸ‘€)
  • [ ] Request tracing UI