Logger

Radiant includes a highly optimized, Pino-based structured logger out of the box. It automatically formats logs for development environments and switches to fast JSON logging for production. Additionally, it seamlessly integrates with Radiant's KV storage to automatically persist application errors.

Basic Usage

You can import the base logger directly from the radiant package:

import { logger } from "@codesordinatestudio/radiant";

logger.info("Application starting...");
logger.debug({ context: "auth" }, "User session verified");
logger.warn("Rate limit approaching for IP 192.168.1.1");

Creating Component Loggers

For better traceability, you can create child loggers bound to specific components or features:

import { createLogger } from "@codesordinatestudio/radiant";

const dbLogger = createLogger("database");
const authLogger = createLogger("auth");

dbLogger.info("Connection pool established");
// Outputs: {"level":30,"time":1704067200000,"component":"database","msg":"Connection pool established"}

Error KV Storage

Radiant's logger includes an integrated error capture mechanism. If enabled, any .error() logs are automatically written to a dedicated RadiantKV store for later querying and analysis.

Enabling Error Storage

Set the environment variable:

LUCENT_ERROR_LOG_KV=true

When enabled, error logs are written to an isolated SQLite KV store (./data/radiant-error-kv.sqlite).

Retrieving Error Logs

You can retrieve the captured errors using the RadiantErrorLogs class:

import { RadiantErrorLogs } from "@codesordinatestudio/radiant";

// Get the latest 100 error logs
const recentErrors = await RadiantErrorLogs.get({ limit: 100 });

console.log(recentErrors);
/*
[
  {
    key: "error:1704067200000:abc123xyz",
    timestamp: 1704067200000,
    level: "error",
    message: "Failed to connect to database",
    error: "ConnectionRefused: ...",
    stack: "Error: ConnectionRefused\n  at ..."
  }
]
*/

// Count total stored errors
const count = await RadiantErrorLogs.count();

// Clear the error logs
await RadiantErrorLogs.clear();

Configuration

Control the logger via environment variables:

  • LUCENT_LOG_LEVEL or LOG_LEVEL: Set the minimum log level (trace, debug, info, warn, error, fatal). Default is info (silent during tests).
  • LUCENT_ERROR_LOG_KV: Set to true to enable saving .error() output to KV storage.