Class: LogStashLogger::MultiLogger
- Inherits:
-
Logger
- Object
- Logger
- LogStashLogger::MultiLogger
show all
- Defined in:
- lib/logstash-logger/multi_logger.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#<<(msg) ⇒ Object
-
#add(severity, message = nil, progname = nil, &block) ⇒ Object
Methods that write to logs just write to each contained logger in turn.
-
#close ⇒ Object
-
#datetime_format=(datetime_format) ⇒ Object
-
#debug(progname = nil, &block) ⇒ Object
-
#error(progname = nil, &block) ⇒ Object
-
#fatal(progname = nil, &block) ⇒ Object
-
#formatter=(formatter) ⇒ Object
-
#info(progname = nil, &block) ⇒ Object
-
#initialize(loggers) ⇒ MultiLogger
constructor
Synopsis.
-
#level=(value) ⇒ Object
-
#method_missing(name, *args, &block) ⇒ Object
Any method not defined on standard Logger class, just send it on to anyone who will listen.
-
#progname=(value) ⇒ Object
-
#unknown(progname = nil, &block) ⇒ Object
-
#warn(progname = nil, &block) ⇒ Object
Constructor Details
#initialize(loggers) ⇒ MultiLogger
Synopsis
MultiLogger.new([logger1, logger2])
Args
loggers
-
An array of loggers. Each one gets every message that is sent to the MultiLogger instance
Description
Create an instance.
57
58
59
60
61
|
# File 'lib/logstash-logger/multi_logger.rb', line 57
def initialize(loggers)
@loggers = []
super(nil)
@loggers = Array(loggers)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Any method not defined on standard Logger class, just send it on to anyone who will listen
35
36
37
38
39
40
41
|
# File 'lib/logstash-logger/multi_logger.rb', line 35
def method_missing(name, *args, &block)
@loggers.each do |logger|
if logger.respond_to?(name)
logger.send(name, args, &block)
end
end
end
|
Instance Attribute Details
#loggers ⇒ Object
Array of Loggers to be logged to. These can be anything that acts reasonably like a Logger.
32
33
34
|
# File 'lib/logstash-logger/multi_logger.rb', line 32
def loggers
@loggers
end
|
Instance Method Details
#<<(msg) ⇒ Object
70
71
72
73
74
|
# File 'lib/logstash-logger/multi_logger.rb', line 70
def <<(msg)
@loggers.each do |logger|
logger << msg
end
end
|
#add(severity, message = nil, progname = nil, &block) ⇒ Object
Methods that write to logs just write to each contained logger in turn
64
65
66
67
68
|
# File 'lib/logstash-logger/multi_logger.rb', line 64
def add(severity, message = nil, progname = nil, &block)
@loggers.each do |logger|
logger.add(severity, message, progname, &block)
end
end
|
#close ⇒ Object
112
113
114
115
116
|
# File 'lib/logstash-logger/multi_logger.rb', line 112
def close
@loggers.each do |logger|
logger.close if logger.respond_to?(:close)
end
end
|
18
19
20
21
22
23
|
# File 'lib/logstash-logger/multi_logger.rb', line 18
def datetime_format=(datetime_format)
super
@loggers.each do |logger|
logger.datetime_format = datetime_format
end
end
|
#debug(progname = nil, &block) ⇒ Object
76
77
78
79
80
|
# File 'lib/logstash-logger/multi_logger.rb', line 76
def debug(progname = nil, &block)
@loggers.each do |logger|
logger.debug(progname, &block)
end
end
|
#error(progname = nil, &block) ⇒ Object
94
95
96
97
98
|
# File 'lib/logstash-logger/multi_logger.rb', line 94
def error(progname = nil, &block)
@loggers.each do |logger|
logger.error(progname, &block)
end
end
|
#fatal(progname = nil, &block) ⇒ Object
100
101
102
103
104
|
# File 'lib/logstash-logger/multi_logger.rb', line 100
def fatal(progname = nil, &block)
@loggers.each do |logger|
logger.fatal(progname, &block)
end
end
|
25
26
27
28
29
|
# File 'lib/logstash-logger/multi_logger.rb', line 25
def formatter=(formatter)
@loggers.each do |logger|
logger.formatter = formatter
end
end
|
#info(progname = nil, &block) ⇒ Object
82
83
84
85
86
|
# File 'lib/logstash-logger/multi_logger.rb', line 82
def info(progname = nil, &block)
@loggers.each do |logger|
logger.info(progname, &block)
end
end
|
#level=(value) ⇒ Object
4
5
6
7
8
9
|
# File 'lib/logstash-logger/multi_logger.rb', line 4
def level=(value)
super
@loggers.each do |logger|
logger.level = value
end
end
|
#progname=(value) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/logstash-logger/multi_logger.rb', line 11
def progname=(value)
super
@loggers.each do |logger|
logger.progname = value
end
end
|
#unknown(progname = nil, &block) ⇒ Object
106
107
108
109
110
|
# File 'lib/logstash-logger/multi_logger.rb', line 106
def unknown(progname = nil, &block)
@loggers.each do |logger|
logger.unknown(progname, &block)
end
end
|
#warn(progname = nil, &block) ⇒ Object
88
89
90
91
92
|
# File 'lib/logstash-logger/multi_logger.rb', line 88
def warn(progname = nil, &block)
@loggers.each do |logger|
logger.warn(progname, &block)
end
end
|