API reference
log(options) creates a named Layeron log stream.
Import
Section titled “Import”import { log } from "@layeron/modules"Create a Layeron log module.
log(options: LogModuleOptions): LogModuleLogRetentionOptions
Section titled “LogRetentionOptions”Retention policy for a named log stream.
| Field | Type | Description |
|---|---|---|
mode | LogRetentionMode | undefined | Retention mode. Omit to use worker_logs. |
days | int32 | undefined | Archive retention in days. Applies when mode is archive. |
LogWorkerLogsOptions
Section titled “LogWorkerLogsOptions”Cloudflare Workers Logs native options for a named log stream.
| Field | Type | Description |
|---|---|---|
headSamplingRate | float64 | undefined | Cloudflare Workers Logs head-based sampling rate. Value must be from 0 to 1. |
LogSamplingOptions
Section titled “LogSamplingOptions”Sampling policy for a named log stream.
| Field | Type | Description |
|---|---|---|
success | float64 | undefined | Sampling rate for non-error log records. Value must be from 0 to 1. |
error | float64 | undefined | Sampling rate for error and fatal records. Value must be from 0 to 1. |
LogCaptureOptions
Section titled “LogCaptureOptions”Automatic capture switches for a named log stream.
| Field | Type | Description |
|---|---|---|
errors | boolean | undefined | Capture errors through the stream. |
request | boolean | undefined | Attach request identity to runtime records. |
duration | boolean | undefined | Attach duration fields to runtime records. |
LogModuleOptions
Section titled “LogModuleOptions”Options accepted by log(options).
| Field | Type | Description |
|---|---|---|
name | string | Stable log stream name inside the Layeron app. |
namespace | string | Platform namespace for the instance. Defaults to default. |
level | LogLevel | undefined | Minimum level emitted by this stream. Omit to use info. |
sampling | LogSamplingOptions | undefined | Sampling policy for this stream. |
redaction | Layeron.Observability.RedactionPolicy | undefined | Redaction policy applied before attributes are emitted. |
capture | LogCaptureOptions | undefined | Automatic capture switches for this stream. |
retention | LogRetentionOptions | undefined | Retention policy for this stream. |
workerLogs | LogWorkerLogsOptions | undefined | Cloudflare Workers Logs native options. |
sink | LogSink | undefined | Runtime sink. The first supported sink is worker_logs. |
LogModule
Section titled “LogModule”Layeron log module returned by log(options).
| Field | Type | Description |
|---|---|---|
name | ”log” | Module name. |
config | LogModuleOptions | Normalized module configuration. |
observability | Layeron.Observability.ObservabilityConfig | undefined | Effective observability policy recorded on the module declaration. |
LogRetentionMode
Section titled “LogRetentionMode”Retention mode for a named log stream.
| Value | Description |
|---|---|
worker_logs | Use Cloudflare Workers Logs short-term retention only. |
archive | Archive structured log records to Layeron-managed R2 storage. |
LogLevel
Section titled “LogLevel”Log level accepted by log(options).
| Value | Description |
|---|---|
debug | Diagnostic details used during development or deep troubleshooting. |
info | Informational runtime events. |
warn | Unexpected conditions that allow the request or task to continue. |
error | Failures that affect one operation. |
fatal | Severe failures that can make the runtime or product unhealthy. |
LogSink
Section titled “LogSink”Sink used by the log module.
| Value | Description |
|---|---|
worker_logs | Emit structured records through Cloudflare Worker Logs. |
Operations
Section titled “Operations”logInfo
Section titled “logInfo”Emit an informational log record.
logInfo(message: string, attributes?: unknown): voidlogError
Section titled “logError”Emit an error log record.
logError(message: string, attributes?: unknown): voidlogCapture
Section titled “logCapture”Capture an error object through the log stream.
logCapture(error: unknown, attributes?: unknown): voidTypeScript module methods
Section titled “TypeScript module methods”| Method | Description |
|---|---|
event() | Emit a named log event. |