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 +4 -4
- data/lib/timber/contexts/user.rb +15 -2
- data/lib/timber/events/http_server_request.rb +1 -4
- data/lib/timber/log_entry.rb +2 -2
- data/lib/timber/util/hash.rb +15 -3
- data/lib/timber/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4136faf51b1142a6707645674bb4837b2584844
|
4
|
+
data.tar.gz: 85b1e858102d857f4bba6cddce0f74009801367d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8dd6a597c362cd30ea3480d0fc435768f3c22e813344b43554aa66bf6f2e093b8e2ba262d44aaa42aab24288d364d34be52d14384acdb5451552043de49a11d
|
7
|
+
data.tar.gz: 386e1e71a751dec353c51442697a4dd455a325bbfd0dab82a2df240efa6908a933ff1b2f627634f608921cc238902b379430c20c464eb268aac259d345e7c751
|
data/lib/timber/contexts/user.rb
CHANGED
@@ -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
|
-
#
|
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
|
-
|
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
|
data/lib/timber/log_entry.rb
CHANGED
@@ -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.
|
63
|
+
Util::Hash.deep_compact(hash)
|
64
64
|
end
|
65
65
|
|
66
66
|
def to_json(options = {})
|
data/lib/timber/util/hash.rb
CHANGED
@@ -4,10 +4,22 @@ module Timber
|
|
4
4
|
module Hash
|
5
5
|
extend self
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
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
|
data/lib/timber/version.rb
CHANGED