extended_logger 0.2.0 → 0.2.2
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 +20 -5
- data/lib/extended_logger/factory.rb +13 -5
- data/lib/extended_logger/formatter.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8eaf6105561ba3767b626ba5280ee60c95f5c027
|
4
|
+
data.tar.gz: f1cf569de14519bf5c9f4e8fd0bd29f1ddbff36b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92c3d28ac34a3e4d1c3e9a340c8a96bc2682107732241c5defe79c154406072a5687a86f2a3e744151fc8448ae2f6224820de5571d1e260a0fab790c6d0abd76
|
7
|
+
data.tar.gz: 74fb2c6aa36af8091425802fbd4f877b5d632815c68ba50c037ee4d98dbcf67671c13a3f1ba17977de148580d997dc9c4b1da4793ac9909e5b23ccf1d1a11f9e
|
@@ -1,14 +1,14 @@
|
|
1
1
|
class ExtendedLogger < Logger
|
2
|
-
def self.configure receiver, attribute_name=nil
|
2
|
+
def self.configure receiver, attribute_name=nil, **overrides
|
3
3
|
attribute_name ||= 'logger'.freeze
|
4
4
|
setter = "#{attribute_name}=".freeze
|
5
5
|
|
6
|
-
logger = get receiver
|
6
|
+
logger = get receiver, **overrides
|
7
7
|
|
8
8
|
receiver.public_send setter, logger
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.get receiver
|
11
|
+
def self.get receiver, **overrides
|
12
12
|
receiver_name =
|
13
13
|
if receiver.is_a? Module
|
14
14
|
receiver.name
|
@@ -16,8 +16,7 @@ class ExtendedLogger < Logger
|
|
16
16
|
receiver.class.name
|
17
17
|
end
|
18
18
|
|
19
|
-
logger = Factory.()
|
20
|
-
|
19
|
+
logger = Factory.(**overrides)
|
21
20
|
logger.progname = "(#{receiver_name})"
|
22
21
|
logger
|
23
22
|
end
|
@@ -49,6 +48,14 @@ class ExtendedLogger < Logger
|
|
49
48
|
levels.key? level
|
50
49
|
end
|
51
50
|
|
51
|
+
def datetime_format
|
52
|
+
formatter.datetime_format
|
53
|
+
end
|
54
|
+
|
55
|
+
def datetime_format= format
|
56
|
+
formatter.datetime_format = format
|
57
|
+
end
|
58
|
+
|
52
59
|
def format_severity severity
|
53
60
|
unless self.class.level? severity
|
54
61
|
Kernel.warn "(extended-logger) Unknown log severity level #{severity.inspect}"
|
@@ -57,6 +64,14 @@ class ExtendedLogger < Logger
|
|
57
64
|
self.class.levels.fetch severity, 'ANY'.freeze
|
58
65
|
end
|
59
66
|
|
67
|
+
def formatter= formatter
|
68
|
+
if self.formatter.is_a? Formatter
|
69
|
+
self.formatter.logger_formatter = formatter
|
70
|
+
else
|
71
|
+
super
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
60
75
|
def io
|
61
76
|
return unless @logdev
|
62
77
|
@logdev.dev
|
@@ -1,14 +1,20 @@
|
|
1
1
|
class ExtendedLogger
|
2
2
|
class Factory
|
3
3
|
attr_reader :env
|
4
|
+
attr_writer :device
|
5
|
+
attr_writer :level
|
4
6
|
|
5
7
|
def initialize env
|
6
8
|
@env = env
|
7
9
|
end
|
8
10
|
|
9
|
-
def self.build env=nil
|
11
|
+
def self.build env=nil, device: nil, level: nil
|
10
12
|
env ||= ENV
|
11
|
-
|
13
|
+
|
14
|
+
instance = new env
|
15
|
+
instance.device = device if device
|
16
|
+
instance.level = level if level
|
17
|
+
instance
|
12
18
|
end
|
13
19
|
|
14
20
|
def self.call *arguments
|
@@ -38,12 +44,14 @@ class ExtendedLogger
|
|
38
44
|
end
|
39
45
|
|
40
46
|
def device
|
41
|
-
ENV['LOG_DEVICE'] || $stderr
|
47
|
+
ENV['LOG_DEVICE'] or @device || $stderr
|
42
48
|
end
|
43
49
|
|
44
50
|
def level
|
45
|
-
|
46
|
-
|
51
|
+
level = ENV['LOG_LEVEL'] || @level
|
52
|
+
|
53
|
+
if level
|
54
|
+
level , _ = ExtendedLogger.levels.rassoc level.upcase
|
47
55
|
level
|
48
56
|
end
|
49
57
|
end
|
@@ -18,6 +18,14 @@ class ExtendedLogger
|
|
18
18
|
log_entry
|
19
19
|
end
|
20
20
|
|
21
|
+
def datetime_format
|
22
|
+
logger_formatter.datetime_format
|
23
|
+
end
|
24
|
+
|
25
|
+
def datetime_format= format
|
26
|
+
logger_formatter.datetime_format = format
|
27
|
+
end
|
28
|
+
|
21
29
|
def delegate *arguments, message
|
22
30
|
message = format_message message, arguments
|
23
31
|
logger_formatter.(*arguments, message)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: extended_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Ladd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
extended-logger provides a richer logger implementation than the built in ruby
|