Durable.LogCapture (Durable v0.1.0-rc)
View SourceCaptures Logger output and IO operations during workflow step execution.
Uses process dictionary key :durable_logs for buffering log entries.
Optionally replaces group_leader for IO.puts/IO.inspect capture.
Usage
This module is used internally by Durable.Executor.StepRunner to capture
logs during step execution:
Durable.LogCapture.start_capture()
# Step execution happens here - Logger calls are captured
Logger.info("Processing order")
IO.puts("Debug output")
logs = Durable.LogCapture.stop_capture()
# => [%{timestamp: ..., level: "info", message: "Processing order", ...}, ...]Configuration
config :durable,
log_capture: [
enabled: true,
levels: [:debug, :info, :warning, :error],
io_capture: true,
io_passthrough: false,
max_log_entries: 1000,
max_message_length: 10_000,
metadata_filter: [:request_id, :user_id, :module, :function, :line]
]
Summary
Functions
Adds an IO output entry to the log buffer.
Adds a log entry to the buffer.
Clears the log buffer.
Returns the current log buffer contents.
Checks if the current process is executing within a workflow context.
Starts log capture for the current process.
Stops log capture and returns the captured logs.
Functions
@spec add_io_log(String.t()) :: :ok
Adds an IO output entry to the log buffer.
Called when processing IO log messages from the IO server.
Adds a log entry to the buffer.
Called by the Logger handler when a log event occurs in workflow context.
Respects the max_log_entries configuration limit.
Parameters
level- The log level atom (:debug, :info, :warning, :error)message- The log message stringmetadata- Metadata map from the Logger event
@spec clear_logs() :: :ok
Clears the log buffer.
@spec get_logs() :: [map()]
Returns the current log buffer contents.
Logs are returned in chronological order (oldest first).
@spec in_workflow_context?() :: boolean()
Checks if the current process is executing within a workflow context.
Returns true if :durable_workflow_id is set in the process dictionary,
indicating that log capture should be active.
@spec start_capture() :: :ok
Starts log capture for the current process.
Initializes the log buffer in the process dictionary and optionally starts IO capture by replacing the group_leader.
This should be called before step execution begins.
@spec stop_capture() :: [map()]
Stops log capture and returns the captured logs.
Restores the original group_leader if IO capture was active, stops the IO server process, and returns the formatted logs.
Returns an empty list if capture was not started or is disabled.