l2meter 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +5 -0
- data/README.md +21 -0
- data/lib/l2meter/configuration.rb +9 -0
- data/lib/l2meter/emitter.rb +11 -5
- data/lib/l2meter/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e7d0b5b1d2ed03198fd3d9dcf6ceeae3b8ea7e9ea33bd41357d4d8cfcaf50e7
|
4
|
+
data.tar.gz: dad33aee25c34db52c0d2bbcf81735361da935697e94448d1a59d57345127c00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85522f064c39045663580b4bfac46c99aa1ffe4b93bf5fd8bc1bef34c2c7afb938a5d62c527eb474fbfc351e3bfc2e51806c9a953225a396331ff35bdf5f3588
|
7
|
+
data.tar.gz: 98ac4f5586dd2cac47b34fc660ea408ba22370701d4b1202918cbfc4c8005d01151b1e977bd266daf99b445af7d9019bfc2a1731a58121b0d869a57f9b279269
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.15.0] 2020-05-15
|
10
|
+
|
11
|
+
### Added
|
12
|
+
- Allow outputting of true/false/nil values via a config option. ([#9](https://github.com/heroku/l2meter/pull/9))
|
13
|
+
|
9
14
|
## [0.14.0] 2020-04-16
|
10
15
|
|
11
16
|
### Added
|
data/README.md
CHANGED
@@ -235,6 +235,27 @@ logger.log my_url: "https://user:password@example.com"
|
|
235
235
|
|
236
236
|
Note that returning nil value will make l2meter omit the field completely.
|
237
237
|
|
238
|
+
### "Compacting" values
|
239
|
+
|
240
|
+
By default l2meter will treat key-value pairs where the value is `true`, `false` or `nil` differently. `false` and `nil` values will cause the whole pair to be omitted, `true` will cause just the key to be output:
|
241
|
+
|
242
|
+
```ruby
|
243
|
+
logger.log foo: "hello", bar: true # => foo=hello bar
|
244
|
+
logger.log foo: "hello", bar: false # => foo=hello
|
245
|
+
logger.log foo: "hello", bar: nil # => foo=hello
|
246
|
+
```
|
247
|
+
|
248
|
+
When the option is disabled, the full pairs are emitted:
|
249
|
+
|
250
|
+
```ruby
|
251
|
+
config.compact_values = false
|
252
|
+
logger.log foo: "hello", bar: true # => foo=hello bar=true
|
253
|
+
logger.log foo: "hello", bar: false # => foo=hello bar=false
|
254
|
+
logger.log foo: "hello", bar: nil # => foo=hello bar=null
|
255
|
+
```
|
256
|
+
|
257
|
+
Note that "null" is output in the `nil` case.
|
258
|
+
|
238
259
|
## Silence
|
239
260
|
|
240
261
|
There's a way to temporary silence the log emitter. This might be useful for
|
@@ -16,6 +16,7 @@ module L2meter
|
|
16
16
|
@output = $stdout
|
17
17
|
@float_precision = 4
|
18
18
|
@context = nil
|
19
|
+
@compact_values = true
|
19
20
|
end
|
20
21
|
|
21
22
|
def format_keys(&block)
|
@@ -30,6 +31,14 @@ module L2meter
|
|
30
31
|
@sort = !!value
|
31
32
|
end
|
32
33
|
|
34
|
+
def compact_values?
|
35
|
+
@compact_values
|
36
|
+
end
|
37
|
+
|
38
|
+
def compact_values=(value)
|
39
|
+
@compact_values = !!value
|
40
|
+
end
|
41
|
+
|
33
42
|
def context
|
34
43
|
if block_given?
|
35
44
|
@context = Proc.new
|
data/lib/l2meter/emitter.rb
CHANGED
@@ -4,6 +4,8 @@ module L2meter
|
|
4
4
|
class Emitter
|
5
5
|
attr_reader :configuration
|
6
6
|
|
7
|
+
BARE_VALUE_SENTINEL = Object.new.freeze
|
8
|
+
|
7
9
|
def initialize(configuration: Configuration.new)
|
8
10
|
@configuration = configuration
|
9
11
|
end
|
@@ -160,7 +162,7 @@ module L2meter
|
|
160
162
|
end
|
161
163
|
|
162
164
|
def source_context
|
163
|
-
{source: configuration.source}
|
165
|
+
configuration.source ? {source: configuration.source} : {}
|
164
166
|
end
|
165
167
|
|
166
168
|
def resolved_contexts
|
@@ -197,11 +199,13 @@ module L2meter
|
|
197
199
|
end
|
198
200
|
|
199
201
|
def format_token(key, value)
|
200
|
-
case
|
201
|
-
when
|
202
|
+
case
|
203
|
+
when value == true && configuration.compact_values?
|
202
204
|
key
|
203
|
-
when
|
205
|
+
when !value && configuration.compact_values?
|
204
206
|
nil
|
207
|
+
when value == BARE_VALUE_SENTINEL
|
208
|
+
key
|
205
209
|
else
|
206
210
|
value = format_value(value)
|
207
211
|
"#{key}=#{value}"
|
@@ -218,6 +222,8 @@ module L2meter
|
|
218
222
|
format_time_value(value)
|
219
223
|
when Array
|
220
224
|
value.map(&method(:format_value)).join(",")
|
225
|
+
when nil
|
226
|
+
"null"
|
221
227
|
else
|
222
228
|
format_value(value.to_s)
|
223
229
|
end
|
@@ -253,7 +259,7 @@ module L2meter
|
|
253
259
|
{}.tap do |result|
|
254
260
|
args.each do |arg|
|
255
261
|
next if arg.nil?
|
256
|
-
arg = Hash[arg,
|
262
|
+
arg = Hash[arg, BARE_VALUE_SENTINEL] unless Hash === arg
|
257
263
|
arg.each do |key, value|
|
258
264
|
result[key] = value
|
259
265
|
end
|
data/lib/l2meter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: l2meter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Pravosud
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
127
|
+
rubygems_version: 3.0.3
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: L2met friendly log formatter
|