Class: PluginMetaLogger

Inherits:
Object
  • Object
show all
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`

Examples:

# Create and initialize the meta-logger singleton in a high priority Jekyll `site` `:after_init` hook:
@meta_logger = PluginMetaLogger.instance.new_logger(site.config, self)
@meta_logger.info { "Meta-logger has been created" }

# In `config.yml`:
plugin_loggers:
  PluginMetaLogger: info
  MyPlugin: warn
  MakeArchive: error
  ArchiveDisplayTag: debug

# In a Jekyll plugin:
@logger = PluginMetaLogger.instance.setup(self)
@logger.info { "This is a log message from a Jekyll plugin" }
#
PluginMetaLogger.instance.info { "MyPlugin vX.Y.Z has been loaded" }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePluginMetaLogger

Returns a new instance of PluginMetaLogger.



35
36
37
38
39
# File 'lib/jekyll_plugin_meta_logger.rb', line 35

def initialize
  super
  @config = nil
  @logger = new_logger(self)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



33
34
35
# File 'lib/jekyll_plugin_meta_logger.rb', line 33

def config
  @config
end

#loggerObject (readonly)

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



45
46
47
# File 'lib/jekyll_plugin_meta_logger.rb', line 45

def debug(&block)
  @logger.debug(self) { yield block }
end

#error(&block) ⇒ Object



57
58
59
# File 'lib/jekyll_plugin_meta_logger.rb', line 57

def error(&block)
  @logger.error(self) { yield block }
end

#info(&block) ⇒ Object



41
42
43
# File 'lib/jekyll_plugin_meta_logger.rb', line 41

def info(&block)
  @logger.info(self) { yield block }
end

#level_as_symObject



49
50
51
# File 'lib/jekyll_plugin_meta_logger.rb', line 49

def level_as_sym
  @logger.level_as_sym
end

#new_logger(klass, config = nil, stream_name = $stdout) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/jekyll_plugin_meta_logger.rb', line 61

def new_logger(klass, config = nil, stream_name = $stdout)
  @config ||= config
  if @config.nil?
    puts { 'Error: PluginMetaLogger has not been initialized with site.config.'.red }
    PluginLogger.new(klass, {}, stream_name)
  else
    PluginLogger.new(klass, @config, stream_name)
  end
end

#warn(&block) ⇒ Object



53
54
55
# File 'lib/jekyll_plugin_meta_logger.rb', line 53

def warn(&block)
  @logger.warn(self) { yield block }
end