Class: Lumberjack::Template::StandardFormatterTemplate

Inherits:
Lumberjack::Template show all
Defined in:
lib/lumberjack/template.rb

Overview

A wrapper template that delegates formatting to a standard Ruby Logger formatter. This provides compatibility with existing Logger::Formatter implementations while maintaining the Template interface for consistent usage within Lumberjack.

Constant Summary

Constants inherited from Lumberjack::Template

DEFAULT_ADDITIONAL_LINES_TEMPLATE, DEFAULT_ATTRIBUTE_FORMAT, DEFAULT_FIRST_LINE_TEMPLATE, STDLIB_FIRST_LINE_TEMPLATE

Instance Method Summary collapse

Methods inherited from Lumberjack::Template

colorize_entry

Constructor Details

#initialize(formatter) ⇒ StandardFormatterTemplate

Create a new wrapper for a standard Ruby Logger formatter.

Parameters:

  • formatter (Logger::Formatter)

    The formatter to wrap



60
61
62
# File 'lib/lumberjack/template.rb', line 60

def initialize(formatter)
  @formatter = formatter
end

Instance Method Details

#call(entry) ⇒ String

Format a log entry using the wrapped formatter.

Parameters:

Returns:

  • (String)

    The formatted log entry



68
69
70
# File 'lib/lumberjack/template.rb', line 68

def call(entry)
  @formatter.call(entry.severity_label, entry.time, entry.progname, entry.message)
end

#datetime_formatString?

Get the datetime format from the wrapped formatter if supported.

Returns:

  • (String, nil)

    The datetime format string, or nil if not supported



83
84
85
# File 'lib/lumberjack/template.rb', line 83

def datetime_format
  @formatter.datetime_format if @formatter.respond_to?(:datetime_format)
end

#datetime_format=(value) ⇒ void

This method returns an undefined value.

Set the datetime format on the wrapped formatter if supported.

Parameters:

  • value (String)

    The datetime format string



76
77
78
# File 'lib/lumberjack/template.rb', line 76

def datetime_format=(value)
  @formatter.datetime_format = value if @formatter.respond_to?(:datetime_format=)
end