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.
Files changed (142) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +8 -38
  3. data/CHANGELOG.md +9 -0
  4. data/README.md +30 -284
  5. data/Rakefile +78 -0
  6. data/lib/timber.rb +6 -6
  7. data/lib/timber/config.rb +1 -83
  8. data/lib/timber/config/integrations.rb +1 -47
  9. data/lib/timber/context.rb +3 -24
  10. data/lib/timber/contexts.rb +2 -30
  11. data/lib/timber/contexts/http.rb +16 -36
  12. data/lib/timber/contexts/release.rb +12 -23
  13. data/lib/timber/contexts/runtime.rb +9 -36
  14. data/lib/timber/contexts/session.rb +8 -21
  15. data/lib/timber/contexts/system.rb +9 -16
  16. data/lib/timber/contexts/user.rb +13 -33
  17. data/lib/timber/current_context.rb +16 -78
  18. data/lib/timber/event.rb +12 -9
  19. data/lib/timber/events.rb +1 -33
  20. data/lib/timber/events/controller_call.rb +20 -31
  21. data/lib/timber/events/error.rb +18 -26
  22. data/lib/timber/events/exception.rb +1 -0
  23. data/lib/timber/events/sql_query.rb +14 -24
  24. data/lib/timber/events/template_render.rb +13 -24
  25. data/lib/timber/integration.rb +1 -1
  26. data/lib/timber/integrator.rb +1 -1
  27. data/lib/timber/log_devices/http.rb +98 -19
  28. data/lib/timber/log_entry.rb +6 -24
  29. data/lib/timber/logger.rb +5 -14
  30. data/lib/timber/util.rb +1 -6
  31. data/lib/timber/util/non_nil_hash_builder.rb +3 -1
  32. data/lib/timber/version.rb +1 -1
  33. data/spec/README.md +2 -8
  34. data/spec/spec_helper.rb +0 -7
  35. data/spec/support/timber.rb +1 -3
  36. data/spec/timber/current_context_spec.rb +12 -50
  37. data/spec/timber/events/controller_call_spec.rb +4 -4
  38. data/spec/timber/events/error_spec.rb +4 -9
  39. data/spec/timber/log_devices/http_spec.rb +26 -2
  40. data/spec/timber/log_entry_spec.rb +12 -6
  41. data/spec/timber/logger_spec.rb +27 -68
  42. data/timber.gemspec +1 -1
  43. metadata +5 -139
  44. data/gemfiles/rails-3.0.gemfile +0 -5
  45. data/gemfiles/rails-3.1.gemfile +0 -5
  46. data/gemfiles/rails-3.2.gemfile +0 -5
  47. data/gemfiles/rails-4.0.gemfile +0 -9
  48. data/gemfiles/rails-4.1.gemfile +0 -9
  49. data/gemfiles/rails-4.2.gemfile +0 -9
  50. data/gemfiles/rails-5.0.gemfile +0 -9
  51. data/gemfiles/rails-5.1.gemfile +0 -9
  52. data/gemfiles/rails-edge.gemfile +0 -7
  53. data/lib/timber/cli.rb +0 -60
  54. data/lib/timber/cli/api.rb +0 -183
  55. data/lib/timber/cli/api/application.rb +0 -34
  56. data/lib/timber/cli/config_file.rb +0 -71
  57. data/lib/timber/cli/file_helper.rb +0 -53
  58. data/lib/timber/cli/installer.rb +0 -70
  59. data/lib/timber/cli/installers.rb +0 -102
  60. data/lib/timber/cli/installers/config_file.rb +0 -51
  61. data/lib/timber/cli/installers/other.rb +0 -59
  62. data/lib/timber/cli/installers/rails.rb +0 -225
  63. data/lib/timber/cli/installers/root.rb +0 -116
  64. data/lib/timber/cli/io.rb +0 -100
  65. data/lib/timber/cli/io/ansi.rb +0 -22
  66. data/lib/timber/cli/io/messages.rb +0 -198
  67. data/lib/timber/cli/os_helper.rb +0 -74
  68. data/lib/timber/config/integrations/rack.rb +0 -74
  69. data/lib/timber/contexts/custom.rb +0 -44
  70. data/lib/timber/contexts/organization.rb +0 -48
  71. data/lib/timber/events/custom.rb +0 -53
  72. data/lib/timber/events/http_request.rb +0 -71
  73. data/lib/timber/events/http_response.rb +0 -81
  74. data/lib/timber/frameworks.rb +0 -19
  75. data/lib/timber/frameworks/rails.rb +0 -27
  76. data/lib/timber/integrations.rb +0 -29
  77. data/lib/timber/integrations/action_controller.rb +0 -18
  78. data/lib/timber/integrations/action_controller/log_subscriber.rb +0 -27
  79. data/lib/timber/integrations/action_controller/log_subscriber/timber_log_subscriber.rb +0 -46
  80. data/lib/timber/integrations/action_dispatch.rb +0 -23
  81. data/lib/timber/integrations/action_dispatch/debug_exceptions.rb +0 -53
  82. data/lib/timber/integrations/action_view.rb +0 -18
  83. data/lib/timber/integrations/action_view/log_subscriber.rb +0 -27
  84. data/lib/timber/integrations/action_view/log_subscriber/timber_log_subscriber.rb +0 -83
  85. data/lib/timber/integrations/active_record.rb +0 -18
  86. data/lib/timber/integrations/active_record/log_subscriber.rb +0 -26
  87. data/lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb +0 -53
  88. data/lib/timber/integrations/rack.rb +0 -27
  89. data/lib/timber/integrations/rack/error_event.rb +0 -64
  90. data/lib/timber/integrations/rack/http_context.rb +0 -27
  91. data/lib/timber/integrations/rack/http_events.rb +0 -210
  92. data/lib/timber/integrations/rack/middleware.rb +0 -28
  93. data/lib/timber/integrations/rack/session_context.rb +0 -65
  94. data/lib/timber/integrations/rack/user_context.rb +0 -135
  95. data/lib/timber/integrations/rails.rb +0 -22
  96. data/lib/timber/integrations/rails/rack_logger.rb +0 -60
  97. data/lib/timber/overrides.rb +0 -12
  98. data/lib/timber/overrides/active_support_3_tagged_logging.rb +0 -111
  99. data/lib/timber/overrides/active_support_buffered_logger.rb +0 -22
  100. data/lib/timber/overrides/active_support_tagged_logging.rb +0 -66
  101. data/lib/timber/overrides/lograge.rb +0 -18
  102. data/lib/timber/overrides/rails_stdout_logging.rb +0 -21
  103. data/lib/timber/util/active_support_log_subscriber.rb +0 -37
  104. data/lib/timber/util/attribute_normalizer.rb +0 -89
  105. data/lib/timber/util/hash.rb +0 -90
  106. data/lib/timber/util/request.rb +0 -72
  107. data/lib/timber/util/struct.rb +0 -16
  108. data/spec/rails/tagged_logging_spec.rb +0 -44
  109. data/spec/support/action_controller.rb +0 -8
  110. data/spec/support/active_record.rb +0 -32
  111. data/spec/support/rails.rb +0 -67
  112. data/spec/support/rails/templates/_partial.html +0 -1
  113. data/spec/support/rails/templates/template.html +0 -1
  114. data/spec/timber/cli/config_file_spec.rb +0 -26
  115. data/spec/timber/cli/installers/config_file_spec.rb +0 -36
  116. data/spec/timber/cli/installers/other_spec.rb +0 -49
  117. data/spec/timber/cli/installers/rails_spec.rb +0 -364
  118. data/spec/timber/cli/installers/root_spec.rb +0 -73
  119. data/spec/timber/config_spec.rb +0 -28
  120. data/spec/timber/contexts/custom_spec.rb +0 -11
  121. data/spec/timber/contexts/organization_spec.rb +0 -11
  122. data/spec/timber/contexts/runtime_spec.rb +0 -11
  123. data/spec/timber/contexts/system_spec.rb +0 -11
  124. data/spec/timber/contexts/user_spec.rb +0 -11
  125. data/spec/timber/contexts_spec.rb +0 -49
  126. data/spec/timber/event_spec.rb +0 -10
  127. data/spec/timber/events/custom_spec.rb +0 -36
  128. data/spec/timber/events/http_request_spec.rb +0 -32
  129. data/spec/timber/events/http_response_spec.rb +0 -12
  130. data/spec/timber/events_spec.rb +0 -55
  131. data/spec/timber/integrations/action_controller/log_subscriber_spec.rb +0 -55
  132. data/spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb +0 -53
  133. data/spec/timber/integrations/action_view/log_subscriber_spec.rb +0 -115
  134. data/spec/timber/integrations/active_record/log_subscriber_spec.rb +0 -46
  135. data/spec/timber/integrations/rack/error_event_spec.rb +0 -63
  136. data/spec/timber/integrations/rack/http_context_spec.rb +0 -60
  137. data/spec/timber/integrations/rack/http_events_spec.rb +0 -101
  138. data/spec/timber/integrations/rack/session_context_spec.rb +0 -62
  139. data/spec/timber/integrations/rails/rack_logger_spec.rb +0 -58
  140. data/spec/timber/util/attribute_normalizer_spec.rb +0 -90
  141. data/spec/timber/util/hash_spec.rb +0 -30
  142. data/spec/timber/util/request_spec.rb +0 -10
@@ -1,21 +1,21 @@
1
1
  # Base (must come first, order matters)
2
2
  require "timber/version"
3
- require "timber/overrides"
4
3
  require "timber/config"
5
4
  require "timber/util"
6
5
 
6
+ # Load frameworks
7
+
7
8
  # Other (sorted alphabetically)
8
9
  require "timber/contexts"
9
10
  require "timber/current_context"
10
11
  require "timber/events"
12
+ require "timber/integration"
11
13
  require "timber/log_devices"
12
14
  require "timber/log_entry"
13
15
  require "timber/logger"
14
- require "timber/integrations"
15
16
  require "timber/timer"
16
-
17
- # Load frameworks
18
- require "timber/frameworks"
17
+ require "timber/integrator"
18
+ require "timber/integration"
19
19
 
20
20
  module Timber
21
21
  # Access the main configuration object. Please see {{Timber::Config}} for more details.
@@ -33,4 +33,4 @@ module Timber
33
33
  def self.with_context(context, &block)
34
34
  CurrentContext.with(context, &block)
35
35
  end
36
- end
36
+ end
@@ -1,8 +1,6 @@
1
1
  require "logger"
2
2
  require "singleton"
3
3
 
4
- require "timber/config/integrations"
5
-
6
4
  module Timber
7
5
  # Singleton class for reading and setting Timber configuration.
8
6
  #
@@ -25,7 +23,6 @@ module Timber
25
23
  end
26
24
  end
27
25
 
28
- DEFAULT_HTTP_BODY_LIMIT = 2048.freeze
29
26
  DEVELOPMENT_NAME = "development".freeze
30
27
  PRODUCTION_NAME = "production".freeze
31
28
  STAGING_NAME = "staging".freeze
@@ -35,11 +32,6 @@ module Timber
35
32
 
36
33
  attr_writer :http_body_limit
37
34
 
38
- # @private
39
- def initialize
40
- @http_body_limit = DEFAULT_HTTP_BODY_LIMIT
41
- end
42
-
43
35
  # Convenience method for logging debug statements to the debug logger
44
36
  # set in this class.
45
37
  # @private
@@ -112,39 +104,6 @@ module Timber
112
104
  @environment ||= ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development"
113
105
  end
114
106
 
115
- # This is a list of header keys that should be filtered. Note, all headers are
116
- # normalized to down-case. So please _only_ pass down-cased headers.
117
- #
118
- # @example Rails
119
- # # config/environments/production.rb
120
- # config.timber.header_filter_headers += ['api-key']
121
- def http_header_filters=(value)
122
- @http_header_filters = value
123
- end
124
-
125
- # Accessor method for {#http_header_filters=}
126
- def http_header_filters
127
- @http_header_filters ||= []
128
- end
129
-
130
- # Truncates captured HTTP bodies to this specified limit. The default is `2048`.
131
- # If you want to capture more data, you can raise this to a maximum of `8192`,
132
- # or lower this to be more efficient with data. `2048` characters should give you a good
133
- # idea of the body content.
134
- #
135
- # @example Rails
136
- # config.timber.http_body_limit = 2048
137
- # @example Everything else
138
- # Timber::Config.instance.http_body_limit = 2048
139
- def http_body_limit=(value)
140
- @http_body_limit = value
141
- end
142
-
143
- # Accessor method for {#http_body_limit=}
144
- def http_body_limit
145
- @http_body_limit
146
- end
147
-
148
107
  # Convenience method for accessing the various `Timber::Integrations::*` class
149
108
  # settings. These provides settings for enabling, disabled, and silencing integrations.
150
109
  # See {Integrations} for a full list of available methods.
@@ -152,47 +111,6 @@ module Timber
152
111
  Integrations
153
112
  end
154
113
 
155
- # A convenience method that automatically sets Timber's configuration to closely match
156
- # the behavior of the ruby lograge library. This makes it easier when transitioning
157
- # from lograge.
158
- #
159
- # It turns this:
160
- #
161
- # Started GET "/" for 127.0.0.1 at 2012-03-10 14:28:14 +0100
162
- # Processing by HomeController#index as HTML
163
- # Rendered text template within layouts/application (0.0ms)
164
- # Rendered layouts/_assets.html.erb (2.0ms)
165
- # Rendered layouts/_top.html.erb (2.6ms)
166
- # Rendered layouts/_about.html.erb (0.3ms)
167
- # Rendered layouts/_google_analytics.html.erb (0.4ms)
168
- # Completed 200 OK in 79ms (Views: 78.8ms | ActiveRecord: 0.0ms)
169
- #
170
- # Into this:
171
- #
172
- # Get "/" sent 200 OK in 79ms @metadata {...}
173
- #
174
- # In other words it:
175
- #
176
- # 1. Silences ActiveRecord SQL query logs.
177
- # 2. Silences ActiveView template rendering logs.
178
- # 3. Silences ActionController controller call logs.
179
- # 4. Collapses HTTP request and response logs into a single event.
180
- #
181
- # Notice also that is is not exactly like lograge. This is intentional. Lograge has
182
- # a number of downsides:
183
- #
184
- # 1. The attribute names (`method`, `format`, `status`, `db`, etc) are too generalized and vague.
185
- # This makes it _very_ likely that it will clash with other structured data you're
186
- # logging.
187
- # 2. It doesn't support context making it near impossible to view in-app logs generated for
188
- # the same request.
189
- def logrageify!
190
- integrations.action_controller.silence = true
191
- integrations.action_view.silence = true
192
- integrations.active_record.silence = true
193
- integrations.rack.http_events.collapse_into_single_event = true
194
- end
195
-
196
114
  # This is the _main_ logger Timber writes to. All of the Timber integrations write to
197
115
  # this logger instance. It should be set to your global logger. For Rails, this is set
198
116
  # automatically to `Rails.logger`, you should not have to set this.
@@ -233,4 +151,4 @@ module Timber
233
151
  environment == STAGING_NAME
234
152
  end
235
153
  end
236
- end
154
+ end
@@ -1,9 +1,3 @@
1
- require "timber/config/integrations/rack"
2
- require "timber/integrations/action_controller"
3
- require "timber/integrations/action_view"
4
- require "timber/integrations/active_record"
5
- require "timber/integrations/rack"
6
-
7
1
  module Timber
8
2
  class Config
9
3
  # Convenience module for accessing the various `Timber::Integrations::*` classes
@@ -18,46 +12,6 @@ module Timber
18
12
  # config.integrations.active_record.silence = true
19
13
  module Integrations
20
14
  extend self
21
-
22
- # Convenience method for accessing the {Timber::Integrations::ActionController} class
23
- # specific configuration.
24
- #
25
- # @example
26
- # config = Timber::Config.instance
27
- # config.integrations.action_controller.silence = true
28
- def action_controller
29
- Timber::Integrations::ActionController
30
- end
31
-
32
- # Convenience method for accessing the {Timber::Integrations::ActionView} class
33
- # specific configuration.
34
- #
35
- # @example
36
- # config = Timber::Config.instance
37
- # config.integrations.action_view.silence = true
38
- def action_view
39
- Timber::Integrations::ActionView
40
- end
41
-
42
- # Convenience method for accessing the {Timber::Integrations::ActiveRecord} class
43
- # specific configuration.
44
- #
45
- # @example
46
- # config = Timber::Config.instance
47
- # config.integrations.active_record.silence = true
48
- def active_record
49
- Timber::Integrations::ActiveRecord
50
- end
51
-
52
- # Convenience method for accessing the various `Timber::Integrations::Rack::*`
53
- # classes. See {Rack} for a list of methods available.
54
- #
55
- # @example
56
- # config = Timber::Config.instance
57
- # config.integrations.rack.http_events.enabled = true
58
- def rack
59
- Rack
60
- end
61
15
  end
62
16
  end
63
- end
17
+ end
@@ -2,29 +2,8 @@ module Timber
2
2
  # Base class for all `Timber::Contexts::*` classes.
3
3
  # @private
4
4
  class Context
5
- class << self
6
- # The keyspace is the key used when storing the context.
7
- # For example:
8
- #
9
- # {:build => {:version => "1.0.0"}}
10
- #
11
- # The keyspace in the above context is `:build`. This is required
12
- # because it prevents key name conflicts. Without the keyspace
13
- # it very possible another context type might also have a `:version`
14
- # attribute.
15
- def keyspace
16
- @keyspace || raise(NotImplementedError.new)
17
- end
18
- end
19
-
20
- # Returns a simple structure sufficient for encoding. We use
21
- # `as_json` as the name since this is a ruby pattern.
22
- def as_json(options = {})
23
- raise NotImplementedError.new
24
- end
25
-
26
- def keyspace
27
- self.class.keyspace
5
+ def to_hash
6
+ raise(NotImplementedError.new)
28
7
  end
29
8
  end
30
- end
9
+ end
@@ -1,6 +1,4 @@
1
- require "timber/contexts/custom"
2
1
  require "timber/contexts/http"
3
- require "timber/contexts/organization"
4
2
  require "timber/contexts/release"
5
3
  require "timber/contexts/runtime"
6
4
  require "timber/contexts/session"
@@ -8,33 +6,7 @@ require "timber/contexts/system"
8
6
  require "timber/contexts/user"
9
7
 
10
8
  module Timber
11
- # Namespace for all Timber supported Contexts.
9
+ # @private
12
10
  module Contexts
13
- # Protocol for casting objects into a {Timber::Context}.
14
- #
15
- # @example Casting a hash
16
- # Timber::Contexts.build(deploy: {version: "1.0.0"})
17
- def self.build(obj)
18
- if obj.is_a?(::Timber::Context)
19
- obj
20
- elsif obj.respond_to?(:to_timber_context)
21
- obj.to_timber_context
22
- elsif obj.is_a?(Hash) && obj.length == 1
23
- type = obj.keys.first
24
- data = obj.values.first
25
-
26
- Contexts::Custom.new(
27
- type: type,
28
- data: data
29
- )
30
- elsif obj.is_a?(Struct) && obj.respond_to?(:type)
31
- Contexts::Custom.new(
32
- type: obj.type,
33
- data: obj.respond_to?(:to_h) ? obj.to_h : Timber::Util::Struct.to_hash(obj) # ruby 1.9.3 does not have to_h
34
- )
35
- else
36
- nil
37
- end
38
- end
39
11
  end
40
- end
12
+ end
@@ -2,50 +2,30 @@ require "timber/context"
2
2
 
3
3
  module Timber
4
4
  module Contexts
5
- # The HTTP context adds data about the current HTTP request being processed to your logs.
6
- # This allows you to tail and filter by this data. A very useful piece of data this
7
- # captures is the request ID. This gives you the ability to trace requests and view logs
8
- # for a specific request only. For example, say you've searched your logs and found the
9
- # specific line you are looking for, but it lacks context. With Timber you can simply
10
- # click the request ID and "zoom out" to view all logs for that request. This gives you
11
- # complete picture of how the log line in questio was generated.
12
- #
13
- # @note This context should be installed automatically through the,
14
- # {Intregrations::Rack::HTTPContext} Rack middleware.
5
+ # @private
15
6
  class HTTP < Context
16
- HOST_MAX_BYTES = 256.freeze
17
- METHOD_MAX_BYTES = 20.freeze
18
- PATH_MAX_BYTES = 2048.freeze
19
- REMOTE_ADDR_MAX_BYTES = 256.freeze
20
- REQUEST_ID_MAX_BYTES = 256.freeze
21
-
22
- @keyspace = :http
23
-
24
7
  attr_reader :host, :method, :path, :remote_addr, :request_id
25
8
 
26
9
  def initialize(attributes)
27
- normalizer = Util::AttributeNormalizer.new(attributes)
28
- @host = normalizer.fetch(:host, :string, :limit => HOST_MAX_BYTES)
29
- @method = normalizer.fetch!(:method, :string, :upcase => true, :limit => METHOD_MAX_BYTES)
30
- @path = normalizer.fetch(:path, :string, :limit => PATH_MAX_BYTES)
31
- @remote_addr = normalizer.fetch(:remote_addr, :string, :limit => REMOTE_ADDR_MAX_BYTES)
32
- @request_id = normalizer.fetch(:request_id, :string, :limit => REQUEST_ID_MAX_BYTES)
10
+ @host = attributes[:host]
11
+ @method = attributes[:method]
12
+ @path = attributes[:path]
13
+ @remote_addr = attributes[:remote_addr]
14
+ @request_id = attributes[:request_id]
33
15
  end
34
16
 
35
17
  # Builds a hash representation containing simple objects, suitable for serialization (JSON).
36
18
  def to_hash
37
- @to_hash ||= Util::NonNilHashBuilder.build do |h|
38
- h.add(:host, host)
39
- h.add(:method, method)
40
- h.add(:path, path)
41
- h.add(:remote_addr, remote_addr)
42
- h.add(:request_id, request_id)
43
- end
44
- end
45
-
46
- def as_json(_options = {})
47
- to_hash
19
+ @to_hash ||= {
20
+ http: Util::NonNilHashBuilder.build do |h|
21
+ h.add(:host, host)
22
+ h.add(:method, method)
23
+ h.add(:path, path)
24
+ h.add(:remote_addr, remote_addr)
25
+ h.add(:request_id, request_id)
26
+ end
27
+ }
48
28
  end
49
29
  end
50
30
  end
51
- end
31
+ end
@@ -4,16 +4,8 @@ require "timber/util"
4
4
 
5
5
  module Timber
6
6
  module Contexts
7
- # The release context tracks application releases / versions / deploys.
8
- #
9
- # @note To automatically set this context, see {.from_env}.
7
+ # @private
10
8
  class Release < Context
11
- COMMIT_HASH_MAX_BYTES = 256.freeze
12
- CREATED_AT_MAX_BYTES = 256.freeze
13
- VERSION_MAX_BYTES = 256.freeze
14
-
15
- @keyspace = :release
16
-
17
9
  class << self
18
10
  # Builds a release context based on environment variables. Simply add the
19
11
  # `RELEASE_COMMIT`, `RELEASE_CREATED_AT`, or the `RELEASE_VERSION` env vars
@@ -40,24 +32,21 @@ module Timber
40
32
  attr_reader :commit_hash, :created_at, :version
41
33
 
42
34
  def initialize(attributes)
43
- normalizer = Util::AttributeNormalizer.new(attributes)
44
- @commit_hash = normalizer.fetch(:commit_hash, :string, :limit => COMMIT_HASH_MAX_BYTES)
45
- @created_at = normalizer.fetch(:created_at, :string, :limit => CREATED_AT_MAX_BYTES)
46
- @version = normalizer.fetch(:version, :string, :limit => VERSION_MAX_BYTES)
35
+ @commit_hash = attributes[:commit_hash]
36
+ @created_at = attributes[:created_at]
37
+ @version = attributes[:version]
47
38
  end
48
39
 
49
40
  # Builds a hash representation containing simple objects, suitable for serialization (JSON).
50
41
  def to_hash
51
- @to_hash ||= Util::NonNilHashBuilder.build do |h|
52
- h.add(:commit_hash, commit_hash)
53
- h.add(:created_at, created_at)
54
- h.add(:version, version)
55
- end
56
- end
57
-
58
- def as_json(_options = {})
59
- to_hash
42
+ @to_hash ||= {
43
+ release: Util::NonNilHashBuilder.build do |h|
44
+ h.add(:commit_hash, commit_hash)
45
+ h.add(:created_at, created_at)
46
+ h.add(:version, version)
47
+ end
48
+ }
60
49
  end
61
50
  end
62
51
  end
63
- end
52
+ end
@@ -2,49 +2,22 @@ require "timber/context"
2
2
 
3
3
  module Timber
4
4
  module Contexts
5
- # The runtime context adds current runtime data to your logs, such as the file, line number,
6
- # class or module name, etc. This makes it easy to tail and search your logs by their
7
- # origin in your code. For example, if you are debugging a specific class, you can narrow
8
- # by that class and see only it's logs.
5
+ # @private
9
6
  class Runtime < Context
10
- APPLICATION_MAX_BYTES = 256.freeze
11
- CLASS_NAME_MAX_BYTES = 256.freeze
12
- FILE_MAX_BYTES = 1024.freeze
13
- FUNCTION_MAX_BYTES = 256.freeze
14
- MODULE_NAME_MAX_BYTES = 256.freeze
15
- VM_PID_MAX_BYTES = 256.freeze
16
-
17
- @keyspace = :runtime
18
-
19
- attr_reader :application, :class_name, :file, :function, :line, :module_name, :vm_pid
7
+ attr_reader :thread_id
20
8
 
21
9
  def initialize(attributes)
22
- normalizer = Util::AttributeNormalizer.new(attributes)
23
- @application = normalizer.fetch(:application, :string, :limit => APPLICATION_MAX_BYTES)
24
- @class_name = normalizer.fetch(:class_name, :string, :limit => CLASS_NAME_MAX_BYTES)
25
- @file = normalizer.fetch(:file, :string, :limit => FILE_MAX_BYTES)
26
- @function = normalizer.fetch(:function, :string, :limit => FUNCTION_MAX_BYTES)
27
- @line = normalizer.fetch(:line, :integer)
28
- @module_name = normalizer.fetch(:module_name, :string, :limit => MODULE_NAME_MAX_BYTES)
29
- @vm_pid = normalizer.fetch(:vm_pid, :string, :limit => VM_PID_MAX_BYTES)
10
+ @thread_id = attributes[:thread_id]
30
11
  end
31
12
 
32
13
  # Builds a hash representation containing simple objects, suitable for serialization (JSON).
33
14
  def to_hash
34
- @to_hash ||= Util::NonNilHashBuilder.build do |h|
35
- h.add(:application, application)
36
- h.add(:class_name, class_name)
37
- h.add(:file, file)
38
- h.add(:function, function)
39
- h.add(:line, line)
40
- h.add(:module_name, module_name)
41
- h.add(:vm_pid, vm_pid)
42
- end
43
- end
44
-
45
- def as_json(_options = {})
46
- to_hash
15
+ @to_hash ||= {
16
+ runtime: Util::NonNilHashBuilder.build do |h|
17
+ h.add(:thread_id, thread_id)
18
+ end
19
+ }
47
20
  end
48
21
  end
49
22
  end
50
- end
23
+ end