class Logit::Integrations::CrystalLogAdapter

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.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(dispatch_mode : ::Log::DispatchMode = :async) #

[View source]

Class Method Detail

def self.install(dispatch_mode : ::Log::DispatchMode = :sync) : Nil #

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 :sync for synchronous (safer but may block) or :async for asynchronous (better performance). Default is :sync for 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)

[View source]
def self.installed? : Bool #

Check if the adapter is currently installed.


[View source]
def self.uninstall : Nil #

Uninstall the adapter and restore default Log behavior.

This resets Crystal Log to its default configuration (Info to STDOUT).


[View source]

Instance Method Detail

def write(entry : ::Log::Entry) : Nil #
Description copied from class Log::Backend

Writes the entry to this backend.


[View source]