Add Logging

This guide shows you how to implement logging in your Azu application.

Built-in Logger

Use Azu's built-in logger handler:

MyApp.start [
  Azu::Handler::Logger.new,
  # ... other handlers
]

Configure Log Level

Set the log level based on environment:

Azu.configure do |config|
  case ENV.fetch("AZU_ENV", "development")
  when "production"
    config.log.level = Log::Severity::Info
  when "test"
    config.log.level = Log::Severity::Warn
  else
    config.log.level = Log::Severity::Debug
  end
end

Custom Logger Handler

Create a structured logger:

Logging in Endpoints

Log within your endpoints:

Log Backends

File Backend

JSON Backend

Multiple Backends

Request Context Logging

Include request context in all logs:

Error Logging

Log errors with full context:

Sensitive Data Filtering

Filter sensitive data from logs:

Log Rotation

Use logrotate for production:

Performance Logging

Log slow requests:

See Also

Last updated

Was this helpful?