Durable.LogCapture.Handler (Durable v0.1.0-rc)
View SourceLogger handler for capturing workflow step logs.
Implements the Erlang :logger handler behavior (OTP 21+, Elixir 1.15+).
This handler intercepts log events and routes them to the process dictionary
buffer when the current process is executing a workflow step.
Handler Registration
The handler is registered at application startup:
# In Durable.Application.start/2
:ok = Durable.LogCapture.Handler.attach()How It Works
- When a log event occurs, the
log/2callback is invoked - The handler checks if
:durable_workflow_idis set in the process dictionary - If in workflow context, the log is added to the
:durable_logsbuffer - If not in workflow context, the log is ignored (passes through to other handlers)
This design ensures:
- No impact on logging outside of workflow execution
- Each step's logs are captured in isolation
- Concurrent workflow executions don't interfere with each other
Summary
Functions
Attaches the log capture handler to the Logger.
Returns whether the handler is currently attached.
Detaches the log capture handler from the Logger.
Functions
@spec attach() :: :ok | {:error, term()}
Attaches the log capture handler to the Logger.
Called from the application's start callback during application startup.
Returns :ok on success.
If the handler is already attached, this is a no-op.
@spec attached?() :: boolean()
Returns whether the handler is currently attached.
@spec detach() :: :ok | {:error, term()}
Detaches the log capture handler from the Logger.
Useful for testing or when the application is shutting down.