lorekeeper 1.7.2 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +18 -0
- data/Rakefile +4 -4
- data/lib/lorekeeper/json_logger.rb +24 -14
- data/lib/lorekeeper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b72498ad2cf067d82c9371e7affa84ce85974332d2eaa962d34fa9b687ff897f
|
4
|
+
data.tar.gz: af9356d08c95dbadd903dd340a3a3acbe8f1d26768333e20add816f232f93bf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1e4267df3ae911fccb7245e22f6c8271df78e4d454e39740fb966cb881cadeb27ee67cfef54b3f580ffa554bd1c0370895c9287af6b5c25a8fd5dd8ed90659e
|
7
|
+
data.tar.gz: a7e7c0f9c916abf6bb575053ba6a5ce29832ff0eb0f4bdc7f9044bd2a615c0eacb5f6c0a9aa32e063d11bcce83f68fa67ecc86875b379db9f9e3bc77efee22b3
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -169,6 +169,24 @@ Will output:
|
|
169
169
|
}
|
170
170
|
```
|
171
171
|
|
172
|
+
Alternatively you can use named parameters:
|
173
|
+
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
rescue => e
|
177
|
+
logger.exception(e, message: "custom msg!", data: { some: { data: 123 } }, level: :warn)
|
178
|
+
end
|
179
|
+
```
|
180
|
+
|
181
|
+
This is specially useful when there is no custom message or data:
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
rescue => e
|
185
|
+
logger.exception(e, level: :warn)
|
186
|
+
end
|
187
|
+
```
|
188
|
+
|
189
|
+
|
172
190
|
|
173
191
|
## License
|
174
192
|
|
data/Rakefile
CHANGED
@@ -50,10 +50,10 @@ task :benchmark do
|
|
50
50
|
simple_log = create_simple_logger
|
51
51
|
|
52
52
|
Benchmark.ips do |bm|
|
53
|
-
bm.report('short content') { log.
|
54
|
-
bm.report('Logger short content') { simple_log.
|
55
|
-
bm.report('long content') { log.
|
56
|
-
bm.report('Logger long content') { simple_log.
|
53
|
+
bm.report('JSON short content') { log.debug(contents) }
|
54
|
+
bm.report('Logger short content') { simple_log.debug(contents) }
|
55
|
+
bm.report('JSON long content') { log.debug(long_contents) }
|
56
|
+
bm.report('Logger long content') { simple_log.debug(long_contents) }
|
57
57
|
bm.compare!
|
58
58
|
end
|
59
59
|
|
@@ -29,7 +29,7 @@ module Lorekeeper
|
|
29
29
|
LOGGING_METHODS.each do |method_name|
|
30
30
|
define_method "#{method_name}_with_data", ->(message_param = nil, data = {}, &block) do
|
31
31
|
return true if METHOD_SEVERITY_MAP[method_name] < @level
|
32
|
-
extra_fields = {
|
32
|
+
extra_fields = { DATA => (data || {}) }
|
33
33
|
with_extra_fields(extra_fields) { # Using do/end here only valid on Ruby>= 2.3
|
34
34
|
add(METHOD_SEVERITY_MAP[method_name], message_param, nil, &block)
|
35
35
|
}
|
@@ -61,25 +61,31 @@ module Lorekeeper
|
|
61
61
|
end
|
62
62
|
|
63
63
|
# @param exception: instance of a class inheriting from Exception
|
64
|
-
#
|
65
|
-
#
|
66
|
-
def exception(exception, custom_message = nil, custom_data = nil,
|
67
|
-
|
64
|
+
# By default message comes from exception.message
|
65
|
+
# Optional and named parameters to overwrite message, level and add data
|
66
|
+
def exception(exception, custom_message = nil, custom_data = nil, custom_level = :error,
|
67
|
+
message: nil, data: nil, level: nil) # Backwards compatible named params
|
68
|
+
|
69
|
+
param_level = level || custom_level
|
70
|
+
param_data = data || custom_data
|
71
|
+
param_message = message || custom_message
|
72
|
+
|
73
|
+
log_level = METHOD_SEVERITY_MAP[param_level] || ERROR
|
68
74
|
|
69
75
|
if exception.is_a?(Exception)
|
70
76
|
backtrace = exception.backtrace || []
|
71
77
|
exception_fields = {
|
72
|
-
|
73
|
-
|
78
|
+
EXCEPTION => "#{exception.class}: #{exception.message}",
|
79
|
+
STACK => backtrace
|
74
80
|
}
|
75
|
-
exception_fields[
|
81
|
+
exception_fields[DATA] = param_data if param_data
|
76
82
|
|
77
|
-
message =
|
83
|
+
message = param_message || exception.message
|
78
84
|
with_extra_fields(exception_fields) { log_data(log_level, message) }
|
79
85
|
else
|
80
86
|
log_data(METHOD_SEVERITY_MAP[:warn], 'Logger exception called without exception class.')
|
81
|
-
message = "#{exception.class}: #{exception.inspect} #{
|
82
|
-
with_extra_fields(
|
87
|
+
message = "#{exception.class}: #{exception.inspect} #{param_message}"
|
88
|
+
with_extra_fields(DATA => (param_data || {})) { log_data(log_level, message) }
|
83
89
|
end
|
84
90
|
end
|
85
91
|
|
@@ -94,6 +100,9 @@ module Lorekeeper
|
|
94
100
|
MESSAGE = 'message'
|
95
101
|
TIMESTAMP = 'timestamp'
|
96
102
|
DATE_FORMAT = '%FT%T.%6NZ'
|
103
|
+
EXCEPTION = 'exception'
|
104
|
+
STACK = 'stack'
|
105
|
+
DATA = 'data'
|
97
106
|
|
98
107
|
def with_extra_fields(fields)
|
99
108
|
state[:extra_fields] = fields
|
@@ -108,11 +117,12 @@ module Lorekeeper
|
|
108
117
|
end
|
109
118
|
|
110
119
|
def log_data(severity, message)
|
120
|
+
current_state = state # Accessing state is slow. Do it only once per call.
|
111
121
|
# merging is slow, we do not want to merge with empty hash if possible
|
112
|
-
fields_to_log = if
|
113
|
-
|
122
|
+
fields_to_log = if current_state[:extra_fields].empty?
|
123
|
+
current_state[:base_fields]
|
114
124
|
else
|
115
|
-
|
125
|
+
current_state[:base_fields].merge(current_state[:extra_fields])
|
116
126
|
end
|
117
127
|
|
118
128
|
fields_to_log[MESSAGE] = message
|
data/lib/lorekeeper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lorekeeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordi Polo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|