Logit::Config
Configuration builder for setting up Logit logging infrastructure.
Use Logit.configure to create and apply a configuration. The config
provides a fluent API for adding backends, setting up namespace filtering,
and configuring redaction patterns.
Basic Configuration
Logit.configure do |config|
config.console(level: Logit::LogLevel::Debug)
end
Multiple Backends
Logit.configure do |config|
# Console for development
console = config.console(level: Logit::LogLevel::Info)
# JSON file for production logs
file = config.file("logs/app.log", level: Logit::LogLevel::Debug)
# Different levels per namespace
config.bind("MyApp::Database::*", Logit::LogLevel::Warn, console)
config.bind("MyApp::Http::*", Logit::LogLevel::Debug, file)
end
Redaction
Logit.configure do |config|
config.console
# Enable common security patterns (password, token, api_key, etc.)
config.redact_common_patterns
# Add custom patterns
config.redact_patterns(/ssn/i, /credit_card/i)
end
Constructors
Creates a new Config, yields it for configuration, and returns it.
Typically you should use Logit.configure instead, which also applies
the configuration.
Instance methods
Adds a backend to the default tracer.
Creates the default tracer if it doesn't exist. For most applications,
use console or file methods instead, which call this internally.
Registers a named tracer.
Most applications only need the default tracer, but you can create additional named tracers for advanced use cases like multi-tenant logging.
Binds a namespace pattern to a log level for a specific backend.
This allows fine-grained control over which namespaces (classes) log at which levels. More specific patterns take precedence over less specific ones.
Pattern syntax:
MyApp::*- matches any class directly in MyAppMyApp::**- matches any class in MyApp or any nested namespaceMyApp::Http::*- matches classes in MyApp::Http
console = config.console
# Only log warnings and above from database classes
config.bind("MyApp::Database::*", Logit::LogLevel::Warn, console)
# But log everything from the query builder
config.bind("MyApp::Database::QueryBuilder", Logit::LogLevel::Debug, console)
Finalizes the configuration by setting the default tracer.
Called automatically by Logit.configure.
Adds a console backend that writes to STDOUT.
The console backend uses Formatter::Human by default, which produces
colorized, human-readable output suitable for development.
- level: Minimum log level (default: Info)
- formatter: Output formatter (default: Human)
- buffered: Whether to buffer output (default: false for immediate display)
Returns the created backend for further configuration (e.g., namespace bindings).
config.console(level: Logit::LogLevel::Debug)
Name of the default tracer used by instrumented methods.
Adds a file backend that writes to the specified path.
The file backend uses Formatter::JSON by default, which produces
structured JSON output suitable for log aggregation systems.
- path: Path to the log file (will be created if it doesn't exist)
- level: Minimum log level (default: Info)
- buffered: Whether to buffer output (default: true for performance)
Returns the created backend for further configuration (e.g., namespace bindings).
config.file("logs/app.log", level: Logit::LogLevel::Debug)
NOTE: The file is opened with mode 0o600 (owner read/write only) by default.
Symlinks are not followed unless explicitly enabled in Backend::File.
Adds an OTLP backend that exports logs to an OpenTelemetry collector.
The OTLP backend sends log events in batches via HTTP/JSON to an OpenTelemetry-compatible endpoint. Events are buffered and flushed when the batch size is reached or the flush interval elapses.
- endpoint: OTLP HTTP endpoint URL (e.g., "http://localhost:4318/v1/logs")
- level: Minimum log level (default: Info)
- batch_size: Maximum events per batch (default: 512)
- flush_interval: Time between automatic flushes (default: 5.seconds)
- headers: HTTP headers for authentication (default: empty)
- timeout: HTTP request timeout (default: 30.seconds)
- resource_attributes: Resource attributes like service.name (default: empty)
Returns the created backend for further configuration (e.g., namespace bindings).
Logit.configure do |config|
config.otlp(
"http://localhost:4318/v1/logs",
resource_attributes: {"service.name" => "my-app"}
)
end
With authentication:
Logit.configure do |config|
config.otlp(
"https://otlp.example.com/v1/logs",
headers: {"Authorization" => "Bearer token"},
resource_attributes: {
"service.name" => "my-app",
"deployment.environment" => "production"
}
)
end
Enables a set of common security-related redaction patterns.
This is a convenience method that adds patterns for commonly sensitive argument names including: password, secret, token, api_key, auth, credential, private_key, access_key, and bearer.
config.redact_common_patterns
Adds global redaction patterns that apply to all instrumented methods.
Any argument name matching one of these regex patterns will have its
value replaced with [REDACTED] in the logs.
config.redact_patterns(/ssn/i, /credit_card/i, /social_security/i)