Skip to main content

@adrper79-dot/logger

Structured JSON logger with levels, context binding, and child loggers. Depends on @adrper79-dot/errors and @adrper79-dot/monitoring.

Installation

npm install @adrper79-dot/logger

API

createLogger(opts)

function createLogger(opts: {
  service: string;
  level?: 'debug' | 'info' | 'warn' | 'error';
  context?: Record<string, unknown>;
}): Logger;

Logger

interface Logger {
  debug(message: string, context?: Record<string, unknown>): void;
  info(message: string, context?: Record<string, unknown>): void;
  warn(message: string, context?: Record<string, unknown>): void;
  error(message: string, context?: Record<string, unknown>): void;
  child(context: Record<string, unknown>): Logger;
}
All log methods emit a JSON line to console.log — Cloudflare Workers streams this to Logpush.

child(context)

Creates a child logger that inherits the parent’s service and merges in additional context fields.
const requestLogger = logger.child({ requestId: c.req.header('x-request-id') });
requestLogger.info('Request received', { path: c.req.path });

Example

import { createLogger } from '@adrper79-dot/logger';

const logger = createLogger({ service: 'my-app', level: 'info' });

logger.info('User signed in', { userId: 'user-123', tenantId: 'tenant-1' });
// {"level":"info","service":"my-app","message":"User signed in","userId":"user-123","tenantId":"tenant-1","ts":"2026-04-25T00:00:00.000Z"}