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

@johnboxcodes/boxlogger

v0.3.3

Published

Lightweight, Sentry-compatible backend logger with pluggable storage providers (SQLite, Memory) for Node.js

Downloads

33

Readme

boxlogger

A lightweight, Sentry-compatible backend logger with pluggable storage providers for Node.js applications.

Features

  • Pluggable Storage - Memory, Console, or custom providers
  • Sentry-Compatible API - Drop-in replacement for common Sentry functions
  • Browser Compatible - Console and Memory providers work in Next.js client components
  • Session Tracking - Track user sessions with crash detection
  • Transaction Support - Performance monitoring with custom measurements
  • Breadcrumbs - Event trail for debugging
  • Scoped Context - Isolated logging contexts with tags and metadata
  • Fully Tested - Comprehensive test coverage

Installation

npm install @johnboxcodes/boxlogger

No additional dependencies required!

Quick Start

import * as Sentry from '@johnboxcodes/boxlogger';

// Initialize with Console (great for development!)
await Sentry.init('console', { 
  service: 'my-api',
  environment: 'development'
});

// Capture errors
try {
  await riskyOperation();
} catch (error) {
  Sentry.captureException(error, {
    tags: { section: 'payment' },
    extra: { userId: '123' }
  });
}

// Log messages
Sentry.captureMessage('Payment processed', 'info');

// Set user context
Sentry.setUser({ id: '123', email: '[email protected]' });

// Add breadcrumbs
Sentry.addBreadcrumb({
  category: 'navigation',
  message: 'User navigated to checkout',
  level: 'info'
});

Storage Providers

Console (Development/Debugging)

Logs everything to console with beautiful colorful formatting. Perfect for development and debugging.

await Sentry.init('console', {
  service: 'my-service',
  environment: 'development',
  minLevel: 'debug'
});
import * as Sentry from '@johnboxcodes/boxlogger';

  filename: './logs.db',
  service: 'my-service',
  environment: 'production',
  minLevel: 'info'
});

Memory (Testing)

await Sentry.init('memory', {
  service: 'my-service',
  environment: 'development',
  minLevel: 'debug'
});

Custom Provider

import { create } from 'boxlogger';
import { MyCustomStore } from './my-store';

const logger = await create(new MyCustomStore(), {
  service: 'my-service'
});

API Reference

Core Functions

init(provider, options)

Initialize the logger with a storage provider.

  filename: './logs.db',
  service: 'my-api',
  environment: 'production',
  release: '1.0.0',
  minLevel: 'info',
  ignoreErrors: [/NetworkError/],
  sampleRate: 1.0,
  beforeSend: (event) => event
});

captureException(error, context?)

Capture and log exceptions with optional context.

Sentry.captureException(error, {
  tags: { section: 'api' },
  extra: { endpoint: '/users' },
  level: 'error',
  user: { id: '123' }
});

captureMessage(message, level?)

Log custom messages.

Sentry.captureMessage('User action completed', 'info');
Sentry.captureMessage('Warning: High memory usage', {
  level: 'warning',
  tags: { component: 'memory-monitor' }
});

setUser(user)

Set user context for all subsequent logs.

Sentry.setUser({
  id: '123',
  email: '[email protected]',
  username: 'john_doe',
  ip_address: '{{auto}}'
});

addBreadcrumb(breadcrumb)

Add breadcrumb for event trail.

Sentry.addBreadcrumb({
  category: 'http',
  message: 'API request',
  level: 'info',
  data: { url: '/api/users', method: 'GET' }
});

withScope(callback)

Execute code with isolated logging context.

Sentry.withScope((scope) => {
  scope.setTag('transaction', 'payment');
  scope.setExtra('orderId', '12345');
  Sentry.captureException(error);
});

Session Management

// Start session
await Sentry.startSession({ user: { id: '123' } });

// End session
await Sentry.endSession('ended');

// Get current session
const session = Sentry.getCurrentSession();

Transaction Tracking

const transaction = Sentry.startTransaction({
  name: 'payment-processing',
  op: 'payment'
});

transaction.setTag('payment-method', 'credit-card');
transaction.setMeasurement('amount', 99.99, 'usd');
transaction.setStatus('ok');
transaction.finish();

Query Logs

// Get logs with filters
const logs = await Sentry.getLogs({
  level: 'error',
  startTime: new Date('2024-01-01'),
  limit: 100
});

// Get sessions
const sessions = await Sentry.getSessions({
  status: 'crashed'
});

// Get statistics
const stats = await Sentry.getStats();

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | service | string | - | Service name | | environment | string | 'production' | Environment (production, development, etc.) | | release | string | - | Release version | | minLevel | LogLevel | 'info' | Minimum log level | | ignoreErrors | (string\|RegExp)[] | [] | Errors to ignore | | sampleRate | number | 1.0 | Error sampling rate (0-1) | | messagesSampleRate | number | 1.0 | Message sampling rate (0-1) | | beforeSend | function | - | Hook to modify/filter events | | beforeSendMessage | function | - | Hook to modify/filter messages |

Next.js Integration

Perfect for development! Use boxlogger locally and Sentry in production with the same API.

Development + Production Setup

// sentry.server.config.ts
import * as Sentry from '@sentry/nextjs';

if (process.env.NODE_ENV === 'development') {
  // Development: Use boxlogger with colorful console output
  const boxlogger = await import('@johnboxcodes/boxlogger');
  await boxlogger.init('console', {
    service: 'my-app',
    environment: 'development',
    minLevel: 'debug',
  });
  Object.assign(Sentry, boxlogger);
} else {
  // Production: Use real Sentry
  Sentry.init({
    dsn: process.env.SENTRY_DSN,
    tracesSampleRate: 0.1,
  });
}

Benefits

Development:

  • Beautiful colorful console output
  • No Sentry quota usage
  • Works offline
  • Instant feedback

Production:

  • Full Sentry features (alerts, dashboards, replays)
  • Error aggregation and monitoring
  • Same API - just change NODE_ENV!

See examples/nextjs-integration.tsx for complete setup including Edge runtime and client components.

Examples

See the examples directory for complete examples:

License

MIT

Author

johnbox codes