Class: CemAcpt::Logging::MultiLogger
- Inherits:
-
Object
- Object
- CemAcpt::Logging::MultiLogger
show all
- Defined in:
- lib/cem_acpt/logging.rb
Overview
Delegator class for when you want to log to multiple devices at the same time, such as STDOUT and a file.
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*logger_instances) ⇒ MultiLogger
40
41
42
|
# File 'lib/cem_acpt/logging.rb', line 40
def initialize(*logger_instances)
@loggers = logger_instances
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/cem_acpt/logging.rb', line 48
def method_missing(m, *args, &block)
if loggers.all? { |l| l.respond_to?(m) }
loggers.map { |l| l.send(m, *args, &block) }
else
super
end
end
|
Class Method Details
.from_logger_configs(configs) ⇒ MultiLogger
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/cem_acpt/logging.rb', line 28
def self.from_logger_configs(configs)
return if configs.nil? || configs.empty?
logger_instances = configs.map do |config|
CemAcpt::Logging::Logger.new(config[:logdev],
config[:shift_age],
config[:shift_size],
**config.reject { |k, _| [:logdev, :shift_age, :shift_size].include?(k) })
end
new(*logger_instances)
end
|
Instance Method Details
#logger_configs ⇒ Object
44
45
46
|
# File 'lib/cem_acpt/logging.rb', line 44
def logger_configs
loggers.map(&:config_hash)
end
|
#respond_to_missing?(m, include_private = false) ⇒ Boolean
56
57
58
|
# File 'lib/cem_acpt/logging.rb', line 56
def respond_to_missing?(m, include_private = false)
loggers.all? { |l| l.respond_to?(m) } || super
end
|