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,198 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "timber/cli/io/ansi"
4
- require "timber/cli/os_helper"
5
-
6
- module Timber
7
- class CLI
8
- class IO
9
- module Messages
10
- extend self
11
-
12
- APP_URL = "https://app.timber.io"
13
- DOCS_URL = "https://timber.io/docs"
14
- OBTAIN_KEY_DOCS_URL = "https://timber.io/docs/app/obtain-api-key/"
15
- REPO_URL = "https://github.com/timberio/timber-ruby"
16
- SUPPORT_EMAIL = "support@timber.io"
17
- TWITTER_HANDLE = "@timberdotio"
18
- WEBSITE_URL = "https://timber.io"
19
- MAX_LENGTH = 80.freeze
20
-
21
- def application_details(app)
22
- message = <<-MESSAGE
23
- Woot! Your API 🔑 is valid: #{app.name} (#{app.environment}) on #{app.platform_type}
24
- MESSAGE
25
- message.rstrip
26
- end
27
-
28
- def edit_app_url(app)
29
- "#{APP_URL}"
30
- end
31
-
32
- def bad_experience_message
33
- message = <<-MESSAGE
34
- Bummer! That is certainly not the experience we were going for.
35
-
36
- Could you tell us why you a bad experience?
37
-
38
- (this will be sent directly to the Timber engineering team)
39
- MESSAGE
40
- message.rstrip
41
- end
42
-
43
- def git_commands
44
- message = <<-MESSAGE
45
- #{ANSI.colorize("git add config/initializers/timber.rb", :blue)}
46
- #{ANSI.colorize("git commit -am 'Install the timber logger'", :blue)}
47
- MESSAGE
48
- message.rstrip
49
- end
50
-
51
- def console_url(app)
52
- message = <<-MESSAGE
53
- Your console URL: https://app.timber.io/organizations/timber/apps/#{app.slug}/console
54
- MESSAGE
55
- end
56
-
57
- def contact
58
- message = <<-MESSAGE
59
- Website: #{WEBSITE_URL}
60
- Documentation: #{DOCS_URL}
61
- Support: #{SUPPORT_EMAIL}
62
- MESSAGE
63
- message.rstrip
64
- end
65
-
66
- def copied_to_clipboard
67
- IO::ANSI.colorize("(✓ copied to clipboard)", :green)
68
- end
69
-
70
- def http_environment_variables(api_key)
71
- command = "export TIMBER_API_KEY=\"#{api_key}\""
72
- copied = OSHelper.copy_to_clipboard(command)
73
-
74
- message = <<-MESSAGE
75
- Great! Add this variable to your environment:
76
-
77
- #{ANSI.colorize(command, :blue)}
78
-
79
- MESSAGE
80
- message = message.rstrip
81
-
82
- if copied
83
- message << "\n #{copied_to_clipboard}"
84
- end
85
-
86
- message
87
- end
88
-
89
- def header
90
- message = <<-MESSAGE
91
- 🌲 Timber.io Ruby Installer - Great Ruby Logging Made *Easy*
92
-
93
- ^ ^ ^ ^ ___I_ ^ ^ ^ ^ ^ ^ ^
94
- /|\\/|\\/|\\ /|\\ /\\-_--\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\
95
- /|\\/|\\/|\\ /|\\ / \\_-__\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\
96
- /|\\/|\\/|\\ /|\\ |[]| [] | /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\
97
- MESSAGE
98
- message.rstrip
99
- end
100
-
101
- def heroku_install(app)
102
- command = "heroku drains:add #{app.heroku_drain_url}"
103
- copied = OSHelper.copy_to_clipboard(command)
104
-
105
- message = <<-MESSAGE
106
- First, let's setup your Heroku drain. Run this command in a separate window:
107
-
108
- #{ANSI.colorize(command, :blue)}
109
- MESSAGE
110
- message = message.rstrip
111
-
112
- if copied
113
- message << "\n #{copied_to_clipboard}"
114
- end
115
-
116
- message
117
- end
118
-
119
- def no_api_key_provided
120
- message = <<-MESSAGE
121
- Hey there! Welcome to Timber. In order to proceed, you'll need an API key.
122
- If you already have one, you can run this installer like:
123
-
124
- #{ANSI.colorize("bundle exec timber install my-api-key", :blue)}
125
-
126
- #{obtain_key_instructions}
127
- MESSAGE
128
- message.rstrip
129
- end
130
-
131
- def obtain_key_instructions
132
- message = <<-MESSAGE
133
- Don't have a key? Head over to:
134
-
135
- #{ANSI.colorize(APP_URL, :blue)}
136
-
137
- For a simple guide, checkout out:
138
-
139
- #{ANSI.colorize(OBTAIN_KEY_DOCS_URL, :blue)}
140
-
141
- If you're stuck, contact us:
142
-
143
- #{ANSI.colorize(SUPPORT_EMAIL, :blue)}
144
- MESSAGE
145
- message.rstrip
146
- end
147
-
148
- def separator
149
- "--------------------------------------------------------------------------------"
150
- end
151
-
152
- def spinner(iteration)
153
- rem = iteration % 3
154
- case rem
155
- when 0
156
- "/"
157
- when 1
158
- "-"
159
- when 2
160
- "\\"
161
- end
162
- end
163
-
164
- def failed
165
- "Failed :("
166
- end
167
-
168
- def success
169
- "✓ Success!"
170
- end
171
-
172
- def task_complete(message)
173
- remainder = MAX_LENGTH - message.length - success.length
174
-
175
- dots = "." * remainder
176
- "\r#{message}#{dots}#{success}"
177
- end
178
-
179
- def task_failed(message)
180
- remainder = MAX_LENGTH - message.length - failed.length
181
-
182
- dots = "." * remainder
183
- "\r#{message}#{dots}#{failed}"
184
- end
185
-
186
- def task_start(message)
187
- remainder = MAX_LENGTH - message.length - success.length
188
-
189
- "\r#{message}" + ("." * remainder)
190
- end
191
-
192
- def we_love_you_too
193
- "Thanks! We 💖 you too!"
194
- end
195
- end
196
- end
197
- end
198
- end
@@ -1,74 +0,0 @@
1
- module Timber
2
- class CLI
3
- module OSHelper
4
- def self.can_copy_to_clipboard?
5
- `which pbcopy` != ""
6
- rescue Exception
7
- false
8
- end
9
-
10
- def self.copy_to_clipboard(input)
11
- ::IO.popen('pbcopy', 'w') { |f| f << input }
12
- true
13
- rescue Exception
14
- false
15
- end
16
-
17
- def self.git_clean_working_tree?
18
- `git diff-index --quiet HEAD -- || echo "untracked";` == ""
19
- end
20
-
21
- def self.git_commit_changes
22
- begin
23
- `git add config/initializers/timber.rb`
24
- rescue Exception
25
- end
26
-
27
- `git commit -am 'Install the timber logger'`
28
- true
29
- rescue Exception
30
- false
31
- end
32
-
33
- def self.git_master?
34
- `git rev-parse --abbrev-ref HEAD` == "master"
35
- end
36
-
37
- def self.has_git?
38
- begin
39
- `which git` != ""
40
- rescue Exception
41
- false
42
- end
43
- end
44
-
45
- def self.can_open?
46
- begin
47
- `which #{open_command}` != ""
48
- rescue Exception
49
- false
50
- end
51
- end
52
-
53
- # Attemps to open a URL in the user's default browser across
54
- # the popular operating systems.
55
- def self.open(link)
56
- `#{open_command} #{link}`
57
- true
58
- rescue Exception
59
- false
60
- end
61
-
62
- private
63
- def self.open_command
64
- if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
65
- "start"
66
- elsif RbConfig::CONFIG['host_os'] =~ /darwin/
67
- "open"
68
- elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
69
- "xdg-open"
70
- end
71
- end
72
- end
73
- end
74
- end
@@ -1,74 +0,0 @@
1
- module Timber
2
- class Config
3
- module Integrations
4
- # Convenience module for accessing the various `Timber::Integrations::Rack::*` classes
5
- # through the {Timber::Config} object. Timber couples configuration with the class
6
- # responsibls for implementing it. This provides for a tighter design, but also
7
- # requires the user to understand and access the various classes. This module aims
8
- # to provide a simple ruby-like configuration interface for internal Timber classes.
9
- #
10
- # For example:
11
- #
12
- # config = Timber::Config.instance
13
- # config.integrations.rack.http_events.enabled = false
14
- module Rack
15
- extend self
16
-
17
- # Convenience method for accessing the {Timber::Integrations::Rack::ErrorEvent}
18
- # middleware class specific configuration. See {Timber::Integrations::Rack::ExceptionEvent}
19
- # for a list of methods available.
20
- #
21
- # @example
22
- # config = Timber::Config.instance
23
- # config.integrations.rack.error_event.enabled = false
24
- def error_event
25
- Timber::Integrations::Rack::ErrorEvent
26
- end
27
-
28
- # Convenience method for accessing the {Timber::Integrations::Rack::HTTPContext}
29
- # middleware class specific configuration. See {Timber::Integrations::Rack::HTTPContext}
30
- # for a list of methods available.
31
- #
32
- # @example
33
- # config = Timber::Config.instance
34
- # config.integrations.rack.http_context.enabled = false
35
- def http_context
36
- Timber::Integrations::Rack::HTTPContext
37
- end
38
-
39
- # Convenience method for accessing the {Timber::Integrations::Rack::HTTPEvents}
40
- # middleware class specific configuration. See {Timber::Integrations::Rack::HTTPEvents}
41
- # for a list of methods available.
42
- #
43
- # @example
44
- # config = Timber::Config.instance
45
- # config.integrations.rack.http_events.enabled = false
46
- def http_events
47
- Timber::Integrations::Rack::HTTPEvents
48
- end
49
-
50
- # Convenience method for accessing the {Timber::Integrations::Rack::SessionContext}
51
- # middleware class specific configuration. See {Timber::Integrations::Rack::SessionContext}
52
- # for a list of methods available.
53
- #
54
- # @example
55
- # config = Timber::Config.instance
56
- # config.integrations.rack.session_context.enabled = false
57
- def session_context
58
- Timber::Integrations::Rack::SessionContext
59
- end
60
-
61
- # Convenience method for accessing the {Timber::Integrations::Rack::UserContext}
62
- # middleware class specific configuration. See {Timber::Integrations::Rack::UserContext}
63
- # for a list of methods available.
64
- #
65
- # @example
66
- # config = Timber::Config.instance
67
- # config.integrations.rack.user_context.enabled = false
68
- def user_context
69
- Timber::Integrations::Rack::UserContext
70
- end
71
- end
72
- end
73
- end
74
- end
@@ -1,44 +0,0 @@
1
- require "timber/context"
2
- require "timber/util"
3
-
4
- module Timber
5
- module Contexts
6
- # Custom contexts allow you to add application specific context not covered elsewhere.
7
- # Any data added this way will be included in your logs. A good example is worker job
8
- # IDs. When processing a job you might add the job ID to the context, allowing you to
9
- # view *all* logs generated while processing that job, not just the logs that contain
10
- # the ID.
11
- #
12
- # Note in the example below all custom contexts must contain a root key. This is to
13
- # ensure attribute names and types never clash across your contexts. It gives you
14
- # much cleaner pallete to organize your data on.
15
- #
16
- # @example Adding a custom context
17
- # logger.with_context(build: {version: "1.0.0"}) do
18
- # # anything logged here will have the custom context above
19
- # # when this block exits the context will no longer be included
20
- # end
21
- class Custom < Context
22
- @keyspace = :custom
23
-
24
- attr_reader :type, :data
25
-
26
- def initialize(attributes)
27
- normalizer = Util::AttributeNormalizer.new(attributes)
28
- @type = normalizer.fetch!(:type, :symbol)
29
- @data = normalizer.fetch!(:data, :hash)
30
- end
31
-
32
- # Builds a hash representation containing simple objects, suitable for serialization (JSON).
33
- def to_hash
34
- @to_hash ||= Util::NonNilHashBuilder.build do |h|
35
- h.add(type, data)
36
- end
37
- end
38
-
39
- def as_json(options = {})
40
- to_hash
41
- end
42
- end
43
- end
44
- end
@@ -1,48 +0,0 @@
1
- require "timber/context"
2
- require "timber/util"
3
-
4
- module Timber
5
- module Contexts
6
- # The organization context tracks the organization of the currently
7
- # authenticated user.
8
- #
9
- # You will want to add this context at the time you determine
10
- # the organization a user belongs to, typically in the authentication
11
- # flow.
12
- #
13
- # Example:
14
- #
15
- # organization_context = Timber::Contexts::Organization.new(id: "abc1234", name: "Timber Inc")
16
- # logger.with_context(organization_context) do
17
- # # Logging will automatically include this context
18
- # logger.info("This is a log message")
19
- # end
20
- #
21
- class Organization < Context
22
- ID_MAX_BYTES = 256.freeze
23
- NAME_MAX_BYTES = 256.freeze
24
-
25
- @keyspace = :organization
26
-
27
- attr_reader :id, :name
28
-
29
- def initialize(attributes)
30
- normalizer = Util::AttributeNormalizer.new(attributes)
31
- @id = normalizer.fetch(:id, :string, :limit => ID_MAX_BYTES)
32
- @name = normalizer.fetch(:name, :string, :limit => NAME_MAX_BYTES)
33
- end
34
-
35
- # Builds a hash representation containing simple objects, suitable for serialization (JSON).
36
- def to_hash
37
- @to_hash ||= Util::NonNilHashBuilder.build do |h|
38
- h.add(:id, id)
39
- h.add(:name, name)
40
- end
41
- end
42
-
43
- def as_json(_options = {})
44
- to_hash
45
- end
46
- end
47
- end
48
- end
@@ -1,53 +0,0 @@
1
- require "timber/event"
2
- require "timber/util"
3
-
4
- module Timber
5
- module Events
6
- # Allows for custom events that aren't covered elsewhere.
7
- #
8
- # Custom events can be used to encode information about events that are central
9
- # to your line of business like receiving credit card payments, saving a draft of a post,
10
- # or changing a user's password.
11
- #
12
- # For examples of logging custom events see {Logger}.
13
- class Custom < Timber::Event
14
- attr_reader :type, :message, :data
15
-
16
- # Instantiates a new custom event that can be logged. See {Logger} for examples
17
- # on logging custom events.
18
- #
19
- # @param [Hash] attributes the options to create a custom event with.
20
- # @option attributes [Symbol] :type *required* The custom event type. This should be in
21
- # snake case. Example: `:my_custom_event`.
22
- # @option attributes [String] :message *required* The message to be logged.
23
- # @option attributes [Hash] :data A hash of JSON encodable data to be stored with the
24
- # log line.
25
- def initialize(attributes)
26
- normalizer = Util::AttributeNormalizer.new(attributes)
27
- @type = normalizer.fetch!(:type, :symbol)
28
- @message = normalizer.fetch!(:message, :string)
29
-
30
- data = normalizer.fetch(:data, :hash, default: {})
31
-
32
- if !data.nil? && data[:time_ms].is_a?(Time)
33
- data[:time_ms] = Timer.duration_ms(data[:time_ms])
34
- @message << " in #{data[:time_ms]}ms"
35
- end
36
-
37
- @data = data
38
- end
39
-
40
- def to_hash
41
- @to_hash ||= Util::NonNilHashBuilder.build do |h|
42
- h.add(type, data)
43
- end
44
- end
45
- alias to_h to_hash
46
-
47
- # Builds a hash representation containing simple objects, suitable for serialization (JSON).
48
- def as_json(_options = {})
49
- {:custom => to_hash}
50
- end
51
- end
52
- end
53
- end