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
Class Method Summary collapse
-
.debug(component, message) ⇒ void
Log a debug message with component prefix.
-
.debug? ⇒ Boolean
Check if debug logging is enabled.
-
.debug_if_enabled(component, message) ⇒ void
Conditionally log at debug level if debug is enabled.
-
.error(component, message) ⇒ void
Log an error message with component prefix.
-
.info(component, message) ⇒ void
Log an info message with component prefix.
-
.trace?(config) ⇒ Boolean
Check if trace logging is enabled in configuration.
-
.trace_if_enabled(config, component, message) ⇒ void
Conditionally log at debug level if trace mode is enabled.
-
.warn(component, message) ⇒ void
Log a warning message with component prefix.
Class Method Details
.debug(component, message) ⇒ void
This method returns an undefined value.
Log a debug message with component prefix.
36 37 38 |
# File 'lib/jekyll-l10n/utils/logger_formatter.rb', line 36 def self.debug(component, ) Jekyll.logger.debug 'Localization', "[#{component}] #{}" end |
.debug? ⇒ Boolean
Check if debug logging is enabled.
Returns true if JEKYLL_LOG_LEVEL is set to debug or lower (trace).
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.
97 98 99 |
# File 'lib/jekyll-l10n/utils/logger_formatter.rb', line 97 def self.debug_if_enabled(component, ) debug(component, ) if debug? end |
.error(component, message) ⇒ void
This method returns an undefined value.
Log an error message with component prefix.
54 55 56 |
# File 'lib/jekyll-l10n/utils/logger_formatter.rb', line 54 def self.error(component, ) Jekyll.logger.error 'Localization', "[#{component}] #{}" end |
.info(component, message) ⇒ void
This method returns an undefined value.
Log an info message with component prefix.
27 28 29 |
# File 'lib/jekyll-l10n/utils/logger_formatter.rb', line 27 def self.info(component, ) Jekyll.logger.info 'Localization', "[#{component}] #{}" 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.
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.
109 110 111 |
# File 'lib/jekyll-l10n/utils/logger_formatter.rb', line 109 def self.trace_if_enabled(config, component, ) debug(component, ) if trace?(config) end |
.warn(component, message) ⇒ void
This method returns an undefined value.
Log a warning message with component prefix.
45 46 47 |
# File 'lib/jekyll-l10n/utils/logger_formatter.rb', line 45 def self.warn(component, ) Jekyll.logger.warn 'Localization', "[#{component}] #{}" end |