Snakepit.Logger (Snakepit v0.8.7)
View SourceCentralized, silent-by-default logging for Snakepit.
Configuration
# Silent (default) - only errors
config :snakepit, log_level: :error
# Warnings and errors
config :snakepit, log_level: :warning
# Verbose - info, warnings, errors
config :snakepit, log_level: :info
# Debug - everything
config :snakepit, log_level: :debug
# Completely silent (not even errors)
config :snakepit, log_level: :noneCategories
Enable specific categories for targeted debugging:
config :snakepit, log_categories: [:lifecycle, :grpc]Process-Level Isolation (for Testing)
Log levels can be set per-process to avoid race conditions in async tests:
# Set log level for current process only
Snakepit.Logger.set_process_level(:debug)
# Execute with temporary log level
Snakepit.Logger.with_level(:warning, fn ->
# ... code that should log at warning level
end)
# Clear process-level override
Snakepit.Logger.clear_process_level()The resolution order is:
- Process-level override (via
set_process_level/1) - Elixir Logger process level (via
Logger.put_process_level/2) - Application config (via
config :snakepit, log_level: ...)
Summary
Functions
Clear the process-level log level override.
Log at debug level if configured log level allows it.
Log at error level if configured log level allows it.
Get the effective log level for the current process.
Log at info level if configured log level allows it.
Set the log level for the current process only.
Check if logging at the given level is enabled.
Check if logging at the given level/category is enabled.
Log at warning level if configured log level allows it.
Execute a function with a temporary log level for the current process.
Types
Functions
@spec clear_process_level() :: :ok
Clear the process-level log level override.
After calling this, the process will use the global Application config.
Log at debug level if configured log level allows it.
Log at error level if configured log level allows it.
@spec get_process_level() :: level()
Get the effective log level for the current process.
Returns the log level in priority order:
- Process-level override (set via
set_process_level/1) - Elixir Logger process level
- Application config
Log at info level if configured log level allows it.
@spec set_process_level(level()) :: :ok
Set the log level for the current process only.
This is useful for test isolation - each test process can have its own log level without affecting other concurrent tests.
Examples
Snakepit.Logger.set_process_level(:debug)
# All logging in this process now uses :debug level
Snakepit.Logger.set_process_level(:none)
# All logging in this process is now suppressed
Check if logging at the given level is enabled.
Check if logging at the given level/category is enabled.
Log at warning level if configured log level allows it.
Execute a function with a temporary log level for the current process.
The previous log level is restored after the function completes, even if it raises an exception.
Examples
Snakepit.Logger.with_level(:debug, fn ->
# Debug logs are enabled here
Snakepit.Logger.debug(:pool, "detailed info")
end)
# Previous log level is restored