Quickstart Guide
View SourceGet started with LoggerLogfmt in under 5 minutes.
Installation
Add LoggerLogfmt to your dependencies in mix.exs:
def deps do
[
{:logger_logfmt, "~> 0.1.0"}
]
endThen run:
mix deps.get
Configuration
Configure Logger to use the logfmt formatter in config/config.exs:
config :logger, :console,
format: {Logger.Backends.Logfmt, :format},
metadata: [:request_id, :user_id]Basic Usage
require Logger
# Simple log message
Logger.info("User logged in")
# Output: timestamp="2024-01-15 10:30:45.123" level=info message="User logged in"
# With metadata
Logger.info("Payment processed", amount: 99.99, currency: "USD")
# Output: timestamp="2024-01-15 10:30:45.123" level=info message="Payment processed" amount=99.99 currency=USDCommon Configuration
Customize Format Fields
config :logger, :logfmt,
format: [:timestamp, :level, :message, :metadata]Available fields: :timestamp, :level, :message, :domain, :node, :pid, :metadata, :file, :line
Metadata Filtering
# Whitelist mode - only include specified keys
config :logger, :logfmt,
metadata: [:request_id, :user_id],
mode: :whitelist
# Blacklist mode - include all except specified keys
config :logger, :logfmt,
metadata: [:password, :credit_card],
mode: :blacklistTimestamp Format
config :logger, :logfmt,
timestamp_format: :iso8601 # or :elixir, :epoch_timeFormats:
:elixir-"2024-01-15 10:30:45.123":iso8601-"2024-01-15T10:30:45.123"(default):epoch_time- Unix timestamp in seconds
Features
- Human-readable and machine-parseable - Easy to read and grep
- Automatic quoting - Values with spaces are quoted
- Nested maps - Supported with dot notation (
user.name=Alice) - Zero dependencies - Pure Elixir implementation
Next Steps
- USAGE_GUIDE.md - Comprehensive feature documentation
- EXAMPLES.md - Complete runnable examples
- README.md - Project overview