Class: Jekyll::Plugins::PaginateV3::Utils::Logger
- Inherits:
-
Object
- Object
- Jekyll::Plugins::PaginateV3::Utils::Logger
- Defined in:
- lib/jekyll-paginate-v3/utils/logger.rb
Overview
Small logging adapter that keeps pagination internals independent from
Jekyll logger globals while still writing through Jekyll.logger.
Usage:
- call with
(message, level)wherelevelisdebug|info|warn|error - debug messages are emitted only when
debug_enabledis true - use
scoped_log_lambdato override debug emission for one template
Instance Method Summary collapse
-
#call(message, level = 'info', debug_enabled: nil) ⇒ Object
Uniform logging entry point used by model/builder callbacks.
-
#debug(message, debug_enabled: nil) ⇒ Object
Writes a debug message if pagination debug mode is enabled.
-
#error(message) ⇒ Object
Writes an error message.
-
#info(message) ⇒ Object
Writes an informational message.
-
#initialize(debug_enabled:) ⇒ Logger
constructor
A new instance of Logger.
-
#scoped_log_lambda(debug_enabled:) ⇒ Object
Builds a logger callback that reuses the same info/warn/error routing but applies a local debug override for one pagination scope.
-
#warn(message) ⇒ Object
Writes a warning message.
Constructor Details
#initialize(debug_enabled:) ⇒ Logger
Returns a new instance of Logger.
16 17 18 |
# File 'lib/jekyll-paginate-v3/utils/logger.rb', line 16 def initialize(debug_enabled:) @debug_enabled = !!debug_enabled end |
Instance Method Details
#call(message, level = 'info', debug_enabled: nil) ⇒ Object
Uniform logging entry point used by model/builder callbacks.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jekyll-paginate-v3/utils/logger.rb', line 29 def call(, level = 'info', debug_enabled: nil) case level.to_s when 'debug' debug(, debug_enabled: debug_enabled) when 'warn' warn() when 'error' error() else info() end end |
#debug(message, debug_enabled: nil) ⇒ Object
Writes a debug message if pagination debug mode is enabled.
43 44 45 46 47 |
# File 'lib/jekyll-paginate-v3/utils/logger.rb', line 43 def debug(, debug_enabled: nil) return unless debug_enabled?(debug_enabled) Jekyll.logger.info('Pagination:', "[debug] #{}") end |
#error(message) ⇒ Object
Writes an error message.
60 61 62 |
# File 'lib/jekyll-paginate-v3/utils/logger.rb', line 60 def error() Jekyll.logger.error('Pagination:', .to_s) end |
#info(message) ⇒ Object
Writes an informational message.
50 51 52 |
# File 'lib/jekyll-paginate-v3/utils/logger.rb', line 50 def info() Jekyll.logger.info('Pagination:', .to_s) end |
#scoped_log_lambda(debug_enabled:) ⇒ Object
Builds a logger callback that reuses the same info/warn/error routing but applies a local debug override for one pagination scope.
22 23 24 25 26 |
# File 'lib/jekyll-paginate-v3/utils/logger.rb', line 22 def scoped_log_lambda(debug_enabled:) lambda do |, level = 'info'| call(, level, debug_enabled: debug_enabled) end end |
#warn(message) ⇒ Object
Writes a warning message.
55 56 57 |
# File 'lib/jekyll-paginate-v3/utils/logger.rb', line 55 def warn() Jekyll.logger.warn('Pagination:', .to_s) end |