logger_extension 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8fc1b3b6c4822d517838020352573dbf0db8fff
|
4
|
+
data.tar.gz: d5437f5da461a0017eca85a4c63679de5f5ca352
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d1612ef5cf46995a1461552a68a88c9184f1d9e4675d3ff785bd0f76dc97122c85c5a8a8687379348c39a91d302de47610c19490e82afd78ab4889c37a56550
|
7
|
+
data.tar.gz: 0af4b74bae32ae1eacaac26618f95fe712954966b5ef409221602a23507662f612ba1d6ec5eaaa4b827f4b0eb8be09507d35c72777f5a21d09ca66edbf7b0ad2
|
@@ -1,59 +1,11 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
class MultiIOLogger
|
4
|
-
extend Forwardable
|
1
|
+
require 'logger'
|
2
|
+
require 'logger_extension/multiple_devise'
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
attr_reader :default_formatter
|
11
|
-
attr_accessor :default_progname
|
4
|
+
module LoggerExtension
|
5
|
+
class MultiIOLogger < Logger
|
12
6
|
|
13
7
|
def initialize(*targets)
|
14
|
-
|
15
|
-
@default_formatter = ::LoggerExtension::Formatter.new
|
16
|
-
@mutex = LogDeviceMutex.new
|
17
|
-
end
|
18
|
-
|
19
|
-
def_delegator :@default_formatter, :datetime_format
|
20
|
-
def_delegator :@default_formatter, :datetime_format=
|
21
|
-
|
22
|
-
def write(*arguments)
|
23
|
-
@targets.each { |target|
|
24
|
-
begin
|
25
|
-
@mutex.synchronize do
|
26
|
-
begin
|
27
|
-
target.write(*arguments)
|
28
|
-
rescue
|
29
|
-
log_exception('WARN', 'log writing failed.--->', $!)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
rescue Exception => ignored
|
33
|
-
log_exception('WARN', 'log writing failed.--->', ignored)
|
34
|
-
end
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
def close
|
39
|
-
@targets.each do |target|
|
40
|
-
begin
|
41
|
-
@mutex.synchronize do
|
42
|
-
target.close rescue nil
|
43
|
-
end
|
44
|
-
rescue Exception
|
45
|
-
target.close rescue nil
|
46
|
-
end
|
47
|
-
end
|
8
|
+
super(MultipleDevise.new(*targets))
|
48
9
|
end
|
49
|
-
|
50
|
-
private
|
51
|
-
def log_exception(severity, message, exception)
|
52
|
-
write_message(message.to_s + default_formatter.call(severity, Time.now, default_progname, exception).to_s)
|
53
|
-
end
|
54
|
-
|
55
|
-
def write_message(message)
|
56
|
-
STDOUT.write message
|
57
|
-
end
|
58
10
|
end
|
59
|
-
end
|
11
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
module LoggerExtension
|
3
|
+
class MultipleDevise
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
class LogDeviceMutex
|
7
|
+
include MonitorMixin
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :default_formatter
|
11
|
+
attr_accessor :default_progname
|
12
|
+
|
13
|
+
def initialize(*targets)
|
14
|
+
@targets = targets.each { |target| target.sync = true if target.respond_to?(:sync=) }
|
15
|
+
@default_formatter = ::LoggerExtension::Formatter.new
|
16
|
+
@mutex = LogDeviceMutex.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def_delegator :@default_formatter, :datetime_format
|
20
|
+
def_delegator :@default_formatter, :datetime_format=
|
21
|
+
|
22
|
+
def write(*arguments)
|
23
|
+
@targets.each { |target|
|
24
|
+
begin
|
25
|
+
@mutex.synchronize do
|
26
|
+
begin
|
27
|
+
target.write(*arguments)
|
28
|
+
rescue
|
29
|
+
log_exception('WARN', 'log writing failed.--->', $!)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
rescue Exception => ignored
|
33
|
+
log_exception('WARN', 'log writing failed.--->', ignored)
|
34
|
+
end
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def close
|
39
|
+
@targets.each do |target|
|
40
|
+
begin
|
41
|
+
@mutex.synchronize do
|
42
|
+
target.close rescue nil
|
43
|
+
end
|
44
|
+
rescue Exception
|
45
|
+
target.close rescue nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def log_exception(severity, message, exception)
|
52
|
+
write_message(message.to_s + default_formatter.call(severity, Time.now, default_progname, exception).to_s)
|
53
|
+
end
|
54
|
+
|
55
|
+
def write_message(message)
|
56
|
+
STDOUT.write message
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logger_extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kuldeepaggarwal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A utility for logging on multiple files for rack applications
|
14
14
|
email:
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- lib/logger_extension.rb
|
26
26
|
- lib/logger_extension/formatter.rb
|
27
27
|
- lib/logger_extension/multi_i_o_logger.rb
|
28
|
+
- lib/logger_extension/multiple_devise.rb
|
28
29
|
- lib/logger_extension/version.rb
|
29
30
|
- logger_extension.gemspec
|
30
31
|
homepage: https://github.com/kuldeepaggarwal/logger_extension
|