l2meter 0.4.1 → 0.5.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/lib/l2meter/emitter.rb +24 -25
- data/lib/l2meter/version.rb +1 -1
- 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: e9da3c4d1d2be86ce7bd40b98d85467eea70490e
|
4
|
+
data.tar.gz: 2e8a3deb41608f27ae8ddc67cbeda41938cdb454
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32ee41b3d8f5cd1c13583bea3fa05204ccef57aadcdfdcc1703a2a740ed7be288dec294fc6f6a0de8555e8b0329d79ed28a786cd28c3e5126f67fe4aecad08df
|
7
|
+
data.tar.gz: 496b78a386a8eb6968323b319db4e766b6013a8362916e609f6c1da6886fc9c90cfef5ddc510154ad81f51875e943d4573fea0de3409b4cee6350b9e7caa1449
|
data/lib/l2meter/emitter.rb
CHANGED
@@ -4,6 +4,8 @@ module L2meter
|
|
4
4
|
|
5
5
|
def initialize(configuration: Configuration.new)
|
6
6
|
@configuration = configuration
|
7
|
+
@buffer = {}
|
8
|
+
@autoflush = true
|
7
9
|
@start_times = []
|
8
10
|
@contexts = []
|
9
11
|
@outputs = []
|
@@ -63,7 +65,7 @@ module L2meter
|
|
63
65
|
push_context context_data
|
64
66
|
yield
|
65
67
|
ensure
|
66
|
-
context_data.length.times { @contexts.pop }
|
68
|
+
context_data.length.times { @contexts.pop } if block_given?
|
67
69
|
end
|
68
70
|
|
69
71
|
def clone
|
@@ -71,10 +73,11 @@ module L2meter
|
|
71
73
|
end
|
72
74
|
|
73
75
|
def batch
|
74
|
-
@
|
76
|
+
@autoflush = false
|
75
77
|
yield
|
76
78
|
ensure
|
77
|
-
|
79
|
+
@autoflush = true
|
80
|
+
flush_buffer
|
78
81
|
end
|
79
82
|
|
80
83
|
protected
|
@@ -93,8 +96,11 @@ module L2meter
|
|
93
96
|
|
94
97
|
def unwrap(*args)
|
95
98
|
params = Hash === args.last ? args.pop : {}
|
96
|
-
args
|
97
|
-
|
99
|
+
args.compact.map { |key| [key, true] }.to_h.merge(params)
|
100
|
+
end
|
101
|
+
|
102
|
+
def stringify_keys(hash)
|
103
|
+
hash.each_with_object({}) { |(k, v), a| a[k.to_s] = v }
|
98
104
|
end
|
99
105
|
|
100
106
|
def merge_contexts(params)
|
@@ -129,22 +135,9 @@ module L2meter
|
|
129
135
|
configuration.key_formatter.call(key)
|
130
136
|
end
|
131
137
|
|
132
|
-
def format_keys(params)
|
133
|
-
params.inject({}) do |normalized, (key, value)|
|
134
|
-
normalized.tap { |n| n[format_key(key)] = value }
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
138
|
def write(params)
|
139
|
-
|
140
|
-
|
141
|
-
end
|
142
|
-
|
143
|
-
emit configuration.sort?? tokens.sort : tokens
|
144
|
-
end
|
145
|
-
|
146
|
-
def emit(tokens)
|
147
|
-
output_queue.last.puts [*tokens].join(" ")
|
139
|
+
@buffer.merge! stringify_keys(params)
|
140
|
+
flush_buffer if @autoflush
|
148
141
|
end
|
149
142
|
|
150
143
|
def log_with_prefix(method, key, value, unit: nil)
|
@@ -185,11 +178,17 @@ module L2meter
|
|
185
178
|
[configuration.output, *@outputs].compact
|
186
179
|
end
|
187
180
|
|
188
|
-
def flush_buffer
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
181
|
+
def flush_buffer
|
182
|
+
tokens = @buffer.map do |key, value|
|
183
|
+
key = format_key(key)
|
184
|
+
value == true ? key : "#{key}=#{format_value(value)}"
|
185
|
+
end
|
186
|
+
|
187
|
+
tokens.sort! if configuration.sort?
|
188
|
+
|
189
|
+
output_queue.last.puts [*tokens].join(" ")
|
190
|
+
ensure
|
191
|
+
@buffer.clear
|
193
192
|
end
|
194
193
|
end
|
195
194
|
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Pravosud
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|