logger_extension 0.0.2 → 0.0.2.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,60 +1,62 @@
|
|
1
|
-
|
1
|
+
module LoggerExtension
|
2
|
+
class MultiIOLogger
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
class LogDeviceMutex
|
5
|
+
include MonitorMixin
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :default_formatter
|
9
|
+
attr_accessor :default_progname
|
10
|
+
|
11
|
+
def initialize(*targets)
|
12
|
+
@targets = targets
|
13
|
+
@default_formatter = ::LoggerExtension::Formatter.new
|
14
|
+
@mutex = LogDeviceMutex.new
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
def write(*arguments)
|
18
|
+
@targets.each { |target|
|
19
|
+
begin
|
20
|
+
@mutex.synchronize do
|
21
|
+
begin
|
22
|
+
target.write(*arguments)
|
23
|
+
rescue
|
24
|
+
log_exception('WARN', 'log writing failed.--->', $!)
|
25
|
+
end
|
24
26
|
end
|
27
|
+
rescue Exception => ignored
|
28
|
+
log_exception('WARN', 'log writing failed.--->', ignored)
|
25
29
|
end
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
}
|
30
|
-
end
|
30
|
+
}
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
def close
|
34
|
+
@targets.each do |target|
|
35
|
+
begin
|
36
|
+
@mutex.synchronize do
|
37
|
+
target.close rescue nil
|
38
|
+
end
|
39
|
+
rescue Exception
|
36
40
|
target.close rescue nil
|
37
41
|
end
|
38
|
-
rescue Exception
|
39
|
-
target.close rescue nil
|
40
42
|
end
|
41
43
|
end
|
42
|
-
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
def datetime_format=(format)
|
49
|
-
default_formatter.datetime_format = format
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
def log_exception(severity, message, exception)
|
54
|
-
write_message(message.to_s + default_formatter.call(severity, Time.now, default_progname, exception).to_s)
|
45
|
+
def datetime_format
|
46
|
+
default_formatter.datetime_format
|
55
47
|
end
|
56
48
|
|
57
|
-
def
|
58
|
-
|
49
|
+
def datetime_format=(format)
|
50
|
+
default_formatter.datetime_format = format
|
59
51
|
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def log_exception(severity, message, exception)
|
55
|
+
write_message(message.to_s + default_formatter.call(severity, Time.now, default_progname, exception).to_s)
|
56
|
+
end
|
57
|
+
|
58
|
+
def write_message(message)
|
59
|
+
STDOUT.write message
|
60
|
+
end
|
61
|
+
end
|
60
62
|
end
|