extended_logger 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/extended_logger/extended_logger.rb +45 -41
- data/lib/extended_logger/factory.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49556d004b36ef29b6255c074ec501261fc36b51
|
4
|
+
data.tar.gz: f07f8bf086584eacc2e4294def7cd9bc3d0521a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dee76927f44546a57acc7d6549cf1881d3e3e475a36b24c9f1785de66a42eb78e3ea49b843f67e5e214baa42b64932467d54996fd14668da3b0fad279165edc2
|
7
|
+
data.tar.gz: 5dfad9653cbd53610122e28a4b4be44f9bfbb39d947fb130274971be5218730dd87c257e78043a9539e55bbbef004787903b96a97dad4c42ace1e317a4310e4e
|
@@ -1,51 +1,55 @@
|
|
1
1
|
class ExtendedLogger < Logger
|
2
|
-
|
3
|
-
|
4
|
-
setter = "#{attribute_name}=".freeze
|
2
|
+
class << self
|
3
|
+
attr_accessor :default_log_level
|
5
4
|
|
6
|
-
|
5
|
+
def configure receiver, attribute_name=nil, **overrides
|
6
|
+
attribute_name ||= 'logger'.freeze
|
7
|
+
setter = "#{attribute_name}=".freeze
|
7
8
|
|
8
|
-
|
9
|
-
end
|
9
|
+
logger = get receiver, **overrides
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
if receiver.is_a? Module
|
14
|
-
receiver.name
|
15
|
-
else
|
16
|
-
receiver.class.name
|
17
|
-
end
|
18
|
-
|
19
|
-
logger = Factory.(**overrides)
|
20
|
-
logger.progname = "(#{receiver_name})"
|
21
|
-
logger
|
22
|
-
end
|
11
|
+
receiver.public_send setter, logger
|
12
|
+
end
|
23
13
|
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
def get receiver, **overrides
|
15
|
+
receiver_name =
|
16
|
+
if receiver.is_a? Module
|
17
|
+
receiver.name
|
18
|
+
else
|
19
|
+
receiver.class.name
|
20
|
+
end
|
27
21
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
-5 => 'OPT_TRACE'.freeze,
|
33
|
-
-4 => 'OPT_DEBUG'.freeze,
|
34
|
-
-3 => 'DATA'.freeze,
|
35
|
-
-2 => 'TRACE'.freeze,
|
36
|
-
-1 => 'DEBUG'.freeze,
|
37
|
-
0 => 'INFO'.freeze,
|
38
|
-
1 => 'PASS'.freeze,
|
39
|
-
2 => 'FAIL'.freeze,
|
40
|
-
3 => 'FOCUS'.freeze,
|
41
|
-
4 => 'WARN'.freeze,
|
42
|
-
5 => 'ERROR'.freeze,
|
43
|
-
6 => 'FATAL'.freeze,
|
44
|
-
}
|
45
|
-
end
|
22
|
+
logger = Factory.(**overrides)
|
23
|
+
logger.progname = "(#{receiver_name})"
|
24
|
+
logger
|
25
|
+
end
|
46
26
|
|
47
|
-
|
48
|
-
|
27
|
+
def instance
|
28
|
+
@instance ||= Factory.()
|
29
|
+
end
|
30
|
+
|
31
|
+
def levels
|
32
|
+
@levels ||= {
|
33
|
+
-7 => 'OBSOLETE'.freeze,
|
34
|
+
-6 => 'OPT_DATA'.freeze,
|
35
|
+
-5 => 'OPT_TRACE'.freeze,
|
36
|
+
-4 => 'OPT_DEBUG'.freeze,
|
37
|
+
-3 => 'DATA'.freeze,
|
38
|
+
-2 => 'TRACE'.freeze,
|
39
|
+
-1 => 'DEBUG'.freeze,
|
40
|
+
0 => 'INFO'.freeze,
|
41
|
+
1 => 'PASS'.freeze,
|
42
|
+
2 => 'FAIL'.freeze,
|
43
|
+
3 => 'FOCUS'.freeze,
|
44
|
+
4 => 'WARN'.freeze,
|
45
|
+
5 => 'ERROR'.freeze,
|
46
|
+
6 => 'FATAL'.freeze,
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def level? level
|
51
|
+
levels.key? level
|
52
|
+
end
|
49
53
|
end
|
50
54
|
|
51
55
|
def datetime_format
|
@@ -10,6 +10,7 @@ class ExtendedLogger
|
|
10
10
|
|
11
11
|
def self.build env=nil, device: nil, level: nil
|
12
12
|
env ||= ENV
|
13
|
+
level ||= ExtendedLogger.default_log_level
|
13
14
|
|
14
15
|
instance = new env
|
15
16
|
instance.device = device if device
|
@@ -51,6 +52,7 @@ class ExtendedLogger
|
|
51
52
|
level = ENV['LOG_LEVEL'] || @level
|
52
53
|
|
53
54
|
return unless level
|
55
|
+
return level if level.is_a? Integer
|
54
56
|
|
55
57
|
level , _ = ExtendedLogger.levels.rassoc level.upcase
|
56
58
|
level
|