contextual_logger 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/contextual_logger.rb +23 -0
- data/lib/contextual_logger/logger_with_context.rb +1 -21
- 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: 2982d6e312ab94acc9d71c3ed92d127f3c52c1cb
|
4
|
+
data.tar.gz: 031bc0dc6c086dbbb8f3795db550514814482b38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c07df2056f512b6190f6aee23911f0da948c9625e89b4c0acb0d2449713c84eaa468c4cd20964e2bdf3790b178cff23ccbf8818536a20b01ba41c57c1f1f6f4
|
7
|
+
data.tar.gz: c91b9641c769391a31209725ad60b2b375c89e60f337c59118cbbf092cd291a23cbceed321e9caf6acf35c3dab898c19c220a473ed3abe351758b73bcea9b43a
|
data/lib/contextual_logger.rb
CHANGED
@@ -9,6 +9,29 @@ module ContextualLogger
|
|
9
9
|
def new(logger)
|
10
10
|
logger.extend(LoggerMixin)
|
11
11
|
end
|
12
|
+
|
13
|
+
def normalize_log_level(log_level)
|
14
|
+
if log_level.is_a?(Integer) && (Logger::Severity::DEBUG..Logger::Severity::UNKNOWN).include?(log_level)
|
15
|
+
log_level
|
16
|
+
else
|
17
|
+
case log_level.to_s.downcase
|
18
|
+
when 'debug'
|
19
|
+
Logger::Severity::DEBUG
|
20
|
+
when 'info'
|
21
|
+
Logger::Severity::INFO
|
22
|
+
when 'warn'
|
23
|
+
Logger::Severity::WARN
|
24
|
+
when 'error'
|
25
|
+
Logger::Severity::ERROR
|
26
|
+
when 'fatal'
|
27
|
+
Logger::Severity::FATAL
|
28
|
+
when 'unknown'
|
29
|
+
Logger::Severity::UNKNOWN
|
30
|
+
else
|
31
|
+
raise ArgumentError, "invalid log level: #{log_level.inspect}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
12
35
|
end
|
13
36
|
|
14
37
|
module LoggerMixin
|
@@ -22,27 +22,7 @@ module ContextualLogger
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def level=(override_level)
|
25
|
-
@override_level =
|
26
|
-
if (Logger::Severity::DEBUG..Logger::Severity::UNKNOWN).include?(override_level) || override_level.nil?
|
27
|
-
override_level
|
28
|
-
else
|
29
|
-
case override_level.to_s.downcase
|
30
|
-
when 'debug'
|
31
|
-
Logger::Severity::DEBUG
|
32
|
-
when 'info'
|
33
|
-
Logger::Severity::INFO
|
34
|
-
when 'warn'
|
35
|
-
Logger::Severity::WARN
|
36
|
-
when 'error'
|
37
|
-
Logger::Severity::ERROR
|
38
|
-
when 'fatal'
|
39
|
-
Logger::Severity::FATAL
|
40
|
-
when 'unknown'
|
41
|
-
Logger::Severity::UNKNOWN
|
42
|
-
else
|
43
|
-
raise ArgumentError, "invalid log level: #{override_level.inspect}"
|
44
|
-
end
|
45
|
-
end
|
25
|
+
@override_level = (ContextualLogger.normalize_log_level(override_level) if override_level)
|
46
26
|
end
|
47
27
|
|
48
28
|
def write_entry_to_log(severity, timestamp, progname, message, context:)
|