JSON log

GitHub

Structured JSON logger with info, error, and elapsed-time helpers.

Installation

bash
pnpm dlx shadcn@latest add @cs/jsonlog

Usage

tsx
import { jsonlog } from "@/lib/cs/jsonlog"
tsx
jsonlog.info("user.create", "User created", { userId: 123 })

API Reference

jsonlog

Writes structured JSON log entries and measures named operations.

Methods

tsx
jsonlog.info(source: string, message: string, data?: unknown): void

Writes an informational structured log entry.

tsx
jsonlog.error(source: string, message: string, data?: unknown): void

Writes an error structured log entry.

tsx
jsonlog.timer(source: string, message: string, data?: object): void

Creates a named operation timer that can record multiple elapsed intervals.