informed 1.0.0 → 1.1.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: 400cde4d28ec801fa0a3673a51ceee479ccaaf75
4
- data.tar.gz: 0a4cf3e450db47d356741563f05e427628567bc2
3
+ metadata.gz: ba5433e00f3520fb5d488f0597c86df6a260a57f
4
+ data.tar.gz: c8cdfb9e6130b1c503204062c5b09b03e2b69167
5
5
  SHA512:
6
- metadata.gz: ead6a13f3a4453df836f2ad3bf11f74265c3d57ef71be3ad56ab7fea4a5d1366c8e09108d6c59e480a1163c5eef73bb9f62f0a2922520148a4e23b84b821dedb
7
- data.tar.gz: c50e3655490c233aac89b6f0d02e70bdc40ea535c6c99d753eb2794073cbd4a108bd07b1c0a7bab197b2b0afa1ca953cced1a1733c65a711473d2e3ab062a0ef
6
+ metadata.gz: 0bed52a50511a9201dc57fbd52f8cf52e1c954f5e5dc28657dc20cd6d7ffb527d94fbb61b972f3df94b94446e110d2d063296515a7176bc44a4bf074558d924f
7
+ data.tar.gz: f35acc7f08150778f5808ff033eabb777232e0745182f74dcaf2db8ef5f816679b4a348963c10cf06596318f344f46be6c17de64bf8859841e79d6b5bfe78932
data/.travis.yml CHANGED
@@ -4,6 +4,6 @@ rvm:
4
4
  - 2.1.10
5
5
  - 2.2.7
6
6
  - 2.3.4
7
- - 2.4.1
8
- before_install: gem install bundler -v 1.14.6
7
+ - 2.4.2
8
+ before_install: gem install bundler -v 1.15.4
9
9
  script: ruby test/informed_test.rb --documentation
data/README.md CHANGED
@@ -1,12 +1,32 @@
1
1
  # Informed
2
- ![build status](https://travis-ci.org/zincmade/informed.svg?branch=primary)
2
+ ![build status](https://api.travis-ci.org/wecohere/informed.svg?branch=primary)
3
+
4
+ Informed improves application debuggability by:
5
+ * Logging which methods were called.
6
+ * Aggregating useful data, such as the result of the call, keyword arguments provided, or the result of related instance methods
7
+ * Exposing when a method starts and finishes
8
+
9
+ Informed does *not*:
10
+ * Format logs. It provides a hash to the logger you provide, and it's up to you
11
+ to format your logs in a useful manner. This will depend on what log
12
+ aggregation system you are using.
13
+ * Store logs. You will need to configure your applications logger correctly to
14
+ ensure logs will actually reach your log aggregator.
15
+ * Provide useful analytics or performance tuning data. Logs are for informing
16
+ your incident detection system, debugging, and auditing. While one may get
17
+ *some* amount of metrics utility out of them, products oriented towards
18
+ exposing the insights you are looking for are generally better equipped for
19
+ that.
3
20
 
4
- ## Installation
21
+
22
+ ## Usage
23
+
24
+ ### Install
5
25
 
6
26
  Add this line to your application's Gemfile:
7
27
 
8
28
  ```ruby
9
- gem 'informed'
29
+ gem 'informed', '~> 1.0'
10
30
  ```
11
31
 
12
32
  And then execute:
@@ -17,11 +37,7 @@ Or install it yourself as:
17
37
 
18
38
  $ gem install informed
19
39
 
20
- ## Usage
21
-
22
- Informed, when included, makes it easy to log method calls when they start and
23
- finish. It provides a means to log additional data, such as the result of said
24
- calls, keyword arguments, or other instance methods.
40
+ ### Instrument
25
41
 
26
42
  ```
27
43
 
@@ -56,23 +72,36 @@ class FancyService
56
72
  end
57
73
 
58
74
  FancyService.new(fanciness: 12).do_something
59
- # I, [2017-04-04T19:46:05.256753 #29957] INFO -- : {:method=>:do_something, :values=>{:fancy?=>true, :fanciness=>12}, :status=>:starting}
60
- # I, [2017-04-04T19:46:05.256896 #29957] INFO -- : {:method=>:do_something, :values=>{:fancy?=>true, :fanciness=>12}, :status=>:done, :result=>"so fancy"}
75
+ # I, [2017-07-05T18:27:13.431695 #3297] INFO -- : {:method=>:do_something, :class=>"FancyService", :values=>{:fancy?=>true, :fanciness=>12}, :status=>:starting}
76
+ # I, [2017-07-05T18:27:13.431780 #3297] INFO -- : {:method=>:do_something, :class=>"FancyService", :values=>{:fancy?=>true, :fanciness=>12}, :status=>:done, :result=>"so fancy"}
61
77
  # => "so fancy"
62
78
  FancyService.new(fanciness: 12).do_something(force: true)
63
- # I, [2017-04-04T19:46:09.043051 #29957] INFO -- : {:method=>:do_something, :values=>{:fancy?=>true, :force=>true, :fanciness=>12}, :status=>:starting}
64
- # I, [2017-04-04T19:46:09.043159 #29957] INFO -- : {:method=>:do_something, :values=>{:fancy?=>true, :force=>true, :fanciness=>12}, :status=>:done, :result=>"so fancy"}
79
+ # I, [2017-07-05T18:27:57.612778 #3297] INFO -- : {:method=>:do_something, :class=>"FancyService", :values=>{:fancy?=>true, :force=>true, :fanciness=>12}, :status=>:starting}
80
+ # I, [2017-07-05T18:27:57.612853 #3297] INFO -- : {:method=>:do_something, :class=>"FancyService", :values=>{:fancy?=>true, :force=>true, :fanciness=>12}, :status=>:done, :result=>"so fancy"}
65
81
  # => "so fancy"
66
82
  FancyService.new(fanciness: 8).do_something(force: true)
67
- # I, [2017-04-04T19:46:17.968960 #29957] INFO -- : {:method=>:do_something, :values=>{:fancy?=>false, :force=>true, :fanciness=>8}, :status=>:starting}
68
- # I, [2017-04-04T19:46:17.969066 #29957] INFO -- : {:method=>:do_something, :values=>{:fancy?=>false, :force=>true, :fanciness=>8}, :status=>:done, :result=>"so fancy"}
83
+ # I, [2017-07-05T18:28:35.282196 #3297] INFO -- : {:method=>:do_something, :class=>"FancyService", :values=>{:fancy?=>false, :force=>true, :fanciness=>8}, :status=>:starting}
84
+ # I, [2017-07-05T18:28:35.282272 #3297] INFO -- : {:method=>:do_something, :class=>"FancyService", :values=>{:fancy?=>false, :force=>true, :fanciness=>8}, :status=>:done, :result=>"so fancy"}
69
85
  # => "so fancy"
70
86
  FancyService.new(fanciness: 8).do_something(force: false)
71
- # I, [2017-04-04T19:49:10.485462 #29957] INFO -- : {:method=>:do_something, :values=>{:fancy?=>false, :force=>false, :fanciness=>8}, :status=>:starting}
72
- # I, [2017-04-04T19:49:10.485596 #29957] INFO -- : {:method=>:do_something, :values=>{:fancy?=>false, :force=>false, :fanciness=>8}, :status=>:done, :result=>"so plain"}
73
- # => "so plain"
87
+ # I, [2017-07-05T18:29:13.319488 #3297] INFO -- : {:method=>:do_something, :class=>"FancyService", :values=>{:fancy?=>false, :force=>false, :fanciness=>8}, :status=>:starting}
88
+ # I, [2017-07-05T18:29:13.319560 #3297] INFO -- : {:method=>:do_something, :class=>"FancyService", :values=>{:fancy?=>false, :force=>false, :fanciness=>8}, :status=>:done, :result=>"so plain"}
89
+ # => "so plain"
74
90
  ```
75
91
 
92
+ ### Configure
93
+
94
+ While we default to logging to standard out, Informed is Logger-agnostic. You
95
+ may provide a logger to informed that is interface compatible with the Logger
96
+ class in the Ruby standard library.
97
+
98
+ To do so either:
99
+ * Set `Informed.logger` to your application logger. (Rails Example:
100
+ `Informed.logger = Rails.logger`)
101
+ * Define an instance method `logger` on the informed upon class and have it
102
+ return whatever logger you want.
103
+
104
+
76
105
  ## Development
77
106
 
78
107
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
@@ -1,3 +1,3 @@
1
1
  module Informed
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/informed.rb CHANGED
@@ -91,8 +91,12 @@ module Informed
91
91
  def inform_on(method, level:, also_log: {})
92
92
  alias_method :"unwatched_#{method}", method
93
93
  informant = Informant.new(method: method, also_log: also_log, level: level)
94
- define_method method do |*arguments, **keyword_arguments|
95
- informant.inform_on(informee: self, logger: logger, arguments: arguments, keyword_arguments: keyword_arguments)
94
+ define_method method do |*arguments, **keyword_arguments, &block|
95
+ informant.inform_on(informee: self,
96
+ logger: logger,
97
+ arguments: arguments,
98
+ keyword_arguments: keyword_arguments,
99
+ block: block)
96
100
  end
97
101
  end
98
102
  end
@@ -145,17 +149,17 @@ module Informed
145
149
  # be logged if specified in the :values
146
150
  # array in {#also_log}.
147
151
  # @return the result of the informed upon method.
148
- def inform_on(logger:, arguments:, keyword_arguments:, informee:)
152
+ def inform_on(logger:, arguments:, keyword_arguments:, informee:, block: nil)
149
153
  method_context = { keyword_arguments: keyword_arguments, method: method, also_log: also_log, informee: informee }
150
154
  log(logger: logger, type: StartingMessage, method_context: method_context)
151
155
  result = if arguments.empty? && keyword_arguments.empty?
152
- informee.send(:"unwatched_#{method}")
156
+ informee.send(:"unwatched_#{method}", &block)
153
157
  elsif arguments.empty? && !keyword_arguments.empty?
154
- informee.send(:"unwatched_#{method}", **keyword_arguments)
158
+ informee.send(:"unwatched_#{method}", **keyword_arguments, &block)
155
159
  elsif !arguments.empty? && keyword_arguments.empty?
156
- informee.send(:"unwatched_#{method}", *arguments)
160
+ informee.send(:"unwatched_#{method}", *arguments, &block)
157
161
  elsif !arguments.empty? && !keyword_arguments.empty?
158
- informee.send(:"unwatched_#{method}", *arguments, **keyword_arguments)
162
+ informee.send(:"unwatched_#{method}", *arguments, **keyword_arguments, &block)
159
163
  end
160
164
  log(logger: logger, type: DoneMessage, method_context: method_context.merge(result: result))
161
165
  result
@@ -189,7 +193,7 @@ module Informed
189
193
  # depends on {#also_log}
190
194
  # @return [Hash]
191
195
  def to_h
192
- message = { method: method }
196
+ message = { method: method, class: informee.class.name }
193
197
  if also_log[:values]
194
198
  message[:values] = {}
195
199
  also_log[:values].each do |local|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: informed
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zee Spencer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-22 00:00:00.000000000 Z
11
+ date: 2017-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  requirements: []
126
126
  rubyforge_project:
127
- rubygems_version: 2.6.8
127
+ rubygems_version: 2.6.11
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: Informs on method calls so you know what your app is doing and why