timber 1.1.4 → 1.1.5

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: a530de0193b8608dad9cf57cd4695260fa861eda
4
- data.tar.gz: 30d326dde43b0fa6ecaa68dc3361a2379bbc8a54
3
+ metadata.gz: e4136faf51b1142a6707645674bb4837b2584844
4
+ data.tar.gz: 85b1e858102d857f4bba6cddce0f74009801367d
5
5
  SHA512:
6
- metadata.gz: fe81f00a478333a7a51b95b7136d14f843e462e71dda131196ed0fbdc53fe86c52b5ea5e163926cefe09b0ca1c3a493fc8fed7e1de96c7707fedb0d556d8028e
7
- data.tar.gz: 8e0af30d2ecb86e448b4d3d90f679ec00adca9fbf204a496cb694ac9c476fea63760b925f3a06455e3633e4ad6175cec46858e02f0c7168294b4dfe02f2cbb31
6
+ metadata.gz: d8dd6a597c362cd30ea3480d0fc435768f3c22e813344b43554aa66bf6f2e093b8e2ba262d44aaa42aab24288d364d34be52d14384acdb5451552043de49a11d
7
+ data.tar.gz: 386e1e71a751dec353c51442697a4dd455a325bbfd0dab82a2df240efa6908a933ff1b2f627634f608921cc238902b379430c20c464eb268aac259d345e7c751
@@ -8,14 +8,27 @@ module Timber
8
8
  # Note: Timber will attempt to automatically add this if you add a #current_user
9
9
  # method to your controllers. Most authentication solutions do this for you automatically.
10
10
  #
11
- # Example:
12
- #
11
+ # @example Basic example
13
12
  # user_context = Timber::Contexts::User.new(id: "abc1234", name: "Ben Johnson")
14
13
  # Timber::CurrentContext.with(user_context) do
15
14
  # # Logging will automatically include this context
16
15
  # logger.info("This is a log message")
17
16
  # end
18
17
  #
18
+ # @example Rails example
19
+ # class ApplicationController < ActionController::Base
20
+ # around_filter :capture_user_context
21
+ # private
22
+ # def capture_user_context
23
+ # if current_user
24
+ # user_context = Timber::Contexts::User.new(id: current_user.id,
25
+ # name: current_user.name, email: current_user.email)
26
+ # Timber::CurrentContext.with(user_context) { yield }
27
+ # else
28
+ # yield
29
+ # end
30
+ # end
31
+ # end
19
32
  class User < Context
20
33
  @keyspace = :user
21
34
 
@@ -29,10 +29,7 @@ module Timber
29
29
  alias to_h to_hash
30
30
 
31
31
  def as_json(_options = {})
32
- hash = to_hash
33
- hash[:headers] = Util::Hash.compact(hash[:headers])
34
- hash = Util::Hash.compact(hash)
35
- {:server_side_app => {:http_request => hash}}
32
+ {:server_side_app => {:http_request => to_hash}}
36
33
  end
37
34
 
38
35
  def message
@@ -39,7 +39,7 @@ module Timber
39
39
  :time_ms => time_ms}
40
40
 
41
41
  if !event.nil?
42
- hash[:event] = event
42
+ hash[:event] = event.as_json
43
43
  end
44
44
 
45
45
  if !context_snapshot.nil? && context_snapshot.length > 0
@@ -60,7 +60,7 @@ module Timber
60
60
  hash
61
61
  end
62
62
 
63
- Util::Hash.compact(hash)
63
+ Util::Hash.deep_compact(hash)
64
64
  end
65
65
 
66
66
  def to_json(options = {})
@@ -4,10 +4,22 @@ module Timber
4
4
  module Hash
5
5
  extend self
6
6
 
7
- def compact(hash)
8
- hash.select do |k, v|
9
- v != nil && v != {} && v != []
7
+ def deep_compact(hash)
8
+ new_hash = {}
9
+
10
+ hash.each do |k, v|
11
+ v = if v.is_a?(::Hash)
12
+ deep_compact(v)
13
+ else
14
+ v
15
+ end
16
+
17
+ if v != nil && v != "" && v != {} && v != []
18
+ new_hash[k] = v
19
+ end
10
20
  end
21
+
22
+ new_hash
11
23
  end
12
24
  end
13
25
  end
@@ -1,3 +1,3 @@
1
1
  module Timber
2
- VERSION = "1.1.4"
2
+ VERSION = "1.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timber
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timber Technologies, Inc.