logger parameter accepts a MinimalLogger, so you can pass in either the full Logger class or any compatible object.
Logger
The main logger class. Construct it with an array of sinks.
Logger by passing only sinks:
Logger implements LoggerApi and also satisfies MinimalLogger.
Logger.withSink(sink)
Returns a new Logger that writes to all existing sinks plus the additional sink. The original logger is not modified.
defaultLogger
A pre-built MinimalLogger that writes to console.log / console.warn / console.error with [INFO], [WARN], and [ERROR] prefixes. Used as the fallback when you omit the logger option on any Libretto function.
LoggerApi interface
The full interface implemented by Logger.
Logs an entry at
"log" level.Logs an entry at
"info" level. data can be an Error, { error: Error, ...rest }, or any plain object.Logs an entry at
"warn" level.Logs an entry at
"error" level and returns an Error object. If data is or contains an Error, that error is returned; otherwise a new Error is constructed from event.Returns a new
LoggerApi with an additional scope segment prepended to all log entries. Scope segments are joined with . (e.g. "workflow.network").Returns a new
LoggerApi with additional key-value pairs merged into every log entry’s data.Flushes all sinks in reverse order (most recently added first).
MinimalLogger type
A minimal subset of LoggerApi. Any object with info, warn, and error methods satisfies this type, which is what every Libretto runtime function accepts for its optional logger parameter.
LogOptions
Override the timestamp written to the log entry. Defaults to
new Date() at write time.LoggerSink type
A sink is any object with a write method. Implement this interface to route log output to any destination.
Called for every log entry.
id is a unique random identifier per entry.Optional. Called by
Logger.flush() to ensure buffered entries are written.Optional. Called by
Logger.close() to release resources (e.g. close file handles). Safe to call multiple times — subsequent calls are no-ops.Built-in sinks
createFileLogSink({ filePath })
Writes JSONL (one JSON object per line) to a file. The directory is created automatically if it does not exist. Appends to the file if it already exists.
Absolute or relative path to the log file.
prettyConsoleSink
A pre-built LoggerSink constant that writes human-readable, ANSI-colored output to the console. Timestamps, log levels, scopes, and events are each color-coded. Error stacks are printed on separate lines.
jsonlConsoleSink
A pre-built LoggerSink constant that writes each log entry as a single JSON line to console.log. Useful for log aggregation systems that consume structured output from stdout.
Full example
createLLMClientFromModel()
Creates a Libretto LLMClient from a Vercel AI SDK LanguageModel. While logically an LLM utility, it is included here as a companion to the logger since both are commonly configured together at the top of a workflow file.
A Vercel AI SDK language model instance. The result of calling a provider factory such as
openai("gpt-4o") from @ai-sdk/openai, anthropic("claude-3-5-sonnet-20241022") from @ai-sdk/anthropic, or google("gemini-1.5-pro") from @ai-sdk/google.LLMClient is used by extractFromPage, attemptWithRecovery, executeRecoveryAgent, and detectSubmissionError.