Centralized logging system for Raxol with structured context, performance tracking, and consistent formatting across all modules.
Features
- Structured logging with automatic context enrichment
- Module-aware logging with automatic module detection
- Performance and timing utilities
- Standardized error handling with stacktraces
- Debug mode support with conditional logging
- Automatic metadata collection (node, environment, version)
- IO.puts/inspect migration helpers
Usage
One call style per module: a module that can require Logger uses the
Logger macros for every plain level call in that file (the macro skips
building the message when the level is disabled), and every other module
uses this one.
The functions here are FUNCTIONS: their arguments, inspect/1 included,
are evaluated before any level check, at every level. So never pass them
inspect of an unbounded term (an app model, a view, an event, the
emulator, a GenServer state) or build a message in a per-byte or per-event
loop. Log a bounded summary (a module, an event type, a size), or use the
Logger macros where the full term is only wanted at :debug. Input a
remote peer sends reaches these paths, so an eager dump there is both a CPU
amplifier (#1031) and a way for that input to land in the logs.
# Basic logging
Log.info("User authenticated successfully")
Log.error("Database connection failed")
# With context
Log.info("Processing request", %{user_id: 123, action: :login})
Log.error("Validation failed", %{errors: errors, input: input})
# Performance timing
Log.time_info("Database query", fn ->
expensive_operation()
end)
# Module-aware logging (automatically detects calling module)
Log.info("Operation completed")
# Migration from IO.puts
Log.console("Debug output for development")
Summary
Functions
Log with automatic error classification and severity detection.
Console logging for development - replacement for IO.puts.
Logs at :info in development/test environments and at :debug otherwise.
Logs a debug message.
Conditional debug logging based on module configuration.
Logs an error with stacktrace and context.
Structured event logging with automatic metadata enrichment.
Structured inspect logging - replacement for IO.inspect.
Module-aware logging that automatically detects the calling module.
Performance timing logger that measures and logs execution time.
Logs a warning with context.
Types
Functions
Log with automatic error classification and severity detection.
Console logging for development - replacement for IO.puts.
Logs at :info in development/test environments and at :debug otherwise.
@spec debug(iodata()) :: :ok
Logs a debug message.
Conditional debug logging based on module configuration.
Logs an error with stacktrace and context.
Structured event logging with automatic metadata enrichment.
Structured inspect logging - replacement for IO.inspect.
Module-aware logging that automatically detects the calling module.
Performance timing logger that measures and logs execution time.
Logs a warning with context.