Class: PluginMetaLogger
- Inherits:
-
Object
- Object
- PluginMetaLogger
- Includes:
- Singleton
- Defined in:
- lib/jekyll_plugin_meta_logger.rb
Overview
Makes a meta-logger instance (a singleton) with level set by site.config.
Saves site.config for later use when creating plugin loggers; these loggers each have their own log levels.
For example, if the plugin's progname has value MyPlugin then an entry called plugin_loggers.MyPlugin
will be read from config, if present.
If no such entry is found then the meta-logger log_level is set to :info.
If you want to see messages that indicate the loggers and log levels as they are created,
set the log level for PluginMetaLogger to debug in _config.yml
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #debug(&block) ⇒ Object
- #error(&block) ⇒ Object
- #info(&block) ⇒ Object
-
#initialize ⇒ PluginMetaLogger
constructor
A new instance of PluginMetaLogger.
- #level_as_sym ⇒ Object
-
#new_logger(klass, config = nil, stream_name = $stdout) ⇒ Object
By the time this method is called,
PluginMetaLogger.instance.configcontains the entire contents of_config.yml. - #warn(&block) ⇒ Object
Constructor Details
#initialize ⇒ PluginMetaLogger
Returns a new instance of PluginMetaLogger.
36 37 38 39 40 |
# File 'lib/jekyll_plugin_meta_logger.rb', line 36 def initialize super @config = nil @logger = new_logger(self) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
33 34 35 |
# File 'lib/jekyll_plugin_meta_logger.rb', line 33 def config @config end |
#logger ⇒ Object
Returns the value of attribute logger.
33 34 35 |
# File 'lib/jekyll_plugin_meta_logger.rb', line 33 def logger @logger end |
Instance Method Details
#debug(&block) ⇒ Object
47 48 49 50 |
# File 'lib/jekyll_plugin_meta_logger.rb', line 47 def debug(&block) # Delegate to @logger which respects the configured level @logger.debug(self) { yield block } end |
#error(&block) ⇒ Object
60 61 62 |
# File 'lib/jekyll_plugin_meta_logger.rb', line 60 def error(&block) @logger.error(self) { yield block } end |
#info(&block) ⇒ Object
42 43 44 45 |
# File 'lib/jekyll_plugin_meta_logger.rb', line 42 def info(&block) # Delegate to @logger which respects the configured level @logger.info(self) { yield block } end |
#level_as_sym ⇒ Object
52 53 54 |
# File 'lib/jekyll_plugin_meta_logger.rb', line 52 def level_as_sym @logger.level_as_sym end |
#new_logger(klass, config = nil, stream_name = $stdout) ⇒ Object
By the time this method is called, PluginMetaLogger.instance.config contains the entire contents of _config.yml
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/jekyll_plugin_meta_logger.rb', line 65 def new_logger(klass, config = nil, stream_name = $stdout) @config ||= config if @config.nil? logger = PluginLogger.new(klass, {}, stream_name) logger.debug { 'PluginMetaLogger was not initialized from site.config.' } else logger = PluginLogger.new(klass, @config, stream_name) logger.debug { 'PluginMetaLogger was initialized from site.config.' } end logger end |
#warn(&block) ⇒ Object
56 57 58 |
# File 'lib/jekyll_plugin_meta_logger.rb', line 56 def warn(&block) @logger.warn(self) { yield block } end |