timber 1.1.7 → 1.1.8

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: eedbdde12666a1140ddf56d8d94a69e21fdd447a
4
- data.tar.gz: 687c97f7258d47d0d40fae21030b5efca5f47c79
3
+ metadata.gz: 3c9b324e70feb9ff1373222ba8a5f713a7c3137a
4
+ data.tar.gz: 73ec3459c15d1a9438f762c9aec975eefd1e2852
5
5
  SHA512:
6
- metadata.gz: b000f04c0d0d15e9500210e886500af6bebe1dfe8fb72147b7d0b15b2858e76ccebcdb851b139c64fccd001e55764b59eca299d98ff31849899ba304c39e12c6
7
- data.tar.gz: bcb842aec9aca3249b0ff4c572686dd39864dd79711ad36bc0acac60d6de67e989912a6bf75b318e23078620601e3578a23c2c33db52528334bd5cc231133623
6
+ metadata.gz: ac167d0a6d8ae1f7968d3df367203d75df9405f26dd89d6d4bb6a0641182f45d6290c771f187099f6858633f593bac5d49da086fc1b35b4028745c377385ae98
7
+ data.tar.gz: 9b6d80aae0f5f44c821ea73f00ff9418e2656b52d007840c292f189182b4480e6b9907beae8bf365ace3d255f68494ac36668a84a9d40ab34f17ca51fa2ed302
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # 🌲 Timber - Master your Ruby apps with structured logging
2
2
 
3
3
  <p align="center" style="background: #140f2a;">
4
- <a href="http://github.com/timberio/timber-ruby"><img src="http://files.timber.io/images/ruby-library-readme-header.gif" height="469" /></a>
4
+ <a href="http://files.timber.io/images/readme-interface.gif"><img src="http://files.timber.io/images/readme-interface.gif" width="100%" /></a>
5
5
  </p>
6
6
 
7
7
  [![ISC License](https://img.shields.io/badge/license-ISC-ff69b4.svg)](LICENSE.md)
@@ -10,108 +10,125 @@
10
10
  [![Code Climate](https://codeclimate.com/github/timberio/timber-ruby/badges/gpa.svg)](https://codeclimate.com/github/timberio/timber-ruby)
11
11
  [![View docs](https://img.shields.io/badge/docs-viewdocs-blue.svg?style=flat-square "Viewdocs")](http://www.rubydoc.info/github/timberio/timber-ruby)
12
12
 
13
+ Still logging raw text? Timber is a complete *structured* logging solution that you can setup in
14
+ minutes. It solves logging so you don't have to!
13
15
 
14
- ---
16
+ To learn more, checkout out [timber.io](https://timber.io).
15
17
 
16
- 👉 **Timber is in beta testing, if interested in joining, please email us at
17
- [beta@timber.io](mailto:beta@timber.io)**
18
18
 
19
- ---
19
+ ## Installation
20
20
 
21
- Still logging raw text? Timber is a complete *structured* logging solution that you can setup in
22
- minutes. It goes beyond traditional log management by focusing on data quality and modern
23
- developer standards.
21
+ 1. *Add* the `timber` gem in `Gemfile`:
24
22
 
25
- High quality logs, [a modern UX-first interface](https://timber.io), simple setup,
26
- zero-maintenance, 6-month retention, and sane prices are just a few of the benefits Timber
27
- offers.
23
+ ```ruby
24
+ # Gemfile
28
25
 
29
- To learn more, checkout out [timber.io](https://timber.io) or the
30
- ["why we built Timber"](http://moss-ibex2.cloudvent.net/blog/why-were-building-timber/)
31
- blog post.
26
+ gem 'timber'
27
+ ```
32
28
 
29
+ 2. *Install* the `Timber::Logger` in `config/environments/production.rb`:
33
30
 
34
- ## Overview
31
+ ```ruby
32
+ # config/environments/production.rb
35
33
 
36
- <details><summary><strong>What are the benefits of using Timber?</strong></summary><p>
34
+ # config.log_formatter = ::Logger::Formatter.new # <--------------------------- REMOVE ME
35
+ # config.logger = ActiveSupport::TaggedLogging.new(logger) # <----------------- REMOVE ME
37
36
 
38
- 1. **Data quality.** The usefulness of your logs starts here. This is why we ship libraries that
39
- structure logs from *within* your application; a fundamental difference from parsing. Not only
40
- is it much more stable, but we can include data you couldn't obtain otherwise.
41
- 2. **Human readability.** Structuring your logs doesn't mean they have to be unreadable. Timber
42
- *augments* your logs with structured data. Meaning we do not alter the original log message,
43
- we simply attach metadata to it. And our console is specifically designed to give you access
44
- to this data, without compromising readability. 😮
45
- 3. **Reliable downstream consumption.** All log events adhere to a
46
- [normalized, shared, schema](https://github.com/timberio/log-event-json-schema) that follows
47
- [semantic versioning](http://semver.org/) and goes through a [standard release process](https://github.com/timberio/log-event-json-schema/releases).
48
- This means you can *rely* on the structure of your logs and interact consistently with them
49
- across apps of any language: queries, graphs, alerts, and other downstream consumers.
50
- 4. **Zero risk of code debt or lock-in.** Logging is a standard that has been around since the dawn
51
- of computers. It's built into every language, framework, and library. Timber adheres strictly
52
- to the default `Logger` interface. There are no special APIs, and no need to pepper your app
53
- with Timber specific code. It's just better logging. If you choose to stop using Timber, you
54
- can do so without consequence.
55
- 5. **Long term retention.** Timber is designed on modern big-data principles. As a result, we can
56
- offer 6+ months of retention at prices cheaper than alternatives offering <1 month.
57
- This allows you to unlock your logs for purposes beyond debugging.
37
+ config.logger = ActiveSupport::TaggedLogging.new(Timber::Logger.new(STDOUT)) # <-- ADD ME
38
+ ```
39
+
40
+ ---
41
+
42
+ <details><summary><strong>Prefer to see an example pull request?</strong></summary><p>
43
+
44
+ Checkout our the [Timber install example pull request](https://github.com/timberio/ruby-rails-example-app/pull/1/files)
58
45
 
59
46
  ---
60
47
 
61
48
  </p></details>
62
49
 
63
- <details><summary><strong>What specifically does the Timber library do?</strong></summary><p>
50
+ <details><summary><strong>Not using Rails?</strong></summary><p>
64
51
 
65
- 1. Captures and structures your framework and 3rd party logs. (see next question)
66
- 2. Adds useful context to every log line. (see next question)
67
- 3. Allows you to easily add tags and timings to log. (see [Usage](#usage))
68
- 4. Provides a framework for logging custom structured events. (see [Usage](#usage))
69
- 5. Offers transport strategies to [send your logs](#send-your-logs) to the Timber service.
52
+ No problem! You can easily install Timber following these steps:
53
+
54
+ 1. *Insert* the Timber probes:
55
+
56
+ This should be executed *immediately after* you have required your dependencies.
57
+
58
+ ```ruby
59
+ Timber::Probes.insert!
60
+ ```
61
+
62
+ 2. *Add* the Rack middlewares:
63
+
64
+ This should be included where you build your `Rack` application. Usually `config.ru`:
65
+
66
+ ```ruby
67
+ # Most likely config.ru
68
+
69
+ Timber::RackMiddlewares.middlewares.each do |m|
70
+ use m
71
+ end
72
+ ```
73
+
74
+ 2. *Instantiate* the Timber logger:
75
+
76
+ This should be *globally* available to your application:
77
+
78
+ ```ruby
79
+ logger = Timber::Logger.new(STDOUT)
80
+ ```
70
81
 
71
82
  ---
72
83
 
73
84
  </p></details>
74
85
 
75
- <details><summary><strong>What events does Timber capture & structure for me?</strong></summary><p>
76
86
 
77
- Out of the box you get everything in the [`Timber::Events`](lib/timber/events) namespace:
78
87
 
79
- 1. [Controller Call Event](lib/timber/events/controller_call.rb)
80
- 2. [Exception Event](lib/timber/events/exception.rb)
81
- 3. [HTTP Client Request Event (net/http outgoing)](lib/timber/events/http_client_request.rb)
82
- 4. [HTTP Client Response Event (resposne from net/http outgoing)](lib/timber/events/http_client_response.rb)
83
- 5. [HTTP Server Request Event (incoming client request)](lib/timber/events/http_server_request.rb)
84
- 6. [HTTP Server Response Event (response to incoming client request)](lib/timber/events/http_server_response.rb)
85
- 7. [SQL Query Event](lib/timber/events/sql_query.rb)
86
- 8. [Template Render Event](lib/timber/events/template_render.rb)
87
- 9. ...more coming soon, [file an issue](https://github.com/timberio/timber-ruby/issues) to request.
88
88
 
89
- We also add context to every log, everything in the [`Timber::Contexts`](lib/timber/contexts)
90
- namespace. Context is structured data representing the current environment when the log line was
91
- written. It is included in every log line. Think of it like join data for your logs:
92
89
 
93
- 1. [HTTP Context](lib/timber/contexts/http.rb)
94
- 2. [Organization Context](lib/timber/contexts/organization.rb)
95
- 3. [Process Context](lib/timber/contexts/process.rb)
96
- 4. [Server Context](lib/timber/contexts/server.rb)
97
- 5. [Runtime Context](lib/timber/contexts/runtime.rb)
98
- 5. [User Context](lib/timber/contexts/user.rb)
99
- 6. ...more coming soon, [file an issue](https://github.com/timberio/timber-ruby/issues) to request.
90
+
91
+
92
+
93
+ ## Send your logs (choose one)
94
+
95
+ <details><summary><strong>Heroku (log drains)</strong></summary><p>
96
+
97
+ The recommended strategy for Heroku is to setup a
98
+ [log drain](https://devcenter.heroku.com/articles/log-drains). To get your Timber log drain URL:
99
+
100
+ 👉 **[Add your app to Timber](https://app.timber.io)**
100
101
 
101
102
  ---
102
103
 
103
104
  </p></details>
104
105
 
105
- <details><summary><strong>What about my current log statements?</strong></summary><p>
106
+ <details><summary><strong>All other platforms (Network / HTTP)</strong></summary><p>
106
107
 
107
- They'll continue to work as expected. Timber adheres strictly to the default `::Logger` interface
108
- and will never deviate in *any* way.
108
+ 1. *Specify* the Timber Network logger backend in `config/environments/production.rb`:
109
109
 
110
- In fact, traditional log statements for non-meaningful events, debug statements, etc, are
111
- encouraged. In cases where the data is meaningful, consider [logging a custom event](#usage).
110
+ Replace any existing `config.logger =` calls with:
111
+
112
+ ```ruby
113
+ # config/environments/production.rb (or staging, etc)
114
+
115
+ network_log_device = Timber::LogDevices::Network.new(ENV['TIMBER_LOGS_KEY'])
116
+ config.logger = Timber::Logger.new(network_log_device) # <-- Use network_log_device instead of STDOUT
117
+ ```
118
+
119
+ 2. Obtain your Timber API :key: by **[adding your app in Timber](https://app.timber.io)**.
120
+
121
+ 3. Assign your API key to the `TIMBER_LOGS_KEY` environment variable.
112
122
 
113
123
  </p></details>
114
124
 
125
+ <details><summary><strong>Advanced setup (syslog, file tailing agent, etc)</strong></summary><p>
126
+
127
+ Checkout our [docs](https://timber.io/docs) for a comprehensive list of install instructions.
128
+
129
+ </p></details>
130
+
131
+
115
132
  ## Usage
116
133
 
117
134
  <details><summary><strong>Basic logging</strong></summary><p>
@@ -287,103 +304,84 @@ value.
287
304
  </p></details>
288
305
 
289
306
 
307
+ ## Jibber-Jabber
290
308
 
291
- ## Installation
292
-
293
- ```ruby
294
- # Gemfile
295
- gem 'timber'
296
- ```
297
-
298
-
299
- ## Setup
300
-
301
- <details><summary><strong>Rails (all versions, including edge)</strong></summary><p>
302
-
303
- 👉 **Prefer examples?** Checkout our the [Timber install example pull request](https://github.com/timberio/ruby-rails-example-app/pull/1/files)
304
-
305
- ---
306
-
307
- *Replace* any existing `config.logger=` calls in `config/environments/production.rb` with:
308
-
309
- ```ruby
310
- # config/environments/production.rb
309
+ <details><summary><strong>What specifically does the Timber library do?</strong></summary><p>
311
310
 
312
- config.logger = ActiveSupport::TaggedLogging.new(Timber::Logger.new(STDOUT))
313
- ```
311
+ 1. Captures and structures your framework and 3rd party logs. (see next question)
312
+ 2. Adds useful context to every log line. (see next question)
313
+ 3. Allows you to easily add tags and timings to log. (see [Usage](#usage))
314
+ 4. Provides a framework for logging custom structured events. (see [Usage](#usage))
315
+ 5. Offers transport strategies to [send your logs](#send-your-logs) to the Timber service.
314
316
 
315
317
  ---
316
318
 
317
319
  </p></details>
318
320
 
319
- <details><summary><strong>Other</strong></summary><p>
320
-
321
- 1. *Insert* the Timber probes:
322
-
323
- This should be executed *immediately after* you have required your dependencies.
324
-
325
- ```ruby
326
- Timber::Probes.insert!
327
- ```
328
-
329
- 2. *Add* the Rack middlewares:
330
-
331
- This should be included where you build your `Rack` application. Usually `config.ru`:
332
-
333
- ```ruby
334
- # Most likely config.ru
335
-
336
- Timber::RackMiddlewares.middlewares.each do |m|
337
- use m
338
- end
339
- ```
340
-
341
- 2. *Instantiate* the Timber logger:
321
+ <details><summary><strong>What are the benefits of using Timber?</strong></summary><p>
342
322
 
343
- This should be *globally* available to your application:
323
+ 1. **Data quality.** The usefulness of your logs starts here. This is why we ship libraries that
324
+ structure logs from *within* your application; a fundamental difference from parsing. Not only
325
+ is it much more stable, but we can include data you couldn't obtain otherwise.
326
+ 2. **Human readability.** Structuring your logs doesn't mean they have to be unreadable. Timber
327
+ *augments* your logs with structured data. Meaning we do not alter the original log message,
328
+ we simply attach metadata to it. And our console is specifically designed to give you access
329
+ to this data, without compromising readability. 😮
330
+ 3. **Reliable downstream consumption.** All log events adhere to a
331
+ [normalized, shared, schema](https://github.com/timberio/log-event-json-schema) that follows
332
+ [semantic versioning](http://semver.org/) and goes through a [standard release process](https://github.com/timberio/log-event-json-schema/releases).
333
+ This means you can *rely* on the structure of your logs and interact consistently with them
334
+ across apps of any language: queries, graphs, alerts, and other downstream consumers.
335
+ 4. **Zero risk of code debt or lock-in.** Logging is a standard that has been around since the dawn
336
+ of computers. It's built into every language, framework, and library. Timber adheres strictly
337
+ to the default `Logger` interface. There are no special APIs, and no need to pepper your app
338
+ with Timber specific code. It's just better logging. If you choose to stop using Timber, you
339
+ can do so without consequence.
340
+ 5. **Long term retention.** Timber is designed on modern big-data principles. As a result, we can
341
+ offer 6+ months of retention at prices cheaper than alternatives offering <1 month.
342
+ This allows you to unlock your logs for purposes beyond debugging.
344
343
 
345
- ```ruby
346
- logger = Timber::Logger.new(STDOUT)
347
- ```
344
+ ---
348
345
 
349
346
  </p></details>
350
347
 
348
+ <details><summary><strong>What events does Timber capture & structure for me?</strong></summary><p>
351
349
 
352
- ## Send your logs
350
+ Out of the box you get everything in the [`Timber::Events`](lib/timber/events) namespace:
353
351
 
354
- <details><summary><strong>Heroku (log drains)</strong></summary><p>
352
+ 1. [Controller Call Event](lib/timber/events/controller_call.rb)
353
+ 2. [Exception Event](lib/timber/events/exception.rb)
354
+ 3. [HTTP Client Request Event (net/http outgoing)](lib/timber/events/http_client_request.rb)
355
+ 4. [HTTP Client Response Event (resposne from net/http outgoing)](lib/timber/events/http_client_response.rb)
356
+ 5. [HTTP Server Request Event (incoming client request)](lib/timber/events/http_server_request.rb)
357
+ 6. [HTTP Server Response Event (response to incoming client request)](lib/timber/events/http_server_response.rb)
358
+ 7. [SQL Query Event](lib/timber/events/sql_query.rb)
359
+ 8. [Template Render Event](lib/timber/events/template_render.rb)
360
+ 9. ...more coming soon, [file an issue](https://github.com/timberio/timber-ruby/issues) to request.
355
361
 
356
- The recommended strategy for Heroku is to setup a
357
- [log drain](https://devcenter.heroku.com/articles/log-drains). To get your Timber log drain URL:
362
+ We also add context to every log, everything in the [`Timber::Contexts`](lib/timber/contexts)
363
+ namespace. Context is structured data representing the current environment when the log line was
364
+ written. It is included in every log line. Think of it like join data for your logs:
358
365
 
359
- 👉 **[Add your app to Timber](https://app.timber.io)**
366
+ 1. [HTTP Context](lib/timber/contexts/http.rb)
367
+ 2. [Organization Context](lib/timber/contexts/organization.rb)
368
+ 3. [Process Context](lib/timber/contexts/process.rb)
369
+ 4. [Server Context](lib/timber/contexts/server.rb)
370
+ 5. [Runtime Context](lib/timber/contexts/runtime.rb)
371
+ 5. [User Context](lib/timber/contexts/user.rb)
372
+ 6. ...more coming soon, [file an issue](https://github.com/timberio/timber-ruby/issues) to request.
360
373
 
361
374
  ---
362
375
 
363
376
  </p></details>
364
377
 
365
- <details><summary><strong>All other platforms (Network / HTTP)</strong></summary><p>
366
-
367
- 1. *Specify* the Timber Network logger backend in `config/environments/production.rb`:
368
-
369
- Replace any existing `config.logger =` calls with:
370
-
371
- ```ruby
372
- # config/environments/production.rb (or staging, etc)
373
-
374
- network_log_device = Timber::LogDevices::Network.new(ENV['TIMBER_LOGS_KEY'])
375
- config.logger = Timber::Logger.new(network_log_device) # <-- Use network_log_device instead of STDOUT
376
- ```
377
-
378
- 2. Obtain your Timber API :key: by **[adding your app in Timber](https://app.timber.io)**.
379
-
380
- 3. Assign your API key to the `TIMBER_LOGS_KEY` environment variable.
381
-
382
- </p></details>
378
+ <details><summary><strong>What about my current log statements?</strong></summary><p>
383
379
 
384
- <details><summary><strong>Advanced setup (syslog, file tailing agent, etc)</strong></summary><p>
380
+ They'll continue to work as expected. Timber adheres strictly to the default `::Logger` interface
381
+ and will never deviate in *any* way.
385
382
 
386
- Checkout our [docs](https://timber.io/docs) for a comprehensive list of install instructions.
383
+ In fact, traditional log statements for non-meaningful events, debug statements, etc, are
384
+ encouraged. In cases where the data is meaningful, consider [logging a custom event](#usage).
387
385
 
388
386
  </p></details>
389
387
 
data/lib/timber.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # core classes
2
2
  require "json" # brings to_json to the core classes
3
3
 
4
+ require "timber/overrides/rails_stdout_logging"
5
+
4
6
  # Base (must come first, order matters)
5
7
  require "timber/config"
6
8
  require "timber/context"
data/lib/timber/logger.rb CHANGED
@@ -60,6 +60,7 @@ module Timber
60
60
  # Logger.info PymentRejectedEvent.new("abcd1234", 100)
61
61
  #
62
62
  class Logger < ::Logger
63
+
63
64
  # @private
64
65
  class Formatter
65
66
  # Formatters get the formatted level from the logger.
@@ -161,11 +162,19 @@ module Timber
161
162
  # logger.formatter = Timber::Logger::JSONFormatter.new
162
163
  def initialize(*args)
163
164
  super(*args)
165
+
166
+ # Ensure we sync STDOUT to avoid buffering
167
+ if args.size == 1 and args.first.respond_to?(:"sync=")
168
+ args.first.sync = true
169
+ end
170
+
164
171
  if args.size == 1 and args.first.is_a?(LogDevices::HTTP)
165
172
  self.formatter = PassThroughFormatter.new
166
173
  else
167
174
  self.formatter = HybridFormatter.new
168
175
  end
176
+
177
+ self.level = environment_level
169
178
  end
170
179
 
171
180
  def formatter=(value)
@@ -174,7 +183,13 @@ module Timber
174
183
  "Timber::LogDevices::HTTP log device. The PassThroughFormatter must be used for proper " +
175
184
  "delivery.")
176
185
  end
177
- super
186
+
187
+ if !value.is_a?(Timber::Logger::Formatter)
188
+ # silently discard this value since rails calls this during initialization :/
189
+ nil
190
+ else
191
+ super
192
+ end
178
193
  end
179
194
 
180
195
  # Backwards compatibility with older ActiveSupport::Logger versions
@@ -185,5 +200,11 @@ module Timber
185
200
  end # end
186
201
  EOT
187
202
  end
203
+
204
+ private
205
+ def environment_level
206
+ level = ([ENV['LOG_LEVEL'].to_s.upcase, "DEBUG"] & %w[DEBUG INFO WARN ERROR FATAL UNKNOWN]).compact.first
207
+ self.class.const_get(level)
208
+ end
188
209
  end
189
210
  end
@@ -0,0 +1,21 @@
1
+ # See https://github.com/heroku/rails_stdout_logging
2
+ # I have no idea why this library was created, but most Heroku / Rails apps use it.
3
+ # This library completely obliterates any logger configuration you set.
4
+ # So this patch fixes that.
5
+
6
+ begin
7
+ require "rails_stdout_logging"
8
+
9
+ module RailsStdoutLogging
10
+ class Rails2 < Rails
11
+ def self.set_logger
12
+ end
13
+ end
14
+
15
+ class Rails3 < Rails
16
+ def self.set_logger(config)
17
+ end
18
+ end
19
+ end
20
+ rescue Exception
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Timber
2
- VERSION = "1.1.7"
2
+ VERSION = "1.1.8"
3
3
  end
@@ -117,4 +117,19 @@ describe Timber::Logger, :rails_23 => true do
117
117
  end
118
118
  end
119
119
  end
120
+
121
+ describe "#formatter=" do
122
+ let(:io) { StringIO.new }
123
+ let(:logger) { Timber::Logger.new(io) }
124
+
125
+ it "should not allow non Timber::Logger::Formatter formatters" do
126
+ logger.formatter = ::Logger::Formatter.new
127
+ expect(logger.formatter).to be_kind_of(::Timber::Logger::HybridFormatter)
128
+ end
129
+
130
+ it "should allow Timber::Logger::Formatter formatters" do
131
+ logger.formatter = ::Timber::Logger::JSONFormatter.new
132
+ expect(logger.formatter).to be_kind_of(::Timber::Logger::JSONFormatter)
133
+ end
134
+ end
120
135
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timber
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 1.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timber Technologies, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-23 00:00:00.000000000 Z
11
+ date: 2017-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -79,6 +79,7 @@ files:
79
79
  - lib/timber/log_devices/http.rb
80
80
  - lib/timber/log_entry.rb
81
81
  - lib/timber/logger.rb
82
+ - lib/timber/overrides/rails_stdout_logging.rb
82
83
  - lib/timber/probe.rb
83
84
  - lib/timber/probes.rb
84
85
  - lib/timber/probes/action_controller_log_subscriber.rb