l2meter 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a603e188a8c1ca88ca691d1dc36acb560d45776
4
- data.tar.gz: 3b6b103b4e385beb3b792cd1ab209e13e517be42
3
+ metadata.gz: 8813cc61c6cf80054b1f532ac952b4a3a8e9bcc1
4
+ data.tar.gz: bc8267895efdd3544c3bd1309504e0bc2f5d3135
5
5
  SHA512:
6
- metadata.gz: e431dab04d27159b89a6426f524f0965009e1002936985cdaf1b680bab1a14f444f6e1dfe139f487d9c2f96bf063a28164f5260e83d99ffbcf32ab925f75049e
7
- data.tar.gz: 0613c23b01a2f066c9a4c77328e1fe91b0013e8a145f5c9a9c7541966dcdd8fe3bf297ececc737e1e4715e6f3dc44577e62ad4fa5b782254123d457f0a2afa13
6
+ metadata.gz: befb44d3bb18e708a2c2172036efdb6863688e8cace9f7c94adc4c55b38621f9dfd7b5a5338654b2f35271a4b0265023ace125983c7cf0cb41632d9ea84664af
7
+ data.tar.gz: e32e10b222b91ae98390f4c730e20d12ce59b3912b3f3ea4105621278d2517aa7ee2f3b2668aa3d2f376228e4793f3168f1392d8e95d03cccbc07f84081567f0
data/README.md CHANGED
@@ -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
- Metrics.log :doing_work do # => doing-work
43
+ Metrics.log :doing_work do # => doing-work at=start
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
@@ -107,12 +107,23 @@ L2meter also allows to append elapsed time to your log messages automatically.
107
107
  ```ruby
108
108
  Metrics.with_elapsed do
109
109
  do_work_step_1
110
- log :step_1_done # => step-1-done elapsed=1.2345s
110
+ Metrics.log :step_1_done # => step-1-done elapsed=1.2345s
111
111
  do_work_step_2
112
- log :step_2_done # => step-2-done elapsed=2.3456s
112
+ Metrics.log :step_2_done # => step-2-done elapsed=2.3456s
113
113
  end
114
114
  ```
115
115
 
116
+ There's also a way to batch several calls into a single log line:
117
+
118
+ ```ruby
119
+ Metrics.batch do
120
+ Metrics.log foo: :bar
121
+ Metrics.unique :registeration, "user@example.com"
122
+ Metrics.count :thing, 10
123
+ Metrics.sample :other_thing, 20
124
+ end # => foo=bar unique#registration=user@example.com count#thing=10 sample#other-thing=20
125
+ ```
126
+
116
127
  ### Configuration
117
128
 
118
129
  L2meter supports configuration. Here's how you can configure things:
@@ -140,7 +151,7 @@ Metrics.log foo: :bar # => app-name=my-app-name foo-bar
140
151
  Dynamic context is also supported:
141
152
 
142
153
  ```ruby
143
- context.context do
154
+ config.context do
144
155
  { request_id: CurrentContext.request_id }
145
156
  end
146
157
  ```
@@ -69,6 +69,13 @@ module L2meter
69
69
  self.class.new(configuration: configuration)
70
70
  end
71
71
 
72
+ def batch
73
+ @outputs.push StringIO.new
74
+ yield
75
+ ensure
76
+ emit @outputs.pop.tap(&:rewind).read.split(/\s+/).uniq.join(" ")
77
+ end
78
+
72
79
  private
73
80
 
74
81
  def transform_log_args(*args)
@@ -122,9 +129,14 @@ module L2meter
122
129
 
123
130
  tokens.sort! if configuration.sort?
124
131
 
125
- output_queue.last.print tokens.join(" ") + "\n"
132
+ emit tokens.join(" ")
126
133
  end
127
134
 
135
+ def emit(text)
136
+ output_queue.last.puts text
137
+ end
138
+
139
+
128
140
  def log_with_prefix(method, key, value, unit: nil)
129
141
  key = [configuration.prefix, key, unit].compact * ?.
130
142
  log Hash["#{method}##{key}", value]
@@ -9,6 +9,7 @@ module L2meter
9
9
  extend Forwardable
10
10
 
11
11
  EMITTER_METHODS = %i[
12
+ batch
12
13
  configuration
13
14
  context
14
15
  count
@@ -1,3 +1,3 @@
1
1
  module L2meter
2
- VERSION = "0.2.4".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
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
4
+ version: 0.3.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-02-17 00:00:00.000000000 Z
11
+ date: 2016-02-24 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.5.1
48
+ rubygems_version: 2.4.8
49
49
  signing_key:
50
50
  specification_version: 4
51
51
  summary: L2met friendly log formatter