class Logit::Backend::Console

Overview

Backend that writes log events to the console (STDOUT).

Uses the Formatter::Human formatter by default, which produces colorized, human-readable output suitable for development and debugging.

Basic Usage

Logit.configure do |config|
  config.console(level: Logit::LogLevel::Debug)
end

Custom Configuration

# Use JSON formatter for console output
Logit.configure do |config|
  config.console(
    level: Logit::LogLevel::Info,
    formatter: Logit::Formatter::JSON.new
  )
end

Output Example (Human formatter)

10:30:45.123 INFO  UserService#find_user (2ms) → User{id: 42}  user_service.cr:15
    args: id=42

Included Modules

Defined in:

logit/backends/console.cr

Constructors

Instance Method Summary

Instance methods inherited from module Logit::BufferedIO

buffer_size=(size : Int32) : Nil buffer_size=, buffered=(value : Bool) : Nil buffered=

Instance methods inherited from class Logit::Backend

bind(pattern : String, level : LogLevel) : Nil bind, bindings : Array(NamespaceBinding) bindings, bindings=(bindings : Array(NamespaceBinding)) bindings=, close : Nil close, flush : Nil flush, formatter : Formatter | Nil formatter, formatter=(formatter : Formatter | Nil) formatter=, level : LogLevel level, level=(level : LogLevel) level=, log(event : Event) : Nil log, name : String name, name=(name : String) name=, should_log?(event : Event) : Bool should_log?, should_log_level?(level : LogLevel, namespace : String) : Bool should_log_level?

Constructor methods inherited from class Logit::Backend

new(name : String, level : Logit::LogLevel = LogLevel::Info, formatter : Logit::Formatter | Nil = nil) new

Constructor Detail

def self.new(name = "console", level = LogLevel::Info, formatter = Formatter::Human.new) #

Creates a new console backend.

  • name: Backend name for identification (default: "console")
  • level: Minimum log level (default: Info)
  • formatter: Output formatter (default: Human)

[View source]

Instance Method Detail

def flush : Nil #

Flushes the output buffer.


[View source]
def io : IO #

The IO to write to (defaults to STDOUT).


[View source]
def io=(io : IO) #

The IO to write to (defaults to STDOUT).


[View source]
def log(event : Event) : Nil #

Logs an event to the console.


[View source]