l2meter 0.2.2 → 0.2.3
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/README.md +26 -26
- data/lib/l2meter/emitter.rb +1 -2
- data/lib/l2meter/thread_safe.rb +2 -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: ff38c2bf5a18c7b5ef4e31ad3c666fbee6b407cb
|
4
|
+
data.tar.gz: 31669b5e89ec8eb3e796cedbdf9d68f82a845bcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cb1ac63e7dc949d269197cfc058eb76bb37f30c481dfe0067857b0c0075e839fa7a01026e57949d73709abe343bf3a22cb8ffab643f151dc86bd69f7e00a8d6
|
7
|
+
data.tar.gz: 9f776b18885290732ddff9c4b03d56fb5cbbb70f04af7bce286d3580f3a66d932941b9565afc93336fe1399bfdcd33fe3a3c704d56681b0dd96f5712cd0ee787
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ l2met-friendly format.
|
|
11
11
|
A new logger might be created like so:
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
|
14
|
+
Metrics = L2meter.build
|
15
15
|
```
|
16
16
|
|
17
17
|
If you plan to use it globally across different components of your app,consider
|
@@ -21,8 +21,8 @@ The base `log` method accepts two type of things: bare values and key-value
|
|
21
21
|
pairs in form of hashes.
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
|
25
|
-
|
24
|
+
Metrics.log "Hello world" # => hello-world
|
25
|
+
Metrics.log :db_query, result: :success # => db-query result=success
|
26
26
|
```
|
27
27
|
|
28
28
|
It can also take a block. In this case the message will be emitted twice, once
|
@@ -30,9 +30,9 @@ at the start of the execution and another at the end. The end result might look
|
|
30
30
|
like so:
|
31
31
|
|
32
32
|
```ruby
|
33
|
-
|
33
|
+
Metrics.log :doing_work do # => doing-work at=start
|
34
34
|
do_some_work #
|
35
|
-
|
35
|
+
Metrics.log :work_done # => work-done
|
36
36
|
end # => doing-work at=finish elapsed=1.2345s
|
37
37
|
```
|
38
38
|
|
@@ -40,7 +40,7 @@ In case the exception is raised inside the block, l2meter will report is like
|
|
40
40
|
so:
|
41
41
|
|
42
42
|
```ruby
|
43
|
-
|
43
|
+
Metrics.log :doing_work do # => doing-work
|
44
44
|
raise ArgumentError, \ #
|
45
45
|
"something is wrong" #
|
46
46
|
end # => doing-work at=exception exception=ArgumentError message="something is wrong" elapsed=1.2345s
|
@@ -54,7 +54,7 @@ L2meter allows setting context for a block. It might work something like this:
|
|
54
54
|
def do_work_with_retries
|
55
55
|
attempt = 1
|
56
56
|
begin
|
57
|
-
|
57
|
+
Metrics.context attempt: attempt do
|
58
58
|
do_some_work # => doing-work attempt=1
|
59
59
|
# => doing-work attempt=2
|
60
60
|
# => doing-work attempt=3
|
@@ -67,14 +67,14 @@ end
|
|
67
67
|
```
|
68
68
|
|
69
69
|
L2meter supports dynamic contexts as well. You can pass a proc instead of raw
|
70
|
-
value in
|
70
|
+
value in order to use it.
|
71
71
|
|
72
|
-
The same example as above could be written like
|
72
|
+
The same example as above could be re-written like this instead:
|
73
73
|
|
74
74
|
```ruby
|
75
75
|
def do_work_with_retries
|
76
76
|
attempt = 1
|
77
|
-
|
77
|
+
Metrics.context ->{{ attempt: attempt }} do
|
78
78
|
begin
|
79
79
|
do_some_work
|
80
80
|
rescue => error
|
@@ -90,22 +90,22 @@ end
|
|
90
90
|
Some other l2met-specific methods are supported.
|
91
91
|
|
92
92
|
```ruby
|
93
|
-
|
94
|
-
|
93
|
+
Metrics.count :user_registered # => count#user-registered=1
|
94
|
+
Metrics.count :registered_users, 10 # => count#registered-users=10
|
95
95
|
|
96
|
-
|
97
|
-
|
96
|
+
Metrics.measure :connection_count, 20 # => measure#connection-count=20
|
97
|
+
Metrics.measure :db_query, 235, unit: :ms, # => measure#db-query.ms=235
|
98
98
|
|
99
|
-
|
100
|
-
|
99
|
+
Metrics.sample :connection_count, 20, # => sample#connection-count=235
|
100
|
+
Metrics.sample :db_query, 235, unit: :ms, # => sample#db-query.ms=235
|
101
101
|
|
102
|
-
|
102
|
+
Metrics.unique :user, "bob@example.com" # => unique#user=bob@example.com
|
103
103
|
```
|
104
104
|
|
105
105
|
L2meter also allows to append elapsed time to your log messages automatically.
|
106
106
|
|
107
107
|
```ruby
|
108
|
-
|
108
|
+
Metrics.with_elapsed do
|
109
109
|
do_work_step_1
|
110
110
|
log :step_1_done # => step-1-done elapsed=1.2345s
|
111
111
|
do_work_step_2
|
@@ -118,7 +118,7 @@ end
|
|
118
118
|
L2meter supports configuration. Here's how you can configure things:
|
119
119
|
|
120
120
|
```ruby
|
121
|
-
|
121
|
+
Metrics = L2meter.build do |config|
|
122
122
|
# configuration happens here
|
123
123
|
end
|
124
124
|
```
|
@@ -134,7 +134,7 @@ config.context = { app_name: "my-app-name" }
|
|
134
134
|
|
135
135
|
# ...
|
136
136
|
|
137
|
-
|
137
|
+
Metrics.log foo: :bar # => app-name=my-app-name foo-bar
|
138
138
|
```
|
139
139
|
|
140
140
|
Dynamic context is also supported:
|
@@ -155,7 +155,7 @@ config.sort = true
|
|
155
155
|
|
156
156
|
# ...
|
157
157
|
|
158
|
-
|
158
|
+
Metrics.log :c, :b, :a # => a b c
|
159
159
|
```
|
160
160
|
|
161
161
|
#### Source
|
@@ -167,7 +167,7 @@ config.source = "production"
|
|
167
167
|
|
168
168
|
# ...
|
169
169
|
|
170
|
-
|
170
|
+
Metrics.log foo: :bar # => source=production foo=bar
|
171
171
|
```
|
172
172
|
|
173
173
|
#### Prefix
|
@@ -179,7 +179,7 @@ config.prefix = "my-app"
|
|
179
179
|
|
180
180
|
# ...
|
181
181
|
|
182
|
-
|
182
|
+
Metrics.count :users, 100500 # => count#my-app.users=100500
|
183
183
|
```
|
184
184
|
|
185
185
|
## Silence
|
@@ -188,13 +188,13 @@ There's a way to temporary silence the log emitter. This might be userful for
|
|
188
188
|
tests for example.
|
189
189
|
|
190
190
|
```ruby
|
191
|
-
|
191
|
+
Metrics.silence do
|
192
192
|
# logger is completely silenced
|
193
|
-
|
193
|
+
Metrics.log "hello world" # nothing is emitted here
|
194
194
|
end
|
195
195
|
|
196
196
|
# works normally again
|
197
|
-
|
197
|
+
Metrics.log :foo # => foo
|
198
198
|
```
|
199
199
|
|
200
200
|
The typical setup for RSpec might look like this:
|
data/lib/l2meter/emitter.rb
CHANGED
@@ -73,7 +73,7 @@ module L2meter
|
|
73
73
|
|
74
74
|
def transform_log_args(*args)
|
75
75
|
params = Hash === args.last ? args.pop : {}
|
76
|
-
args = args.map { |key| [ key, true ] }.to_h
|
76
|
+
args = args.compact.map { |key| [ key, true ] }.to_h
|
77
77
|
args.merge(params)
|
78
78
|
end
|
79
79
|
|
@@ -152,7 +152,6 @@ module L2meter
|
|
152
152
|
|
153
153
|
def execute_with_elapsed
|
154
154
|
time_at_start = Time.now
|
155
|
-
caught_exception = nil
|
156
155
|
[ yield, nil, Time.now - time_at_start ]
|
157
156
|
rescue Exception => exception
|
158
157
|
[ nil, exception, Time.now - time_at_start ]
|
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.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Pravosud
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-17 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.1
|
49
49
|
signing_key:
|
50
50
|
specification_version: 4
|
51
51
|
summary: L2met friendly log formatter
|