KeenAuth.Logger (KeenAuth v1.0.1)

Copy Markdown View Source

Categorized logging for KeenAuth with compile-time purging support.

Categories

  • AUTH - Authentication flow (authorize redirect, callback handling)
  • MAPPER - User data mapping and normalization
  • PROCESSOR - Business logic processing
  • STORAGE - Session/token storage operations
  • SECURITY - Security validations (redirect URLs, input validation)
  • CONFIG - Configuration loading and validation

Usage

require KeenAuth.Logger, as: Log

Log.debug(:auth, "Starting OAuth flow", provider: :github)
Log.info(:mapper, "Mapped user", user_id: user.id)
Log.warn(:security, "Rejected redirect URL", url: url)
Log.error(:processor, "Authentication failed", reason: reason)

Compile-Time Purging

Debug logs can be completely removed from production builds by configuring Logger's compile-time purge level in your config/prod.exs:

config :logger,
  compile_time_purge_matching: [
    [level_lower_than: :info]
  ]

This removes all :debug level logs at compile time - zero runtime overhead.

Runtime Control

You can also control log levels at runtime:

# Set KeenAuth logs to debug level
Logger.put_module_level(KeenAuth.Logger, :debug)

# Or configure in config
config :logger, :keen_auth,
  level: :debug

Summary

Functions

Logs a debug message with category prefix.

Logs an error message with category prefix.

Logs an info message with category prefix.

Logs a warning message with category prefix.

Types

category()

@type category() :: :auth | :mapper | :processor | :storage | :security | :config

Functions

debug(category, message, metadata \\ [])

(macro)

Logs a debug message with category prefix.

Debug logs are typically stripped from production builds via compile_time_purge_matching.

error(category, message, metadata \\ [])

(macro)

Logs an error message with category prefix.

info(category, message, metadata \\ [])

(macro)

Logs an info message with category prefix.

warn(category, message, metadata \\ [])

(macro)

Logs a warning message with category prefix.