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

@blue.ts/logging

v0.2.3

Published

Structured logging for blue.ts. Pino-compatible JSON output with child loggers, pluggable transports, and per-request scoped context via the DI container.

Downloads

623

Readme

@blue.ts/logging

Structured logging for blue.ts. Pino-compatible JSON output with child loggers, pluggable transports, and per-request scoped context via the DI container.

Installation

bun add @blue.ts/logging

Quick Start

import { LoggingModule, ConsoleTransport } from '@blue.ts/logging';

app.registerProvider(
    new LoggingModule({
        transports: [new ConsoleTransport()],
        level: 'info',
        fields: { service: 'api', version: '1.0.0' },
    })
);

Logger

Logger writes structured JSON entries across six severity levels.

import { Logger, ConsoleTransport } from '@blue.ts/logging';

const logger = new Logger({
    transports: [new ConsoleTransport()],
    level: 'info',             // minimum level to emit (default: 'info')
    fields: { service: 'api' } // merged into every entry
});

logger.trace('Verbose detail');
logger.debug('Debug info');
logger.info('Server started', { port: 3000 });
logger.warn('Slow query', { durationMs: 320, query: 'SELECT ...' });
logger.error('Request failed', { error: err.message });
logger.fatal('Unrecoverable error');

Log levels (lowest → highest)

| Level | Numeric | Use | |-------|---------|-----| | trace | 10 | Highly verbose debugging | | debug | 20 | Development debugging | | info | 30 | Normal operational events | | warn | 40 | Unexpected but recoverable | | error | 50 | Failures that need attention | | fatal | 60 | Process-ending errors |

Child loggers

Child loggers inherit parent transports, level, and fields — and merge in their own:

const reqLogger = logger.child({ reqId: crypto.randomUUID(), userId: 'u123' });
reqLogger.info('Processing request');
// → { "level": 30, "msg": "Processing request", "service": "api", "reqId": "...", "userId": "u123" }

LoggingModule

LoggingModule is a ConfigProvider that wires the logger into the DI container.

It registers two tokens:

| Token | Lifetime | Description | |-------|----------|-------------| | LoggerToken | singleton | Root logger — same instance for the process lifetime | | RequestLoggerToken | scoped | Child logger with a unique reqId per request |

import { LoggingModule, ConsoleTransport, LoggerToken, RequestLoggerToken } from '@blue.ts/logging';
import type { ILogger } from '@blue.ts/logging';

app.registerProvider(
    new LoggingModule({
        transports: [new ConsoleTransport()],
        level: 'debug',
        fields: { service: 'my-api', env: process.env.NODE_ENV },
    })
);

// Inject into a class-based handler
class MyHandler {
    constructor(private readonly log: ILogger) {}

    handle(ctx) {
        this.log.info('Handling request', { path: ctx.req.url });
        return Context.json({ ok: true });
    }
}

app.registerDependency(MyHandler, {
    lifetime: 'transient',
    factory: async (c) => new MyHandler(await c.get(RequestLoggerToken)),
});

Transports

ConsoleTransport

Writes JSON entries to stdout. Best for development and containerised deployments.

import { ConsoleTransport } from '@blue.ts/logging';

new ConsoleTransport()
// → {"level":30,"time":1712345678901,"pid":12345,"hostname":"host","msg":"..."}

FileTransport

Appends newline-delimited JSON to a file. Rotates when the file exceeds maxBytes.

import { FileTransport } from '@blue.ts/logging';

new FileTransport({
    path: './logs/app.log',
    maxBytes: 10 * 1024 * 1024, // 10 MB — rotate after this size
});

BunWorkerTransport

Offloads all I/O to a Bun Worker thread so the main thread is never blocked.

import { BunWorkerTransport } from '@blue.ts/logging';

const transport = new BunWorkerTransport({
    path: './logs/app.log',
    maxBytes: 10 * 1024 * 1024,
});

// At graceful shutdown — flush and close the worker
await transport.flush();
await transport.close();

Multiple transports

new LoggingModule({
    transports: [
        new ConsoleTransport(),
        new BunWorkerTransport({ path: './logs/app.log' }),
    ],
    level: 'info',
});

Custom transport

Implement the Transport interface to write to any backend:

import type { Transport, LogEntry } from '@blue.ts/logging';

class DatadogTransport implements Transport {
    write(entry: LogEntry): void {
        fetch('https://http-intake.logs.datadoghq.com/api/v2/logs', {
            method: 'POST',
            body: JSON.stringify(entry),
            headers: { 'DD-API-KEY': process.env.DD_API_KEY! },
        });
    }

    async flush(): Promise<void> { /* wait for in-flight requests */ }
}

Log Entry Shape

All entries follow the pino JSON format:

{
  "level": 30,
  "time": 1712345678901,
  "pid": 12345,
  "hostname": "api-server-1",
  "msg": "Request completed",
  "service": "api",
  "reqId": "a1b2c3d4",
  "method": "GET",
  "path": "/users",
  "durationMs": 12
}

Compatible with pino-pretty for human-readable local development output:

bun run index.ts | bunx pino-pretty