> ## Documentation Index
> Fetch the complete documentation index at: https://docs.latwoodtech.com/llms.txt
> Use this file to discover all available pages before exploring further.

# @adrper79-dot/logger

> Structured JSON logger for Cloudflare Workers.

# @adrper79-dot/logger

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

## Installation

```bash theme={null}
npm install @adrper79-dot/logger
```

## API

### `createLogger(opts)`

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

### `Logger`

```typescript theme={null}
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.

```typescript theme={null}
const requestLogger = logger.child({ requestId: c.req.header('x-request-id') });
requestLogger.info('Request received', { path: c.req.path });
```

## Example

```typescript theme={null}
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"}
```
