Module: Jekyll::L10n::LoggerFormatter

Defined in:
lib/jekyll-l10n/utils/logger_formatter.rb

Overview

Formats and conditionally logs messages with component prefixes.

LoggerFormatter provides a consistent logging interface for the plugin, prefixing all messages with component names (e.g., “[HtmlTranslator]”). It also handles conditional debug and trace logging based on Jekyll’s log level and configuration.

Key responsibilities:

  • Log messages with component prefixes

  • Conditionally log at debug level

  • Check debug and trace logging configuration

  • Support both Jekyll log levels and configuration-based trace mode

Examples:

LoggerFormatter.info("HtmlTranslator", "Starting translation")
LoggerFormatter.debug_if_enabled("Extractor", "Extracting from file")

Class Method Summary collapse

Class Method Details

.debug(component, message) ⇒ void

This method returns an undefined value.

Log a debug message with component prefix.

Parameters:

  • component (String)

    Component name

  • message (String)

    Message to log



36
37
38
# File 'lib/jekyll-l10n/utils/logger_formatter.rb', line 36

def self.debug(component, message)
  Jekyll.logger.debug 'Localization', "[#{component}] #{message}"
end

.debug?Boolean

Check if debug logging is enabled.

Returns true if JEKYLL_LOG_LEVEL is set to debug or lower (trace).

Returns:

  • (Boolean)

    True if debug logging is enabled



63
64
65
66
67
68
69
# File 'lib/jekyll-l10n/utils/logger_formatter.rb', line 63

def self.debug?
  level = Jekyll.logger.level
  # Handle both numeric and symbol log levels
  return %i[debug trace].include?(level) if level.is_a?(Symbol)

  level <= 0 # DEBUG = 0
end

.debug_if_enabled(component, message) ⇒ void

This method returns an undefined value.

Conditionally log at debug level if debug is enabled.

Only logs if debug logging is enabled via Jekyll log level.

Parameters:

  • component (String)

    Component name

  • message (String)

    Message to log



97
98
99
# File 'lib/jekyll-l10n/utils/logger_formatter.rb', line 97

def self.debug_if_enabled(component, message)
  debug(component, message) if debug?
end

.error(component, message) ⇒ void

This method returns an undefined value.

Log an error message with component prefix.

Parameters:

  • component (String)

    Component name

  • message (String)

    Message to log



54
55
56
# File 'lib/jekyll-l10n/utils/logger_formatter.rb', line 54

def self.error(component, message)
  Jekyll.logger.error 'Localization', "[#{component}] #{message}"
end

.info(component, message) ⇒ void

This method returns an undefined value.

Log an info message with component prefix.

Parameters:

  • component (String)

    Component name (e.g., ‘HtmlTranslator’)

  • message (String)

    Message to log



27
28
29
# File 'lib/jekyll-l10n/utils/logger_formatter.rb', line 27

def self.info(component, message)
  Jekyll.logger.info 'Localization', "[#{component}] #{message}"
end

.trace?(config) ⇒ Boolean

Check if trace logging is enabled in configuration.

Accepts both PageLocalesConfig objects and hash-based configurations. Returns true if trace mode is explicitly enabled.

Parameters:

Returns:

  • (Boolean)

    True if trace logging is enabled



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/jekyll-l10n/utils/logger_formatter.rb', line 78

def self.trace?(config)
  return false if config.nil?

  # Try to call trace_logging? method (for PageLocalesConfig objects)
  return config.trace_logging? if config.respond_to?(:trace_logging?)

  # Fall back to checking hash structure (for hash-based configs)
  config.dig('logging', 'trace') == true
rescue StandardError
  false
end

.trace_if_enabled(config, component, message) ⇒ void

This method returns an undefined value.

Conditionally log at debug level if trace mode is enabled.

Only logs if trace mode is enabled in configuration.

Parameters:

  • config (PageLocalesConfig, Hash, nil)

    Configuration

  • component (String)

    Component name

  • message (String)

    Message to log



109
110
111
# File 'lib/jekyll-l10n/utils/logger_formatter.rb', line 109

def self.trace_if_enabled(config, component, message)
  debug(component, message) if trace?(config)
end

.warn(component, message) ⇒ void

This method returns an undefined value.

Log a warning message with component prefix.

Parameters:

  • component (String)

    Component name

  • message (String)

    Message to log



45
46
47
# File 'lib/jekyll-l10n/utils/logger_formatter.rb', line 45

def self.warn(component, message)
  Jekyll.logger.warn 'Localization', "[#{component}] #{message}"
end