timber 2.6.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +8 -38
- data/CHANGELOG.md +9 -0
- data/README.md +30 -284
- data/Rakefile +78 -0
- data/lib/timber.rb +6 -6
- data/lib/timber/config.rb +1 -83
- data/lib/timber/config/integrations.rb +1 -47
- data/lib/timber/context.rb +3 -24
- data/lib/timber/contexts.rb +2 -30
- data/lib/timber/contexts/http.rb +16 -36
- data/lib/timber/contexts/release.rb +12 -23
- data/lib/timber/contexts/runtime.rb +9 -36
- data/lib/timber/contexts/session.rb +8 -21
- data/lib/timber/contexts/system.rb +9 -16
- data/lib/timber/contexts/user.rb +13 -33
- data/lib/timber/current_context.rb +16 -78
- data/lib/timber/event.rb +12 -9
- data/lib/timber/events.rb +1 -33
- data/lib/timber/events/controller_call.rb +20 -31
- data/lib/timber/events/error.rb +18 -26
- data/lib/timber/events/exception.rb +1 -0
- data/lib/timber/events/sql_query.rb +14 -24
- data/lib/timber/events/template_render.rb +13 -24
- data/lib/timber/integration.rb +1 -1
- data/lib/timber/integrator.rb +1 -1
- data/lib/timber/log_devices/http.rb +98 -19
- data/lib/timber/log_entry.rb +6 -24
- data/lib/timber/logger.rb +5 -14
- data/lib/timber/util.rb +1 -6
- data/lib/timber/util/non_nil_hash_builder.rb +3 -1
- data/lib/timber/version.rb +1 -1
- data/spec/README.md +2 -8
- data/spec/spec_helper.rb +0 -7
- data/spec/support/timber.rb +1 -3
- data/spec/timber/current_context_spec.rb +12 -50
- data/spec/timber/events/controller_call_spec.rb +4 -4
- data/spec/timber/events/error_spec.rb +4 -9
- data/spec/timber/log_devices/http_spec.rb +26 -2
- data/spec/timber/log_entry_spec.rb +12 -6
- data/spec/timber/logger_spec.rb +27 -68
- data/timber.gemspec +1 -1
- metadata +5 -139
- data/gemfiles/rails-3.0.gemfile +0 -5
- data/gemfiles/rails-3.1.gemfile +0 -5
- data/gemfiles/rails-3.2.gemfile +0 -5
- data/gemfiles/rails-4.0.gemfile +0 -9
- data/gemfiles/rails-4.1.gemfile +0 -9
- data/gemfiles/rails-4.2.gemfile +0 -9
- data/gemfiles/rails-5.0.gemfile +0 -9
- data/gemfiles/rails-5.1.gemfile +0 -9
- data/gemfiles/rails-edge.gemfile +0 -7
- data/lib/timber/cli.rb +0 -60
- data/lib/timber/cli/api.rb +0 -183
- data/lib/timber/cli/api/application.rb +0 -34
- data/lib/timber/cli/config_file.rb +0 -71
- data/lib/timber/cli/file_helper.rb +0 -53
- data/lib/timber/cli/installer.rb +0 -70
- data/lib/timber/cli/installers.rb +0 -102
- data/lib/timber/cli/installers/config_file.rb +0 -51
- data/lib/timber/cli/installers/other.rb +0 -59
- data/lib/timber/cli/installers/rails.rb +0 -225
- data/lib/timber/cli/installers/root.rb +0 -116
- data/lib/timber/cli/io.rb +0 -100
- data/lib/timber/cli/io/ansi.rb +0 -22
- data/lib/timber/cli/io/messages.rb +0 -198
- data/lib/timber/cli/os_helper.rb +0 -74
- data/lib/timber/config/integrations/rack.rb +0 -74
- data/lib/timber/contexts/custom.rb +0 -44
- data/lib/timber/contexts/organization.rb +0 -48
- data/lib/timber/events/custom.rb +0 -53
- data/lib/timber/events/http_request.rb +0 -71
- data/lib/timber/events/http_response.rb +0 -81
- data/lib/timber/frameworks.rb +0 -19
- data/lib/timber/frameworks/rails.rb +0 -27
- data/lib/timber/integrations.rb +0 -29
- data/lib/timber/integrations/action_controller.rb +0 -18
- data/lib/timber/integrations/action_controller/log_subscriber.rb +0 -27
- data/lib/timber/integrations/action_controller/log_subscriber/timber_log_subscriber.rb +0 -46
- data/lib/timber/integrations/action_dispatch.rb +0 -23
- data/lib/timber/integrations/action_dispatch/debug_exceptions.rb +0 -53
- data/lib/timber/integrations/action_view.rb +0 -18
- data/lib/timber/integrations/action_view/log_subscriber.rb +0 -27
- data/lib/timber/integrations/action_view/log_subscriber/timber_log_subscriber.rb +0 -83
- data/lib/timber/integrations/active_record.rb +0 -18
- data/lib/timber/integrations/active_record/log_subscriber.rb +0 -26
- data/lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb +0 -53
- data/lib/timber/integrations/rack.rb +0 -27
- data/lib/timber/integrations/rack/error_event.rb +0 -64
- data/lib/timber/integrations/rack/http_context.rb +0 -27
- data/lib/timber/integrations/rack/http_events.rb +0 -210
- data/lib/timber/integrations/rack/middleware.rb +0 -28
- data/lib/timber/integrations/rack/session_context.rb +0 -65
- data/lib/timber/integrations/rack/user_context.rb +0 -135
- data/lib/timber/integrations/rails.rb +0 -22
- data/lib/timber/integrations/rails/rack_logger.rb +0 -60
- data/lib/timber/overrides.rb +0 -12
- data/lib/timber/overrides/active_support_3_tagged_logging.rb +0 -111
- data/lib/timber/overrides/active_support_buffered_logger.rb +0 -22
- data/lib/timber/overrides/active_support_tagged_logging.rb +0 -66
- data/lib/timber/overrides/lograge.rb +0 -18
- data/lib/timber/overrides/rails_stdout_logging.rb +0 -21
- data/lib/timber/util/active_support_log_subscriber.rb +0 -37
- data/lib/timber/util/attribute_normalizer.rb +0 -89
- data/lib/timber/util/hash.rb +0 -90
- data/lib/timber/util/request.rb +0 -72
- data/lib/timber/util/struct.rb +0 -16
- data/spec/rails/tagged_logging_spec.rb +0 -44
- data/spec/support/action_controller.rb +0 -8
- data/spec/support/active_record.rb +0 -32
- data/spec/support/rails.rb +0 -67
- data/spec/support/rails/templates/_partial.html +0 -1
- data/spec/support/rails/templates/template.html +0 -1
- data/spec/timber/cli/config_file_spec.rb +0 -26
- data/spec/timber/cli/installers/config_file_spec.rb +0 -36
- data/spec/timber/cli/installers/other_spec.rb +0 -49
- data/spec/timber/cli/installers/rails_spec.rb +0 -364
- data/spec/timber/cli/installers/root_spec.rb +0 -73
- data/spec/timber/config_spec.rb +0 -28
- data/spec/timber/contexts/custom_spec.rb +0 -11
- data/spec/timber/contexts/organization_spec.rb +0 -11
- data/spec/timber/contexts/runtime_spec.rb +0 -11
- data/spec/timber/contexts/system_spec.rb +0 -11
- data/spec/timber/contexts/user_spec.rb +0 -11
- data/spec/timber/contexts_spec.rb +0 -49
- data/spec/timber/event_spec.rb +0 -10
- data/spec/timber/events/custom_spec.rb +0 -36
- data/spec/timber/events/http_request_spec.rb +0 -32
- data/spec/timber/events/http_response_spec.rb +0 -12
- data/spec/timber/events_spec.rb +0 -55
- data/spec/timber/integrations/action_controller/log_subscriber_spec.rb +0 -55
- data/spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb +0 -53
- data/spec/timber/integrations/action_view/log_subscriber_spec.rb +0 -115
- data/spec/timber/integrations/active_record/log_subscriber_spec.rb +0 -46
- data/spec/timber/integrations/rack/error_event_spec.rb +0 -63
- data/spec/timber/integrations/rack/http_context_spec.rb +0 -60
- data/spec/timber/integrations/rack/http_events_spec.rb +0 -101
- data/spec/timber/integrations/rack/session_context_spec.rb +0 -62
- data/spec/timber/integrations/rails/rack_logger_spec.rb +0 -58
- data/spec/timber/util/attribute_normalizer_spec.rb +0 -90
- data/spec/timber/util/hash_spec.rb +0 -30
- data/spec/timber/util/request_spec.rb +0 -10
@@ -3,35 +3,22 @@ require "timber/util"
|
|
3
3
|
|
4
4
|
module Timber
|
5
5
|
module Contexts
|
6
|
-
#
|
7
|
-
# to tail and filter logs by specific session IDs. Moreover, it gives you a unique
|
8
|
-
# identifier to report on user activity by session. This way your logs can tell the
|
9
|
-
# story of how many time a user has engaged your site.
|
10
|
-
#
|
11
|
-
# @note This is tracked automatically with the {Integrations::Rack::SessionContext} rack
|
12
|
-
# middleware.
|
6
|
+
# @private
|
13
7
|
class Session < Context
|
14
|
-
ID_MAX_BYTES = 256.freeze
|
15
|
-
|
16
|
-
@keyspace = :session
|
17
|
-
|
18
8
|
attr_reader :id
|
19
9
|
|
20
10
|
def initialize(attributes)
|
21
|
-
|
22
|
-
@id = normalizer.fetch!(:id, :string, :limit => ID_MAX_BYTES)
|
11
|
+
@id = attributes[:id]
|
23
12
|
end
|
24
13
|
|
25
14
|
# Builds a hash representation containing simple objects, suitable for serialization (JSON).
|
26
15
|
def to_hash
|
27
|
-
@to_hash ||=
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def as_json(_options = {})
|
33
|
-
to_hash
|
16
|
+
@to_hash ||= {
|
17
|
+
session: Util::NonNilHashBuilder.build do |h|
|
18
|
+
h.add(:id, id)
|
19
|
+
end
|
20
|
+
}
|
34
21
|
end
|
35
22
|
end
|
36
23
|
end
|
37
|
-
end
|
24
|
+
end
|
@@ -8,29 +8,22 @@ module Timber
|
|
8
8
|
# @note This is tracked automatically in {CurrentContext}. When the current context
|
9
9
|
# is initialized, the system context gets added automatically.
|
10
10
|
class System < Context
|
11
|
-
HOSTNAME_MAX_BYTES = 256.freeze
|
12
|
-
|
13
|
-
@keyspace = :system
|
14
|
-
|
15
11
|
attr_reader :hostname, :pid
|
16
12
|
|
17
13
|
def initialize(attributes)
|
18
|
-
|
19
|
-
@
|
20
|
-
@pid = normalizer.fetch(:pid, :integer)
|
14
|
+
@hostname = attributes[:hostname]
|
15
|
+
@pid = attributes[:pid]
|
21
16
|
end
|
22
17
|
|
23
18
|
# Builds a hash representation containing simple objects, suitable for serialization (JSON).
|
24
19
|
def to_hash
|
25
|
-
@to_hash ||=
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
def as_json(_options = {})
|
32
|
-
to_hash
|
20
|
+
@to_hash ||= {
|
21
|
+
system: Util::NonNilHashBuilder.build do |h|
|
22
|
+
h.add(:hostname, hostname)
|
23
|
+
h.add(:pid, pid)
|
24
|
+
end
|
25
|
+
}
|
33
26
|
end
|
34
27
|
end
|
35
28
|
end
|
36
|
-
end
|
29
|
+
end
|
data/lib/timber/contexts/user.rb
CHANGED
@@ -3,46 +3,26 @@ require "timber/util"
|
|
3
3
|
|
4
4
|
module Timber
|
5
5
|
module Contexts
|
6
|
-
#
|
7
|
-
# By adding this context all of your logs will contain user information. This allows
|
8
|
-
# filter and tail logs by specific users.
|
9
|
-
#
|
10
|
-
# @note This is tracked automatically with the {Integrations::Rack::UserContext} rack
|
11
|
-
# middleware for supported authentication frameworks. See {Integrations::Rack::UserContext}
|
12
|
-
# for more details.
|
6
|
+
# @private
|
13
7
|
class User < Context
|
14
|
-
|
15
|
-
NAME_MAX_BYTES = 256.freeze
|
16
|
-
EMAIL_MAX_BYTES = 256.freeze
|
17
|
-
TYPE_MAX_BYTES = 256.freeze
|
18
|
-
|
19
|
-
@keyspace = :user
|
20
|
-
|
21
|
-
attr_reader :id, :name, :email, :type, :meta
|
8
|
+
attr_reader :id, :name, :email
|
22
9
|
|
23
10
|
def initialize(attributes)
|
24
|
-
|
25
|
-
@
|
26
|
-
@
|
27
|
-
@email = normalizer.fetch(:email, :string, :limit => EMAIL_MAX_BYTES)
|
28
|
-
@type = normalizer.fetch(:type, :string, :limit => TYPE_MAX_BYTES)
|
29
|
-
@meta = normalizer.fetch(:meta, :hash)
|
11
|
+
@id = attributes[:id]
|
12
|
+
@name = attributes[:name]
|
13
|
+
@email = attributes[:email]
|
30
14
|
end
|
31
15
|
|
32
16
|
# Builds a hash representation containing simple objects, suitable for serialization (JSON).
|
33
17
|
def to_hash
|
34
|
-
@to_hash ||=
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
def as_json(_options = {})
|
44
|
-
to_hash
|
18
|
+
@to_hash ||= {
|
19
|
+
user: Util::NonNilHashBuilder.build do |h|
|
20
|
+
h.add(:id, id)
|
21
|
+
h.add(:name, name)
|
22
|
+
h.add(:email, email)
|
23
|
+
end
|
24
|
+
}
|
45
25
|
end
|
46
26
|
end
|
47
27
|
end
|
48
|
-
end
|
28
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require "socket"
|
2
2
|
|
3
3
|
require "timber/config"
|
4
|
-
require "timber/contexts/release"
|
5
|
-
require "timber/contexts/system"
|
6
4
|
|
7
5
|
module Timber
|
8
6
|
# Holds the current context in a thread safe memory storage. This context is
|
@@ -21,11 +19,6 @@ module Timber
|
|
21
19
|
Thread.current[THREAD_NAMESPACE] ||= new
|
22
20
|
end
|
23
21
|
|
24
|
-
# Convenience method for {CurrentContext#with}. See {CurrentContext#with} for more info.
|
25
|
-
def with(*args, &block)
|
26
|
-
instance.with(*args, &block)
|
27
|
-
end
|
28
|
-
|
29
22
|
# Convenience method for {CurrentContext#add}. See {CurrentContext#add} for more info.
|
30
23
|
def add(*args)
|
31
24
|
instance.add(*args)
|
@@ -47,32 +40,6 @@ module Timber
|
|
47
40
|
end
|
48
41
|
end
|
49
42
|
|
50
|
-
# Adds a context and then removes it when the block is finished executing.
|
51
|
-
#
|
52
|
-
# @note Because context is included with every log line, it is recommended that you limit this
|
53
|
-
# to only neccessary data.
|
54
|
-
#
|
55
|
-
# @example Adding a custom context
|
56
|
-
# Timber::CurrentContext.with({build: {version: "1.0.0"}}) do
|
57
|
-
# # ... anything logged here will include the context ...
|
58
|
-
# end
|
59
|
-
#
|
60
|
-
# @note Any custom context needs to have a single root key to be valid. i.e. instead of:
|
61
|
-
# Timber::CurrentContext.with(job_id: "123", job_name: "Refresh User Account")
|
62
|
-
#
|
63
|
-
# do
|
64
|
-
#
|
65
|
-
# Timber::CurrentContext.with(job: {job_id: "123", job_name: "Refresh User Account"})
|
66
|
-
#
|
67
|
-
# @example Adding multiple contexts
|
68
|
-
# Timber::CurrentContext.with(context1, context2) { ... }
|
69
|
-
def with(*objects)
|
70
|
-
add(*objects)
|
71
|
-
yield
|
72
|
-
ensure
|
73
|
-
remove(*objects)
|
74
|
-
end
|
75
|
-
|
76
43
|
# Adds contexts but does not remove them. See {#with} for automatic maintenance and {#remove}
|
77
44
|
# to remove them yourself.
|
78
45
|
#
|
@@ -80,7 +47,7 @@ module Timber
|
|
80
47
|
# to only neccessary data.
|
81
48
|
def add(*objects)
|
82
49
|
objects.each do |object|
|
83
|
-
|
50
|
+
hash.merge!(object.to_hash)
|
84
51
|
end
|
85
52
|
expire_cache!
|
86
53
|
self
|
@@ -93,23 +60,9 @@ module Timber
|
|
93
60
|
|
94
61
|
# Removes a context. If you wish to remove by key, or some other way, use {#hash} and
|
95
62
|
# modify the hash accordingly.
|
96
|
-
def remove(*
|
97
|
-
|
98
|
-
|
99
|
-
hash.delete(object)
|
100
|
-
else
|
101
|
-
context = Contexts.build(object)
|
102
|
-
|
103
|
-
if context.keyspace == :custom
|
104
|
-
# Custom contexts are merged and should be removed the same
|
105
|
-
hash[context.keyspace].delete(context.type)
|
106
|
-
if hash[context.keyspace] == {}
|
107
|
-
hash.delete(context.keyspace)
|
108
|
-
end
|
109
|
-
else
|
110
|
-
hash.delete(context.keyspace)
|
111
|
-
end
|
112
|
-
end
|
63
|
+
def remove(*keys)
|
64
|
+
keys.each do |keys|
|
65
|
+
hash.delete(keys)
|
113
66
|
end
|
114
67
|
expire_cache!
|
115
68
|
self
|
@@ -127,13 +80,7 @@ module Timber
|
|
127
80
|
# since the context can change as execution proceeds. Note that individual contexts
|
128
81
|
# should be immutable, and we implement snapshot caching as a result of this assumption.
|
129
82
|
def snapshot
|
130
|
-
@snapshot ||=
|
131
|
-
snapshot = hash.clone
|
132
|
-
if snapshot.key?(:custom)
|
133
|
-
snapshot[:custom] = hash[:custom].clone
|
134
|
-
end
|
135
|
-
snapshot
|
136
|
-
end
|
83
|
+
@snapshot ||= hash.clone
|
137
84
|
end
|
138
85
|
|
139
86
|
private
|
@@ -149,39 +96,30 @@ module Timber
|
|
149
96
|
new_hash = {}
|
150
97
|
|
151
98
|
# Release context
|
152
|
-
release_context =
|
153
|
-
|
154
|
-
|
99
|
+
release_context = Util::NonNilHashBuilder.build do |h|
|
100
|
+
h.add(:commit_hash, ENV['RELEASE_COMMIT'] || ENV['HEROKU_SLUG_COMMIT'])
|
101
|
+
h.add(:created_at, ENV['RELEASE_CREATED_AT'] || ENV['HEROKU_RELEASE_CREATED_AT'])
|
102
|
+
h.add(:version, ENV['RELEASE_VERSION'] || ENV['HEROKU_RELEASE_VERSION'])
|
103
|
+
end
|
104
|
+
|
105
|
+
if release_context != {}
|
106
|
+
new_hash.merge!({release: release_context})
|
155
107
|
end
|
156
108
|
|
157
109
|
# System context
|
158
110
|
hostname = Socket.gethostname
|
159
111
|
pid = Process.pid
|
160
112
|
system_context = Contexts::System.new(hostname: hostname, pid: pid)
|
161
|
-
|
113
|
+
new_hash.merge!(system_context.to_hash)
|
162
114
|
|
163
115
|
# Runtime context
|
164
116
|
thread_object_id = Thread.current.object_id
|
165
|
-
runtime_context =
|
166
|
-
|
117
|
+
runtime_context = {thread_id: thread_object_id}
|
118
|
+
new_hash.merge!({runtime: runtime_context})
|
167
119
|
|
168
120
|
new_hash
|
169
121
|
end
|
170
122
|
|
171
|
-
def add_to!(hash, object)
|
172
|
-
context = Contexts.build(object) # Normalizes objects into a Timber::Context descendant.
|
173
|
-
key = context.keyspace
|
174
|
-
json = context.as_json # Convert to json now so that we aren't doing it for every line
|
175
|
-
if key == :custom
|
176
|
-
# Custom contexts are merged into the space
|
177
|
-
hash[key] ||= {}
|
178
|
-
hash[key].merge!(json)
|
179
|
-
else
|
180
|
-
hash[key] = json
|
181
|
-
end
|
182
|
-
hash
|
183
|
-
end
|
184
|
-
|
185
123
|
# Hook to clear any caching implement in this class
|
186
124
|
def expire_cache!
|
187
125
|
@snapshot = nil
|
data/lib/timber/event.rb
CHANGED
@@ -2,12 +2,10 @@ module Timber
|
|
2
2
|
# Base class for `Timber::Events::*`
|
3
3
|
# @private
|
4
4
|
class Event
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def as_json(options = {})
|
10
|
-
raise NotImplementedError.new
|
5
|
+
attr_reader :message, :metadata
|
6
|
+
def initialize(message, metadata)
|
7
|
+
@message = message || ""
|
8
|
+
@metadata = metadata || {}
|
11
9
|
end
|
12
10
|
|
13
11
|
# This ensures that Timber events get logged as messages if they are passed to
|
@@ -19,15 +17,20 @@ module Timber
|
|
19
17
|
end
|
20
18
|
|
21
19
|
def to_json(options = {})
|
22
|
-
|
20
|
+
metadata.to_json(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_hash
|
24
|
+
metadata
|
23
25
|
end
|
26
|
+
alias to_h to_hash
|
24
27
|
|
25
28
|
def to_msgpack(*args)
|
26
|
-
|
29
|
+
metadata.to_msgpack(*args)
|
27
30
|
end
|
28
31
|
|
29
32
|
def to_s
|
30
33
|
message
|
31
34
|
end
|
32
35
|
end
|
33
|
-
end
|
36
|
+
end
|
data/lib/timber/events.rb
CHANGED
@@ -1,42 +1,10 @@
|
|
1
1
|
require "timber/events/controller_call"
|
2
|
-
require "timber/events/custom"
|
3
2
|
require "timber/events/error"
|
4
|
-
require "timber/events/http_request"
|
5
|
-
require "timber/events/http_response"
|
6
3
|
require "timber/events/sql_query"
|
7
4
|
require "timber/events/template_render"
|
8
5
|
|
9
6
|
module Timber
|
10
7
|
# Namespace for all Timber supported events.
|
11
8
|
module Events
|
12
|
-
# Protocol for casting objects into a `Timber::Event`.
|
13
|
-
#
|
14
|
-
# @example Casting a hash
|
15
|
-
# Timber::Events.build({type: :custom_event, message: "My log message", data: {my: "data"}})
|
16
|
-
def self.build(obj)
|
17
|
-
if obj.is_a?(::Timber::Event)
|
18
|
-
obj
|
19
|
-
elsif obj.respond_to?(:to_timber_event)
|
20
|
-
obj.to_timber_event
|
21
|
-
elsif obj.is_a?(Hash) && obj.key?(:message) && obj.length == 2
|
22
|
-
event = obj.select { |k,v| k != :message }
|
23
|
-
type = event.keys.first
|
24
|
-
data = event.values.first
|
25
|
-
|
26
|
-
Events::Custom.new(
|
27
|
-
type: type,
|
28
|
-
message: obj[:message],
|
29
|
-
data: data
|
30
|
-
)
|
31
|
-
elsif obj.is_a?(Struct) && obj.respond_to?(:message) && obj.respond_to?(:type)
|
32
|
-
Events::Custom.new(
|
33
|
-
type: obj.type,
|
34
|
-
message: obj.message,
|
35
|
-
data: obj.respond_to?(:to_h) ? obj.to_h : Timber::Util::Struct.to_hash(obj) # ruby 1.9.3 does not have to_h :(
|
36
|
-
)
|
37
|
-
else
|
38
|
-
nil
|
39
|
-
end
|
40
|
-
end
|
41
9
|
end
|
42
|
-
end
|
10
|
+
end
|
@@ -1,43 +1,22 @@
|
|
1
|
-
require "timber/event"
|
2
1
|
require "timber/util"
|
2
|
+
require "timber/event"
|
3
3
|
|
4
4
|
module Timber
|
5
5
|
module Events
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# Processing by PagesController#home as HTML
|
9
|
-
#
|
10
|
-
# @note This event should be installed automatically through integrations,
|
11
|
-
# such as the {Integrations::ActionController} integration.
|
6
|
+
# @private
|
12
7
|
class ControllerCall < Timber::Event
|
13
|
-
|
14
|
-
FORMAT_MAX_BYTES = 256.freeze
|
15
|
-
CONTROLLER_MAX_BYTES = 256.freeze
|
16
|
-
PARAMS_JSON_MAX_BYTES = 32_768.freeze
|
17
|
-
PASSWORD_NAME = 'password'.freeze
|
18
|
-
|
19
|
-
attr_reader :controller, :action, :params, :format
|
8
|
+
attr_reader :controller, :action, :params, :params_json, :format
|
20
9
|
|
21
10
|
def initialize(attributes)
|
22
|
-
|
23
|
-
@
|
24
|
-
@
|
25
|
-
@params = normalizer.fetch(:params, :hash, :sanitize => [PASSWORD_NAME])
|
26
|
-
@format = normalizer.fetch(:format, :string, :limit => FORMAT_MAX_BYTES)
|
27
|
-
end
|
11
|
+
@controller = attributes[:controller]
|
12
|
+
@action = attributes[:action]
|
13
|
+
@params = attributes[:params]
|
28
14
|
|
29
|
-
|
30
|
-
|
31
|
-
h.add(:controller, controller)
|
32
|
-
h.add(:action, action)
|
33
|
-
h.add(:params_json, params.to_json.byteslice(0, PARAMS_JSON_MAX_BYTES))
|
15
|
+
if @params
|
16
|
+
@params_json = @params.to_json
|
34
17
|
end
|
35
|
-
end
|
36
|
-
alias to_h to_hash
|
37
18
|
|
38
|
-
|
39
|
-
def as_json(_options = {})
|
40
|
-
{:controller_call => to_hash}
|
19
|
+
@format = attributes[:format]
|
41
20
|
end
|
42
21
|
|
43
22
|
def message
|
@@ -50,6 +29,16 @@ module Timber
|
|
50
29
|
end
|
51
30
|
message
|
52
31
|
end
|
32
|
+
|
33
|
+
def to_hash
|
34
|
+
{
|
35
|
+
controller_called: Util::NonNilHashBuilder.build do |h|
|
36
|
+
h.add(:controller, controller)
|
37
|
+
h.add(:action, action)
|
38
|
+
h.add(:params_json, params_json)
|
39
|
+
end
|
40
|
+
}
|
41
|
+
end
|
53
42
|
end
|
54
43
|
end
|
55
|
-
end
|
44
|
+
end
|