Durable.LogCapture.Handler (Durable v0.1.0-rc)

View Source

Logger 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

  1. When a log event occurs, the log/2 callback is invoked
  2. The handler checks if :durable_workflow_id is set in the process dictionary
  3. If in workflow context, the log is added to the :durable_logs buffer
  4. 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

attach()

@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.

attached?()

@spec attached?() :: boolean()

Returns whether the handler is currently attached.

detach()

@spec detach() :: :ok | {:error, term()}

Detaches the log capture handler from the Logger.

Useful for testing or when the application is shutting down.