Raxol.Core.Runtime.Log (Raxol v2.0.1)

View Source

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

Instead of using Logger directly or IO.puts, use this module:

# 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. Only logs in development/test environments.

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

context()

@type context() :: map() | keyword() | nil

log_level()

@type log_level() :: :debug | :info | :warn | :error

metadata()

@type metadata() :: map()

Functions

auto_log(msg, data \\ nil)

Log with automatic error classification and severity detection.

console(msg, context \\ nil)

Console logging for development - replacement for IO.puts. Only logs in development/test environments.

debug(msg)

debug(msg, context)

debug_if(condition, msg, context \\ nil)

Conditional debug logging based on module configuration.

debug_with_context(msg, context)

error(msg)

error(msg, context)

error_with_context(msg, context)

error_with_stacktrace(msg, error, stacktrace, context \\ nil)

Logs an error with stacktrace and context.

event(event_type, msg, context \\ %{})

Structured event logging with automatic metadata enrichment.

info(msg)

info(msg, context)

info_with_context(msg)

info_with_context(msg, context)

log_inspect(data, label \\ nil, opts \\ [])

Structured inspect logging - replacement for IO.inspect.

module_debug(msg, context \\ nil)

Module-aware logging that automatically detects the calling module.

module_error(msg, context \\ nil)

module_info(msg, context \\ nil)

module_warning(msg, context \\ nil)

time_debug(msg, func)

Performance timing logger that measures and logs execution time.

time_info(msg, func)

time_warning(msg, func)

warning(msg)

warning(msg, context)

warning_with_context(msg, context)

Logs a warning with context.