timber 2.0.22 → 2.0.23

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: fb727abf7308983fedd10e2b44e661ce337a5fed
4
- data.tar.gz: 4dd342bfd405154dc7e2cc670789745c8879f01b
3
+ metadata.gz: dcda9ae1986cc2ba1cc86941ab161e98cbf87267
4
+ data.tar.gz: 0dd221e5f41253700dc08a47edd24c9d5097ff6c
5
5
  SHA512:
6
- metadata.gz: 1e781929108c46a6a4a6979ed4255bb57e2bb8ee86397f95b8da4a517e795778dd715347d993ab627eefe951a565d9890b91d2729c73717c8a8224ce125f2c2c
7
- data.tar.gz: ac45f8c6b93f67b1829b0771e74b37968ea22e2f413e9bf4ac7952e0c2b292536ebd18f82b807a9721708ba5f20b15be50e85ca7710fa0d96d76287f87d4a7cf
6
+ metadata.gz: e11eff7209118ea8b0e0731e80ec3e1c24deed610a17eddc13d6becd282c66f906fc5cf48dd065ec07df41d2d174273c6695aaea903110d6fa7e29e8b1fe11ee
7
+ data.tar.gz: 163e16d153963b5e2d13ce2da63ff70c3158bfd70f7c29f04a72ea6bf5cecb2d5d50380bf70a83cb10a23344c249d125816db574a864b6170d3709a214fb6d2a
data/.travis.yml CHANGED
@@ -16,6 +16,7 @@ gemfile:
16
16
  - gemfiles/rails-4.2.gemfile
17
17
  - gemfiles/rails-4.2.gemfile
18
18
  - gemfiles/rails-5.0.gemfile
19
+ - gemfiles/rails-5.1.gemfile
19
20
  - gemfiles/rails-edge.gemfile
20
21
  env:
21
22
  global: RAILS_ENV=test
@@ -38,6 +39,8 @@ matrix:
38
39
  - rvm: 2.4.0
39
40
  - rvm: jruby
40
41
  gemfile: gemfiles/rails-5.0.gemfile
42
+ - rvm: jruby
43
+ gemfile: gemfiles/rails-5.1.gemfile
41
44
  - rvm: jruby
42
45
  gemfile: gemfiles/rails-edge.gemfile
43
46
  notifications:
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 5.1.0'
4
+
5
+ if RUBY_PLATFORM == "java"
6
+ gem 'mime-types', '2.6.2'
7
+ end
8
+
9
+ gemspec :path => '../'
data/lib/timber/config.rb CHANGED
@@ -37,7 +37,7 @@ module Timber
37
37
  # This is useful for debugging. This Sets a debug_logger to view internal Timber library
38
38
  # log messages. The default is `nil`. Meaning log to nothing.
39
39
  #
40
- # See `debug_to_file` and `debug_to_stdout` for convenience methods that handle creating
40
+ # See {#debug_to_file} and {#debug_to_stdout} for convenience methods that handle creating
41
41
  # and setting the logger.
42
42
  #
43
43
  # @example Rails
@@ -9,7 +9,7 @@ require "timber/contexts/user"
9
9
  module Timber
10
10
  # Namespace for all Timber supported Contexts.
11
11
  module Contexts
12
- # Protocol for casting objects into a `Timber::Context`.
12
+ # Protocol for casting objects into a {Timber::Context}.
13
13
  #
14
14
  # @example Casting a hash
15
15
  # Timber::Contexts.build(deploy: {version: "1.0.0"})
@@ -2,7 +2,7 @@ module Timber
2
2
  module Contexts
3
3
  # The session context tracks the current session for the given user.
4
4
  #
5
- # @note This is tracked automatically with the `Integrations::Rack::SessionContext` rack
5
+ # @note This is tracked automatically with the {Integrations::Rack::SessionContext} rack
6
6
  # middleware.
7
7
  class Session < Context
8
8
  @keyspace = :session
@@ -2,7 +2,7 @@ module Timber
2
2
  module Contexts
3
3
  # The user context tracks the currently authenticated user.
4
4
  #
5
- # @note This is tracked automatically with the `Integrations::Rack::UserContext` rack
5
+ # @note This is tracked automatically with the {Integrations::Rack::UserContext} rack
6
6
  # middleware.
7
7
  class User < Context
8
8
  @keyspace = :user
@@ -17,7 +17,7 @@ module Timber
17
17
  # @param context_snapshot [Hash] structured data representing a snapshot of the context at
18
18
  # the given point in time.
19
19
  # @param event [Timber.Event] structured data representing the log line event. This should be
20
- # an instance of `Timber.Event`.
20
+ # an instance of {Timber.Event}.
21
21
  # @return [LogEntry] the resulting LogEntry object
22
22
  def initialize(level, time, progname, message, context_snapshot, event, options = {})
23
23
  @level = level
@@ -92,9 +92,9 @@ module Timber
92
92
  event_type = event_hash.keys.first
93
93
 
94
94
  event_type = if event.is_a?(Events::Custom)
95
- "event:#{event_type}.#{event.type}"
95
+ "#{event_type}.#{event.type}"
96
96
  else
97
- "event:#{event_type}"
97
+ "#{event_type}"
98
98
  end
99
99
 
100
100
  log_message = "#{message} [#{event_type}]"
@@ -1,3 +1,4 @@
1
+ require "timber/overrides/active_support_tagged_logging"
1
2
  require "timber/overrides/lograge"
2
3
  require "timber/overrides/rails_stdout_logging"
3
4
 
@@ -0,0 +1,103 @@
1
+ # This patch is specifically for Rails 3. The legacy approach to wrapping the logger in
2
+ # ActiveSupport::TaggedLogging is rather poor, hence the reason it was changed entirely
3
+ # for Rails 4 and 5. The problem is that ActiveSupport::TaggedLogging is a wrapping
4
+ # class that entirely redefines the public API for the logger. As a result, any deviations
5
+ # from this API in the logger are not exposed (such as accepting event data as a second argument).
6
+ # This is assuming, so we're fixing it here.
7
+
8
+ begin
9
+ require "active_support/tagged_logging"
10
+
11
+ # Instead of patching the class we're pulling the code from Rails master. This brings in
12
+ # a number of improvements while also addressing the issue above.
13
+ if ActiveSupport::TaggedLogging.instance_of?(Class)
14
+ ActiveSupport.send(:remove_const, :TaggedLogging)
15
+
16
+ require "active_support/core_ext/module/delegation"
17
+ require "active_support/core_ext/object/blank"
18
+ require "logger"
19
+
20
+ module ActiveSupport
21
+ # Wraps any standard Logger object to provide tagging capabilities.
22
+ #
23
+ # logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
24
+ # logger.tagged('BCX') { logger.info 'Stuff' } # Logs "[BCX] Stuff"
25
+ # logger.tagged('BCX', "Jason") { logger.info 'Stuff' } # Logs "[BCX] [Jason] Stuff"
26
+ # logger.tagged('BCX') { logger.tagged('Jason') { logger.info 'Stuff' } } # Logs "[BCX] [Jason] Stuff"
27
+ #
28
+ # This is used by the default Rails.logger as configured by Railties to make
29
+ # it easy to stamp log lines with subdomains, request ids, and anything else
30
+ # to aid debugging of multi-user production applications.
31
+ module TaggedLogging
32
+ module Formatter # :nodoc:
33
+ # This method is invoked when a log event occurs.
34
+ def call(severity, timestamp, progname, msg)
35
+ super(severity, timestamp, progname, "#{tags_text}#{msg}")
36
+ end
37
+
38
+ def tagged(*tags)
39
+ new_tags = push_tags(*tags)
40
+ yield self
41
+ ensure
42
+ pop_tags(new_tags.size)
43
+ end
44
+
45
+ def push_tags(*tags)
46
+ tags.flatten.reject(&:blank?).tap do |new_tags|
47
+ current_tags.concat new_tags
48
+ end
49
+ end
50
+
51
+ def pop_tags(size = 1)
52
+ current_tags.pop size
53
+ end
54
+
55
+ def clear_tags!
56
+ current_tags.clear
57
+ end
58
+
59
+ def current_tags
60
+ # We use our object ID here to avoid conflicting with other instances
61
+ thread_key = @thread_key ||= "activesupport_tagged_logging_tags:#{object_id}".freeze
62
+ Thread.current[thread_key] ||= []
63
+ end
64
+
65
+ def tags_text
66
+ tags = current_tags
67
+ if tags.any?
68
+ tags.collect { |tag| "[#{tag}] " }.join
69
+ end
70
+ end
71
+ end
72
+
73
+ # Simple formatter which only displays the message.
74
+ class SimpleFormatter < ::Logger::Formatter
75
+ # This method is invoked when a log event occurs
76
+ def call(severity, timestamp, progname, msg)
77
+ "#{String === msg ? msg : msg.inspect}\n"
78
+ end
79
+ end
80
+
81
+ def self.new(logger)
82
+ # Ensure we set a default formatter so we aren't extending nil!
83
+ logger.formatter ||= SimpleFormatter.new
84
+ logger.formatter.extend Formatter
85
+ logger.extend(self)
86
+ end
87
+
88
+ delegate :push_tags, :pop_tags, :clear_tags!, to: :formatter
89
+
90
+ def tagged(*tags)
91
+ formatter.tagged(*tags) { yield self }
92
+ end
93
+
94
+ def flush
95
+ clear_tags!
96
+ super if defined?(super)
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ rescue Exception
103
+ end
@@ -1,3 +1,3 @@
1
1
  module Timber
2
- VERSION = "2.0.22"
2
+ VERSION = "2.0.23"
3
3
  end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ # ActiveSupport::TaggedLogging is not defined in <= 3.1
4
+ if defined?(::ActiveSupport::TaggedLogging)
5
+ describe ActiveSupport::TaggedLogging, :rails_23 => true do
6
+ describe "#info" do
7
+ let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) }
8
+ let(:io) { StringIO.new }
9
+ let(:logger) { ActiveSupport::TaggedLogging.new(Timber::Logger.new(io)) }
10
+
11
+ around(:each) do |example|
12
+ Timecop.freeze(time) { example.run }
13
+ end
14
+
15
+ it "should format properly with events" do
16
+ event = Timber::Events::SQLQuery.new(sql: "select * from users", time_ms: 56, message: "select * from users")
17
+ logger.tagged("tag") do
18
+ logger.info(event)
19
+ end
20
+ expect(io.string).to include("\"tags\":[\"tag\"]")
21
+ end
22
+
23
+ it "should accept events as the second argument" do
24
+ logger.info("SQL query", payment_rejected: {customer_id: "abcd1234", amount: 100, reason: "Card expired"})
25
+ expect(io.string).to start_with("SQL query @metadata")
26
+ expect(io.string).to include("\"event\":{\"custom\":{\"payment_rejected\":")
27
+ end
28
+ end
29
+ end
30
+ end
@@ -100,20 +100,6 @@ describe Timber::Logger, :rails_23 => true do
100
100
  end
101
101
  end
102
102
 
103
- if defined?(ActiveSupport::TaggedLogging)
104
- context "with TaggedLogging", :rails_23 => false do
105
- let(:logger) { ActiveSupport::TaggedLogging.new(Timber::Logger.new(io)) }
106
-
107
- it "should format properly with events" do
108
- message = Timber::Events::SQLQuery.new(sql: "select * from users", time_ms: 56, message: "select * from users")
109
- logger.tagged("tag") do
110
- logger.info(message)
111
- end
112
- expect(io.string).to include("\"tags\":[\"tag\"]")
113
- end
114
- end
115
- end
116
-
117
103
  context "with the HTTP log device" do
118
104
  let(:io) { Timber::LogDevices::HTTP.new("my_key") }
119
105
 
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: 2.0.22
4
+ version: 2.0.23
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-05-24 00:00:00.000000000 Z
11
+ date: 2017-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -146,6 +146,7 @@ files:
146
146
  - gemfiles/rails-4.1.gemfile
147
147
  - gemfiles/rails-4.2.gemfile
148
148
  - gemfiles/rails-5.0.gemfile
149
+ - gemfiles/rails-5.1.gemfile
149
150
  - gemfiles/rails-edge.gemfile
150
151
  - lib/timber.rb
151
152
  - lib/timber/cli.rb
@@ -200,6 +201,7 @@ files:
200
201
  - lib/timber/log_entry.rb
201
202
  - lib/timber/logger.rb
202
203
  - lib/timber/overrides.rb
204
+ - lib/timber/overrides/active_support_tagged_logging.rb
203
205
  - lib/timber/overrides/lograge.rb
204
206
  - lib/timber/overrides/rails_stdout_logging.rb
205
207
  - lib/timber/util.rb
@@ -212,6 +214,7 @@ files:
212
214
  - lib/timber/util/struct.rb
213
215
  - lib/timber/version.rb
214
216
  - spec/README.md
217
+ - spec/rails/tagged_logging_spec.rb
215
218
  - spec/spec_helper.rb
216
219
  - spec/support/action_controller.rb
217
220
  - spec/support/active_record.rb
@@ -270,6 +273,7 @@ specification_version: 4
270
273
  summary: Log Better. Solve Problems Faster. https://timber.io
271
274
  test_files:
272
275
  - spec/README.md
276
+ - spec/rails/tagged_logging_spec.rb
273
277
  - spec/spec_helper.rb
274
278
  - spec/support/action_controller.rb
275
279
  - spec/support/active_record.rb