Class: Scarpe::Components::ModularLogImpl

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

Instance Method Summary collapse

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 '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 'lib/scarpe/components/modular_logger.rb', line 16

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