Class: Scarpe::Components::ModularLogImpl

Inherits:
Object
  • Object
show all
Includes:
Shoes::Log
Defined in:
scarpe-components/lib/scarpe/components/modular_logger.rb

Constant Summary

Constants included from Shoes::Log

Shoes::Log::DEFAULT_COMPONENT, Shoes::Log::DEFAULT_DEBUG_LOG_CONFIG, Shoes::Log::DEFAULT_LOG_CONFIG

Instance Method Summary collapse

Methods included from Shoes::Log

configure_logger, #log_init, logger

Instance Method Details

#configure_logger(log_config) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'scarpe-components/lib/scarpe/components/modular_logger.rb', line 82

def configure_logger(log_config)
  # TODO: custom coloring? https://github.com/TwP/logging/blob/master/examples/colorization.rb
  @custom_log_layout = Logging.layouts.pattern pattern: '[%r] %-5l %c: %m\n'

  if log_config.is_a?(String) && File.exist?(log_config)
    log_config = JSON.load_file(log_config)
  end

  log_config = freeze_log_config(log_config) unless log_config.nil?
  @current_log_config = log_config # Save a copy for later

  Logging.reset # Reset all Logging settings to defaults
  Logging.reopen # For log-reconfig (e.g. test failures), often important to *not* store an open handle to a moved file
  return if log_config.nil?

  Logging.logger.root.appenders = [Logging.appenders.stdout]

  default_logger = log_config[DEFAULT_COMPONENT] || "info"
  json_configure_logger(Logging.logger.root, default_logger)

  log_config.each do |component, logger_data|
    next if component == DEFAULT_COMPONENT

    sublogger = Logging.logger[component]
    json_configure_logger(sublogger, logger_data)
  end
end

#logger_for_component(component) ⇒ Object



16
17
18
# File 'scarpe-components/lib/scarpe/components/modular_logger.rb', line 16

def logger_for_component(component)
  Logging.logger[component]
end