Skip to content

API reference

log(options) creates a named Layeron log stream.

Terminal window
import { log } from "@layeron/modules"

Create a Layeron log module.

Terminal window
log(options: LogModuleOptions): LogModule

Retention policy for a named log stream.

FieldTypeDescription
modeLogRetentionMode | undefinedRetention mode. Omit to use worker_logs.
daysint32 | undefinedArchive retention in days. Applies when mode is archive.

Cloudflare Workers Logs native options for a named log stream.

FieldTypeDescription
headSamplingRatefloat64 | undefinedCloudflare Workers Logs head-based sampling rate. Value must be from 0 to 1.

Sampling policy for a named log stream.

FieldTypeDescription
successfloat64 | undefinedSampling rate for non-error log records. Value must be from 0 to 1.
errorfloat64 | undefinedSampling rate for error and fatal records. Value must be from 0 to 1.

Automatic capture switches for a named log stream.

FieldTypeDescription
errorsboolean | undefinedCapture errors through the stream.
requestboolean | undefinedAttach request identity to runtime records.
durationboolean | undefinedAttach duration fields to runtime records.

Options accepted by log(options).

FieldTypeDescription
namestringStable log stream name inside the Layeron app.
namespacestringPlatform namespace for the instance. Defaults to default.
levelLogLevel | undefinedMinimum level emitted by this stream. Omit to use info.
samplingLogSamplingOptions | undefinedSampling policy for this stream.
redactionLayeron.Observability.RedactionPolicy | undefinedRedaction policy applied before attributes are emitted.
captureLogCaptureOptions | undefinedAutomatic capture switches for this stream.
retentionLogRetentionOptions | undefinedRetention policy for this stream.
workerLogsLogWorkerLogsOptions | undefinedCloudflare Workers Logs native options.
sinkLogSink | undefinedRuntime sink. The first supported sink is worker_logs.

Layeron log module returned by log(options).

FieldTypeDescription
name”log”Module name.
configLogModuleOptionsNormalized module configuration.
observabilityLayeron.Observability.ObservabilityConfig | undefinedEffective observability policy recorded on the module declaration.

Retention mode for a named log stream.

ValueDescription
worker_logsUse Cloudflare Workers Logs short-term retention only.
archiveArchive structured log records to Layeron-managed R2 storage.

Log level accepted by log(options).

ValueDescription
debugDiagnostic details used during development or deep troubleshooting.
infoInformational runtime events.
warnUnexpected conditions that allow the request or task to continue.
errorFailures that affect one operation.
fatalSevere failures that can make the runtime or product unhealthy.

Sink used by the log module.

ValueDescription
worker_logsEmit structured records through Cloudflare Worker Logs.

Emit an informational log record.

Terminal window
logInfo(message: string, attributes?: unknown): void

Emit an error log record.

Terminal window
logError(message: string, attributes?: unknown): void

Capture an error object through the log stream.

Terminal window
logCapture(error: unknown, attributes?: unknown): void
MethodDescription
event()Emit a named log event.