abstract class Logit::Formatter

Overview

Abstract base class for log event formatters.

Formatters convert log events into string output. Each backend uses a formatter to determine how events are displayed or written.

Built-in Formatters

Creating a Custom Formatter

Subclass Formatter and implement the #format method:

class MyFormatter < Logit::Formatter
  def format(event : Logit::Event) : String
    String.build do |io|
      io << "[" << event.level.to_s.upcase << "] "
      io << event.class_name << "#" << event.method_name
      io << " (" << event.duration_ms << "ms)"
    end
  end
end

# Use the custom formatter
Logit.configure do |config|
  config.console(formatter: MyFormatter.new)
end

Direct Known Subclasses

Defined in:

logit/formatter.cr

Instance Method Summary

Instance Method Detail

abstract def format(event : Event) : String #

Formats an event into a string representation.

The returned string should be a complete log line including any necessary newlines.


[View source]