JSPM

  • Created
  • Published
  • Downloads 735
  • Score
    100M100P100Q124566F
  • License MIT

Comprehensive logging library optimized for Bun with ElysiaJS integration

Package Exports

    Readme

    @contractspec/lib.logger

    Website: https://contractspec.io/

    High-performance logging library optimized for Bun, with native ElysiaJS integration.

    Purpose

    To provide structured, performant logging with support for request tracing, timing, and varied output formats (JSON/Pretty). It includes a plugin for ElysiaJS to automatically log HTTP requests.

    Installation

    npm install @contractspec/lib.logger
    # or
    bun add @contractspec/lib.logger

    Key Concepts

    • Structured Logging: Logs are JSON objects by default for easy parsing.
    • Context Awareness: Supports AsyncLocalStorage for request-scoped context (Trace IDs).
    • Elysia Plugin: Drop-in middleware for Elysia apps.

    Exports

    • logger: The main logger instance.
    • elysiaPlugin: Middleware for Elysia.
    • timer: Utilities for measuring execution time.
    • tracer: Request tracing utilities.

    Usage

    Basic Logging

    import { logger } from '@contractspec/lib.logger';
    
    logger.info('Server started', { port: 3000 });
    logger.error('Database connection failed', { error: err });

    With Elysia

    import { Elysia } from 'elysia';
    import { elysiaLogger } from '@contractspec/lib.logger/elysia-plugin';
    
    new Elysia()
      .use(elysiaLogger())
      .get('/', () => 'Hello World')
      .listen(3000);