rt-logman 0.9.0 → 0.10.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: d0fd4713e9ae89962d5c9d63dce15c9592b66c0e
4
- data.tar.gz: bcc046ddbbb50f4563e7ad6f7687a7f923b8014f
3
+ metadata.gz: cb547bfe89e346a9c9198e1fe5f49c536d8a81e8
4
+ data.tar.gz: 6fd763746e3360aef85d2296002ecad1fbf28693
5
5
  SHA512:
6
- metadata.gz: '03663528dfe5ab510667cc91966da0776c0b847ce0ac5936b319d774bf6d57fd0e31c8ed67bc070969ac9e571979b35896cafd100478b2adf5a332bf9c406c9c'
7
- data.tar.gz: 295666771e628e232c630d1a8dde906029213f7b0b7895e03ba31a5e2cadf1ee7a42d8e04d831d7b6ea0468d2acee1f45675932c6c58ec3e00b831bd5151545c
6
+ metadata.gz: c48037c426a5a926734a06cf3a9e0feaf40eb4752ae7a36e4847914f672374f46cdbd5f350cf5c9f09777c0d6e60f0a2def30e52e8edf9b3c7534ec8d00102fa
7
+ data.tar.gz: 83ab488cf6dc57d35790134b385b9d6d7ff1ca860bc1f9c943863ed158f86e3710ce3e298c2d6b7404216b4df6421dab525d2d38f4a92b4543618cbdd14b02de
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rt-logman (0.9.0)
4
+ rt-logman (0.10.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -154,6 +154,56 @@ create a new Logman instance with the same fields as the previous instance:
154
154
  # level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='Hello' version='v2'
155
155
  ```
156
156
 
157
+ With Logman, you can instrument data processing with a logger block. For
158
+ example, if you want to log the steps in a user sign-up progress:
159
+
160
+ ``` ruby
161
+ Logman.process("user-registration", :username => "shiroyasha") do |logger|
162
+ user = User.create(params)
163
+ logger.info("User Record Created")
164
+
165
+ SigupEmail.send(user)
166
+ logger.info("Sent signup email")
167
+
168
+ team.add(user)
169
+ logger.info("Added user to a team", :team_id => team)
170
+ end
171
+ ```
172
+
173
+ The above will log the following information:
174
+
175
+ ``` txt
176
+ level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='user-registration-started' username='shiroyasha'
177
+ level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='User Record Created' username='shiroyasha'
178
+ level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='Sent signup email' username='shiroyasha'
179
+ level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='Added user to a team' username='shiroyasha' team_id='312'
180
+ level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='user-registration-finished' username='shiroyasha'
181
+ ```
182
+
183
+ In case of an exception, the error will be logger and re-thrown:
184
+
185
+ ``` ruby
186
+ Logman.process("user-registration", :username => "shiroyasha") do |logger|
187
+ user = User.create(params)
188
+ logger.info("User Record Created")
189
+
190
+ SigupEmail.send(user)
191
+ logger.info("Sent signup email")
192
+
193
+ raise "Exception"
194
+
195
+ team.add(user)
196
+ logger.info("Added user to a team", :team_id => team)
197
+ end
198
+ ```
199
+
200
+ ``` ruby
201
+ level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='user-registration-started' username='shiroyasha'
202
+ level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='User Record Created' username='shiroyasha'
203
+ level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='Sent signup email' username='shiroyasha'
204
+ level='E' time='2017-12-11 09:47:27 +0000' pid='1234' event='user-registration-failed' username='shiroyasha' type='RuntimeError' message='Exception'
205
+ ```
206
+
157
207
  ## Development
158
208
 
159
209
  After checking out the repo:
@@ -1,3 +1,3 @@
1
1
  class Logman
2
- VERSION = "0.9.0".freeze
2
+ VERSION = "0.10.0".freeze
3
3
  end
data/lib/logman.rb CHANGED
@@ -2,6 +2,7 @@ require "logman/version"
2
2
  require "logger"
3
3
 
4
4
  # :reek:PrimaDonnaMethod { exclude: [clear! ] }
5
+ # :reek:TooManyStatements{ exclude: [process ] }
5
6
  class Logman
6
7
  SEVERITY_LEVELS = %i(fatal error warn info debug).freeze
7
8
 
@@ -10,8 +11,14 @@ class Logman
10
11
  @default_logger ||= Logman.new
11
12
  end
12
13
 
14
+ def process(name, metadata = {}, &block)
15
+ default_logger.process(name, metadata, &block)
16
+ end
17
+
13
18
  SEVERITY_LEVELS.each do |severity|
14
- define_method(severity) { |message, metadata| default_logger.public_send(severity, message, metadata) }
19
+ define_method(severity) do |message, *args|
20
+ default_logger.public_send(severity, message, args.first || {})
21
+ end
15
22
  end
16
23
  end
17
24
 
@@ -42,7 +49,23 @@ class Logman
42
49
  end
43
50
 
44
51
  SEVERITY_LEVELS.each do |severity|
45
- define_method(severity) { |message, metadata| log(severity, message, metadata) }
52
+ define_method(severity) do |message, *args|
53
+ log(severity, message, args.first || {})
54
+ end
55
+ end
56
+
57
+ def process(name, metadata = {})
58
+ logger = Logman.new(:logger => self)
59
+ logger.add(metadata)
60
+
61
+ logger.info("#{name}-started")
62
+
63
+ yield(logger)
64
+
65
+ logger.info("#{name}-finished")
66
+ rescue StandardError => exception
67
+ logger.error("#{name}-failed", :type => exception.class.name, :message => exception.message)
68
+ raise
46
69
  end
47
70
 
48
71
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rt-logman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rendered Text
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-11 00:00:00.000000000 Z
11
+ date: 2017-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler