class
Logit::Integrations::CrystalLogAdapter
- Logit::Integrations::CrystalLogAdapter
- Log::Backend
- Reference
- Object
Overview
Adapter that captures Crystal Log calls and forwards them to Logit.
This enables unified logging infrastructure where all logs flow through Logit, providing OTLP export, trace context, and wide events.
Installation
require "logit"
require "logit/integrations/crystal_log_adapter"
# Configure Logit first
Logit.configure do |config|
config.console(Logit::LogLevel::Debug)
config.otlp("http://localhost:4318/v1/logs")
end
# Install the adapter
Logit::Integrations::CrystalLogAdapter.install
# All Log.info/debug/etc calls now flow through Logit
Log.info { "This is captured by Logit" }
Trace Context Integration
When installed, Crystal Log calls automatically inherit trace context from any active Logit span:
@[Logit::Log]
def process_request
# This Log call inherits the trace context from the span
Log.info { "Processing request" }
do_work
Log.info { "Request complete" }
end
Namespace Mapping
Crystal Log sources are mapped to Logit namespaces, allowing you to control logging per-source:
Logit.configure do |config|
console = config.console
# Control Crystal Log sources via namespace bindings
config.bind "db.*", Logit::LogLevel::Debug, console
config.bind "http.client", Logit::LogLevel::Warn, console
end
Defined in:
logit/integrations/crystal_log_adapter.crConstructors
Class Method Summary
-
.install(dispatch_mode : ::Log::DispatchMode = :sync) : Nil
Install this adapter as Crystal Log backend.
-
.installed? : Bool
Check if the adapter is currently installed.
-
.uninstall : Nil
Uninstall the adapter and restore default Log behavior.
Instance Method Summary
-
#write(entry : ::Log::Entry) : Nil
Writes the entry to this backend.
Constructor Detail
Class Method Detail
Install this adapter as Crystal Log backend.
This replaces the default Log backend so all Log calls flow through Logit. You should configure Logit backends BEFORE calling install.
- dispatch_mode: How to dispatch log entries. Use
:syncfor synchronous (safer but may block) or:asyncfor asynchronous (better performance). Default is:syncfor reliability.
# Configure Logit first
Logit.configure do |config|
config.console(Logit::LogLevel::Debug)
end
# Then install the adapter
Logit::Integrations::CrystalLogAdapter.install
# Or with async dispatch for better performance
Logit::Integrations::CrystalLogAdapter.install(dispatch_mode: :async)
Uninstall the adapter and restore default Log behavior.
This resets Crystal Log to its default configuration (Info to STDOUT).
Instance Method Detail
Writes the entry to this backend.