l2meter 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/l2meter/configuration.rb +1 -3
- data/lib/l2meter/emitter.rb +36 -28
- data/lib/l2meter/thread_safe.rb +1 -0
- data/lib/l2meter/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cbfc8921bc865126c979734995c67271967b7d2
|
4
|
+
data.tar.gz: 8f5f6484144b0a7b7dc402f01a7f4bf5eb71370b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f462a4e6cb2bbb2cf59440ceb9e4b5cece82efc834e67e4adf2c4e6abd03daee45bd9230e924c051480a2c3282a3dc6e93b49a3969bb1d692f6174a089196777
|
7
|
+
data.tar.gz: c4b23fb0182c6295ec25fac023305e6717bbdad1aa120bfd206e5f6a69a4d88f7f3292eba01e54f5de304cfba6a91f3431004488fc47dd3b9e8d5712758344ed
|
data/README.md
CHANGED
data/lib/l2meter/emitter.rb
CHANGED
@@ -10,7 +10,7 @@ module L2meter
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def log(*args)
|
13
|
-
params =
|
13
|
+
params = unwrap(*args)
|
14
14
|
params = merge_contexts(params)
|
15
15
|
|
16
16
|
if block_given?
|
@@ -50,7 +50,7 @@ module L2meter
|
|
50
50
|
log_with_prefix :sample, metric, value, unit: unit
|
51
51
|
end
|
52
52
|
|
53
|
-
def count(metric, value=1)
|
53
|
+
def count(metric, value = 1)
|
54
54
|
log_with_prefix :count, metric, value
|
55
55
|
end
|
56
56
|
|
@@ -58,11 +58,12 @@ module L2meter
|
|
58
58
|
log_with_prefix :unique, metric, value
|
59
59
|
end
|
60
60
|
|
61
|
-
def context(
|
62
|
-
|
61
|
+
def context(*context_data)
|
62
|
+
return clone_with_context(context_data) unless block_given?
|
63
|
+
push_context context_data
|
63
64
|
yield
|
64
65
|
ensure
|
65
|
-
@contexts.pop
|
66
|
+
context_data.length.times { @contexts.pop }
|
66
67
|
end
|
67
68
|
|
68
69
|
def clone
|
@@ -76,11 +77,23 @@ module L2meter
|
|
76
77
|
flush_buffer @outputs.pop
|
77
78
|
end
|
78
79
|
|
80
|
+
protected
|
81
|
+
|
82
|
+
def push_context(context_data)
|
83
|
+
@contexts.concat context_data.reverse
|
84
|
+
end
|
85
|
+
|
79
86
|
private
|
80
87
|
|
81
|
-
def
|
88
|
+
def clone_with_context(context)
|
89
|
+
clone.tap do |emitter|
|
90
|
+
emitter.push_context context
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def unwrap(*args)
|
82
95
|
params = Hash === args.last ? args.pop : {}
|
83
|
-
args = args.compact.map { |key| [
|
96
|
+
args = args.compact.map { |key| [key, true] }.to_h
|
84
97
|
args.merge(params)
|
85
98
|
end
|
86
99
|
|
@@ -102,9 +115,9 @@ module L2meter
|
|
102
115
|
end
|
103
116
|
|
104
117
|
def current_context
|
105
|
-
contexts_queue.inject({}) do |result,
|
106
|
-
|
107
|
-
result.merge(
|
118
|
+
contexts_queue.inject({}) do |result, context|
|
119
|
+
context = context.call if context.respond_to?(:call)
|
120
|
+
result.merge(unwrap(context))
|
108
121
|
end.to_a.reverse.to_h
|
109
122
|
end
|
110
123
|
|
@@ -124,19 +137,16 @@ module L2meter
|
|
124
137
|
|
125
138
|
def write(params)
|
126
139
|
tokens = format_keys(params).map do |key, value|
|
127
|
-
value == true ? key : [
|
140
|
+
value == true ? key : [key, format_value(value)] * ?=
|
128
141
|
end
|
129
142
|
|
130
|
-
tokens.sort
|
131
|
-
|
132
|
-
emit tokens
|
143
|
+
emit configuration.sort?? tokens.sort : tokens
|
133
144
|
end
|
134
145
|
|
135
146
|
def emit(tokens)
|
136
147
|
output_queue.last.puts [*tokens].join(" ")
|
137
148
|
end
|
138
149
|
|
139
|
-
|
140
150
|
def log_with_prefix(method, key, value, unit: nil)
|
141
151
|
key = [configuration.prefix, key, unit].compact * ?.
|
142
152
|
log Hash["#{method}##{key}", value]
|
@@ -145,36 +155,34 @@ module L2meter
|
|
145
155
|
def wrap(params)
|
146
156
|
write params.merge(at: :start)
|
147
157
|
|
148
|
-
result,
|
158
|
+
result, error, elapsed = execute_with_elapsed(&proc)
|
149
159
|
|
150
|
-
if
|
151
|
-
|
160
|
+
status = if error
|
161
|
+
{ at: :exception, exception: error.class, message: error.message.strip }
|
152
162
|
else
|
153
|
-
|
163
|
+
{ at: :finish }
|
154
164
|
end
|
155
165
|
|
156
|
-
|
157
|
-
|
158
|
-
write params.merge(status)
|
166
|
+
write params.merge(merge_elapsed(elapsed, status))
|
159
167
|
|
160
|
-
raise
|
168
|
+
raise error if error
|
161
169
|
|
162
170
|
result
|
163
171
|
end
|
164
172
|
|
165
173
|
def execute_with_elapsed
|
166
174
|
time_at_start = Time.now
|
167
|
-
[
|
168
|
-
rescue
|
169
|
-
[
|
175
|
+
[yield, nil, Time.now - time_at_start]
|
176
|
+
rescue Object => exception
|
177
|
+
[nil, exception, Time.now - time_at_start]
|
170
178
|
end
|
171
179
|
|
172
180
|
def contexts_queue
|
173
|
-
[
|
181
|
+
[configuration.context, *@contexts].compact
|
174
182
|
end
|
175
183
|
|
176
184
|
def output_queue
|
177
|
-
[
|
185
|
+
[configuration.output, *@outputs].compact
|
178
186
|
end
|
179
187
|
|
180
188
|
def flush_buffer(buffer)
|
data/lib/l2meter/thread_safe.rb
CHANGED
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.4.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-
|
11
|
+
date: 2016-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
version: '0'
|
46
46
|
requirements: []
|
47
47
|
rubyforge_project:
|
48
|
-
rubygems_version: 2.
|
48
|
+
rubygems_version: 2.5.2
|
49
49
|
signing_key:
|
50
50
|
specification_version: 4
|
51
51
|
summary: L2met friendly log formatter
|