Statifier.Logging.LogManager (statifier v1.5.0)
View SourceCentral logging manager for the Statifier logging system.
LogManager provides a unified interface for logging throughout Statifier, with automatic metadata extraction from StateChart instances. It handles log level filtering and delegates to the configured logging adapter.
Automatic Metadata Extraction
LogManager automatically extracts core metadata from the StateChart:
current_state: List of currently active leaf statesevent: Name of the current event being processed (if any)
Additional context-specific metadata can be provided by callers.
Log Levels
Supports standard log levels in order of increasing severity:
:trace- Very detailed information:debug- Debugging information:info- General information:warn- Warning messages:error- Error messages
Examples
# Basic logging with automatic metadata
state_chart = LogManager.info(state_chart, "Processing started")
# Logging with additional metadata
state_chart = LogManager.debug(state_chart, "Evaluating condition", %{
action_type: "transition",
condition: "x > 5"
})
# Check if level is enabled before expensive operations
if LogManager.enabled?(state_chart, :debug) do
expensive_debug_info = build_complex_debug_data()
state_chart = LogManager.debug(state_chart, expensive_debug_info)
end
Summary
Functions
Configure logging for a StateChart from initialization options.
Logs a debug message with automatic metadata extraction.
Checks if a log level is enabled for the given StateChart.
Logs an error message with automatic metadata extraction.
Logs an info message with automatic metadata extraction.
Logs a message at the specified level with automatic metadata extraction.
Logs a trace message with automatic metadata extraction.
Logs a warning message with automatic metadata extraction.
Functions
@spec configure_from_options( Statifier.StateChart.t(), keyword() ) :: Statifier.StateChart.t()
Configure logging for a StateChart from initialization options.
This function is called by Interpreter.initialize/2 to set up logging
based on provided options, application configuration, or environment defaults.
Options
:log_adapter- Logging adapter configuration. Can be:- An adapter struct (e.g.,
%TestAdapter{max_entries: 100}) - A tuple
{AdapterModule, opts}(e.g.,{TestAdapter, [max_entries: 50]}) - If not provided, uses environment-specific defaults
- An adapter struct (e.g.,
:log_level- Minimum log level (:trace,:debug,:info,:warn,:error)- Defaults to
:debugin test environment,:infootherwise
- Defaults to
Examples
# Use with runtime options
state_chart = LogManager.configure_from_options(state_chart, [
log_adapter: {TestAdapter, [max_entries: 100]},
log_level: :debug
])
# Use with application configuration set
state_chart = LogManager.configure_from_options(state_chart, [])
@spec debug(Statifier.StateChart.t(), String.t(), map()) :: Statifier.StateChart.t()
Logs a debug message with automatic metadata extraction.
Debug level is for information useful for debugging.
@spec enabled?(Statifier.StateChart.t(), atom()) :: boolean()
Checks if a log level is enabled for the given StateChart.
A level is enabled if:
- It meets the StateChart's minimum log level
- The adapter reports it as enabled
Parameters
state_chart- Current StateChart instancelevel- Log level to check
Returns
true if logging at this level will produce output, false otherwise
@spec error(Statifier.StateChart.t(), String.t(), map()) :: Statifier.StateChart.t()
Logs an error message with automatic metadata extraction.
Error level is for error conditions that don't halt execution.
@spec info(Statifier.StateChart.t(), String.t(), map()) :: Statifier.StateChart.t()
Logs an info message with automatic metadata extraction.
Info level is for general informational messages.
@spec log(Statifier.StateChart.t(), atom(), String.t(), map()) :: Statifier.StateChart.t()
Logs a message at the specified level with automatic metadata extraction.
Extracts core metadata from the StateChart and merges it with any additional metadata provided. Only logs if the level is enabled.
Parameters
state_chart- Current StateChart instancelevel- Log level atommessage- Log message stringadditional_metadata- Optional additional metadata map
Returns
Updated StateChart (may be unchanged if adapter doesn't modify it)
@spec trace(Statifier.StateChart.t(), String.t(), map()) :: Statifier.StateChart.t()
Logs a trace message with automatic metadata extraction.
Trace level is for very detailed diagnostic information.
@spec warn(Statifier.StateChart.t(), String.t(), map()) :: Statifier.StateChart.t()
Logs a warning message with automatic metadata extraction.
Warning level is for potentially problematic situations.