Class: LoggerFactory

Inherits:
Object
  • Object
show all
Defined in:
logger_factory.rb

Overview

Looks within _config.yml for a key corresponding to the plugin progname. For example, if the plugin's progname has value "abc" then an entry called logger_factory.abc will be read from the config file, if present. If the entry exists, its value overrides the value specified when create_logger() was called. If no such entry is found then the log_level value specified when create_logger() was called is used.

For more information about the logging feature in the Ruby standard library,

Examples:

Create a new logger using this code like this:

LoggerFactory.new.create_logger('my_tag_name', site.config, Logger::WARN, $stderr)

See Also:

Instance Method Summary collapse

Instance Method Details

#create_logger(progname, config, log_level, stream_name) ⇒ Object

Examples:

If progname has value abc, then the YAML to override the programmatically set log_level to debug is:

logger_factory:
  abc: debug

Parameters:

  • log_level (String, Symbol, Integer)

    can be specified as $stderr or $stdout, or an integer from 0..3 (inclusive), or as a case-insensitive string (debug, info, warn, error, or DEBUG, INFO, WARN, ERROR), or as a symbol (:debug, :info, :warn, :error ).

  • config (YAML)

    is normally created by reading a YAML file such as Jekyll's _config.yml. When invoking from a Jekyll plugin, provide site.config, which is available from all types of Jekyll plugins as Jekyll.configuration({}).



33
34
35
36
37
38
39
40
41
42
43
# File 'logger_factory.rb', line 33

def create_logger(progname, config, log_level, stream_name)
  config_log_level = check_config_log_level(config: config, progname: progname)

  logger = Logger.new(stream_name)
  logger.level = config_log_level || log_level
  logger.progname = progname
  logger.formatter = proc { |severity, _, prog_name, msg|
    "#{severity} #{prog_name}: #{msg}\n"
  }
  logger
end