call_logger 0.5.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6e801f833860f18014297b607e82c57aee7690df4d50d03a8a36933c8f6fed3
4
- data.tar.gz: 3014e9a30a8e0bfdd2576b7a2f416f0bd2b89e21f610548d53924ee4fd527f19
3
+ metadata.gz: 0adfd61ac39437bc65d870c48db0c0b6d2fd55b460c2464af3147da96fe151cd
4
+ data.tar.gz: 6d7e043e3db14b179cbdaca5f95610b5b2c702b4f38d8c4880d6c59113baa05e
5
5
  SHA512:
6
- metadata.gz: fe4c591ddc244a7a4f099789e02c55db42b0471f0c0dff7508b6382cc68baf1f291ece56ed0583a2f98706cb93d4f14aa78945302d8f4ee1589129e50ed1d672
7
- data.tar.gz: e14c310b304d4a30159bb019b9cf1ec1bf3f897cc1c51089bfeeff6dd0a2850e0ba2ea4ac2a6b99672ab88d11c7f702240f98b48dd8ec127635b9d73918243c7
6
+ metadata.gz: 3ef83a709e2bcba4728b2e24ee08ead8d85069e3515873700ee26d0a00e8544201fd512416032a3801fcd1a6ae26276ece42aaee19b5d863aa70a97b4c09973d
7
+ data.tar.gz: 4f6b506851e99811a0db92587e1ee0b9c3f35dc4f5763a5835fb805e2be133352b219d4b7d4c98b76338995b9906000a78130b9319d556d50c476adab1c2f357
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ Gemfile.lock*
data/README.md CHANGED
@@ -5,6 +5,9 @@ A debugging tool that lets you log method usage.
5
5
  [![Build status](https://travis-ci.org/mrzasa/call_logger.svg?branch=master)](https://travis-ci.org/mrzasa/call_logger)
6
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/55bd374e1cd20af702ed/maintainability)](https://codeclimate.com/github/mrzasa/call_logger/maintainability)
7
7
 
8
+ In the default setting, a method is logged before call with arguments and after the call with result and time call took (in seconds).
9
+ A message is also logged on execution error.
10
+
8
11
  ```
9
12
  class Calculator
10
13
  include CallLogger
@@ -17,6 +20,11 @@ class Calculator
17
20
  a/b
18
21
  end
19
22
 
23
+ log def slow_square(a)
24
+ sleep a
25
+ a * a
26
+ end
27
+
20
28
  log_class def self.info(msg)
21
29
  "Showing: #{msg}"
22
30
  end
@@ -24,7 +32,7 @@ end
24
32
 
25
33
  Calculator.new.times(3,4)
26
34
  # Calculator#times(3, 4)
27
- # Calculator#times => 6
35
+ # Calculator#times => 6, [Took: 0.000011s]
28
36
  # => 6
29
37
 
30
38
  Calculator.new.div(3,0)
@@ -34,7 +42,12 @@ Calculator.new.div(3,0)
34
42
 
35
43
  Calculator.info("hello!")
36
44
  # Calculator.info(hello)
37
- # Calculator.info => "Showing: hello"
45
+ # Calculator.info => "Showing: hello", [Took: 0.000011s]
46
+
47
+
48
+ Calculator.new.slow_square(2)
49
+ # Calculator#slow_square(2)
50
+ # Calculator#slow_square => 4, [Took: 2.000117s]
38
51
  ```
39
52
 
40
53
  ## Installation
@@ -147,7 +160,7 @@ end
147
160
 
148
161
  Calculator.new.times(3,4)
149
162
  # multiply
150
- # multiply => 6
163
+ # multiply => 6, [Took: 0.000011s]
151
164
  # => 6
152
165
  ```
153
166
 
@@ -159,7 +172,7 @@ log_block('multiply')
159
172
  end
160
173
  Calculator.new.times(3,4)
161
174
  # multiply
162
- # multiply => 6
175
+ # multiply => 6, [Took: 0.000011s]
163
176
  # => 6
164
177
  ```
165
178
 
@@ -178,7 +191,7 @@ end
178
191
  * `Logger` should provide a `#call` method accepting a single paramter.
179
192
  * `Formatter` should provide following methods:
180
193
  * `#before(method, args)` - accepting method name and it's arguments; called before method execution
181
- * `#after(method, result)` - accepting method name and it's result; called after method execution
194
+ * `#after(method, result, seconds: nil)` - accepting method name, it's result and seconds took execution as a KV param; called after method execution
182
195
  * `#error(method, exception)` - accepting method name and an exception; called when error is raised
183
196
 
184
197
  ## TODO
@@ -189,7 +202,7 @@ end
189
202
  * [] logging all methods defined in the class
190
203
  * [] doc: Rails integration
191
204
  * [] doc: API docs
192
- * [] infra: travis
205
+ * [+] infra: travis
193
206
 
194
207
  ## Development
195
208
 
data/call_logger.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "bundler", "~> 2.0"
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
29
  spec.add_development_dependency "pry"
@@ -1,3 +1,5 @@
1
+ require 'benchmark'
2
+
1
3
  module CallLogger
2
4
  class CallWrapper
3
5
  attr_reader :formatter, :logger
@@ -9,8 +11,9 @@ module CallLogger
9
11
 
10
12
  def call(name, args)
11
13
  logger.call(formatter.before(name, args))
12
- result = yield
13
- logger.call(formatter.after(name, result))
14
+ result = nil
15
+ seconds = Benchmark.realtime { result = yield }
16
+ logger.call(formatter.after(name, result, seconds: seconds))
14
17
  result
15
18
  rescue StandardError => e
16
19
  logger.call(formatter.error(name, e))
@@ -4,8 +4,8 @@ module CallLogger
4
4
  "#{method}(#{args.join(', ')})"
5
5
  end
6
6
 
7
- def after(method, result)
8
- "#{method} => #{result}"
7
+ def after(method, result, seconds: nil)
8
+ "#{method} => #{result}, [Took: #{'%.6f' % seconds}s]"
9
9
  end
10
10
 
11
11
  def error(method, exception)
@@ -1,3 +1,3 @@
1
1
  module CallLogger
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: call_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Rzasa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-02 00:00:00.000000000 Z
11
+ date: 2019-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -91,7 +91,6 @@ files:
91
91
  - ".rspec"
92
92
  - ".travis.yml"
93
93
  - Gemfile
94
- - Gemfile.lock
95
94
  - LICENSE.txt
96
95
  - README.md
97
96
  - Rakefile
data/Gemfile.lock DELETED
@@ -1,46 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- call_logger (0.5.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- coderay (1.1.2)
10
- diff-lcs (1.3)
11
- method_source (0.9.2)
12
- pry (0.12.2)
13
- coderay (~> 1.1.0)
14
- method_source (~> 0.9.0)
15
- pry-doc (0.13.5)
16
- pry (~> 0.11)
17
- yard (~> 0.9.11)
18
- rake (10.5.0)
19
- rspec (3.8.0)
20
- rspec-core (~> 3.8.0)
21
- rspec-expectations (~> 3.8.0)
22
- rspec-mocks (~> 3.8.0)
23
- rspec-core (3.8.0)
24
- rspec-support (~> 3.8.0)
25
- rspec-expectations (3.8.2)
26
- diff-lcs (>= 1.2.0, < 2.0)
27
- rspec-support (~> 3.8.0)
28
- rspec-mocks (3.8.0)
29
- diff-lcs (>= 1.2.0, < 2.0)
30
- rspec-support (~> 3.8.0)
31
- rspec-support (3.8.0)
32
- yard (0.9.16)
33
-
34
- PLATFORMS
35
- ruby
36
-
37
- DEPENDENCIES
38
- bundler (~> 1.16)
39
- call_logger!
40
- pry
41
- pry-doc
42
- rake (~> 10.0)
43
- rspec (~> 3.0)
44
-
45
- BUNDLED WITH
46
- 1.16.2