timberio 1.0.0.beta1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -2
  3. data/.rspec +2 -0
  4. data/.yardopts +6 -0
  5. data/Appraisals +4 -0
  6. data/Gemfile +9 -1
  7. data/LICENSE.md +15 -0
  8. data/README.md +170 -8
  9. data/circle.yml +11 -8
  10. data/lib/timber/config.rb +11 -18
  11. data/lib/timber/context.rb +9 -68
  12. data/lib/timber/contexts/custom.rb +27 -0
  13. data/lib/timber/contexts/http.rb +28 -0
  14. data/lib/timber/contexts/organization.rb +24 -22
  15. data/lib/timber/contexts/user.rb +25 -28
  16. data/lib/timber/contexts.rb +7 -20
  17. data/lib/timber/current_context.rb +26 -41
  18. data/lib/timber/event.rb +13 -0
  19. data/lib/timber/events/controller_call.rb +40 -0
  20. data/lib/timber/events/custom.rb +42 -0
  21. data/lib/timber/events/exception.rb +35 -0
  22. data/lib/timber/events/http_request.rb +50 -0
  23. data/lib/timber/events/http_response.rb +36 -0
  24. data/lib/timber/events/sql_query.rb +26 -0
  25. data/lib/timber/events/template_render.rb +26 -0
  26. data/lib/timber/events.rb +37 -0
  27. data/lib/timber/frameworks/rails.rb +3 -14
  28. data/lib/timber/frameworks.rb +8 -10
  29. data/lib/timber/log_devices/http.rb +72 -13
  30. data/lib/timber/log_devices.rb +8 -4
  31. data/lib/timber/log_entry.rb +59 -0
  32. data/lib/timber/logger.rb +136 -13
  33. data/lib/timber/probe.rb +6 -4
  34. data/lib/timber/probes/action_controller_log_subscriber/log_subscriber.rb +64 -0
  35. data/lib/timber/probes/action_controller_log_subscriber.rb +20 -0
  36. data/lib/timber/probes/action_dispatch_debug_exceptions.rb +59 -35
  37. data/lib/timber/probes/action_view_log_subscriber/log_subscriber.rb +62 -0
  38. data/lib/timber/probes/action_view_log_subscriber.rb +20 -0
  39. data/lib/timber/probes/active_record_log_subscriber/log_subscriber.rb +72 -0
  40. data/lib/timber/probes/active_record_log_subscriber.rb +20 -0
  41. data/lib/timber/probes/rack_http_context.rb +51 -0
  42. data/lib/timber/probes/rails_rack_logger.rb +76 -0
  43. data/lib/timber/probes.rb +13 -16
  44. data/lib/timber/util/active_support_log_subscriber.rb +33 -0
  45. data/lib/timber/util/hash.rb +14 -0
  46. data/lib/timber/util.rb +8 -0
  47. data/lib/timber/version.rb +2 -2
  48. data/lib/timber.rb +6 -11
  49. data/spec/spec_helper.rb +7 -4
  50. data/spec/support/rails.rb +9 -5
  51. data/spec/support/timber.rb +1 -20
  52. data/spec/timber/events_spec.rb +55 -0
  53. data/spec/timber/log_devices/http_spec.rb +62 -0
  54. data/spec/timber/logger_spec.rb +68 -0
  55. data/spec/timber/probes/action_controller_log_subscriber_spec.rb +70 -0
  56. data/spec/timber/probes/action_dispatch_debug_exceptions_spec.rb +24 -18
  57. data/spec/timber/probes/action_view_log_subscriber_spec.rb +61 -0
  58. data/spec/timber/probes/active_record_log_subscriber_spec.rb +49 -0
  59. data/spec/timber/probes/rack_http_context_spec.rb +54 -0
  60. data/spec/timber/probes/rails_rack_logger_spec.rb +46 -0
  61. data/timberio.gemspec +2 -0
  62. metadata +62 -123
  63. data/.codeclimate.yml +0 -34
  64. data/LICENSE +0 -38
  65. data/Rakefile +0 -4
  66. data/TODO +0 -4
  67. data/benchmark/README.md +0 -26
  68. data/benchmark/rails_request.rb +0 -68
  69. data/benchmark/support/rails.rb +0 -69
  70. data/docs/installation/rails_on_heroku.md +0 -31
  71. data/docs/installation/rails_over_http.md +0 -22
  72. data/gemfiles/rails_3.0.X.gemfile +0 -25
  73. data/gemfiles/rails_3.1.X.gemfile +0 -25
  74. data/gemfiles/rails_3.2.X.gemfile +0 -25
  75. data/gemfiles/rails_4.0.X.gemfile +0 -26
  76. data/gemfiles/rails_4.1.X.gemfile +0 -26
  77. data/gemfiles/rails_4.2.X.gemfile +0 -26
  78. data/gemfiles/rails_5.0.X.gemfile +0 -26
  79. data/gemfiles/rails_edge.gemfile +0 -27
  80. data/lib/timber/api_settings.rb +0 -17
  81. data/lib/timber/bootstrap.rb +0 -45
  82. data/lib/timber/context_snapshot.rb +0 -64
  83. data/lib/timber/contexts/dynamic_values.rb +0 -59
  84. data/lib/timber/contexts/exception.rb +0 -40
  85. data/lib/timber/contexts/http_request.rb +0 -22
  86. data/lib/timber/contexts/http_requests/action_controller_specific.rb +0 -48
  87. data/lib/timber/contexts/http_requests/rack/params.rb +0 -26
  88. data/lib/timber/contexts/http_requests/rack.rb +0 -105
  89. data/lib/timber/contexts/http_response.rb +0 -19
  90. data/lib/timber/contexts/http_responses/action_controller.rb +0 -76
  91. data/lib/timber/contexts/logger.rb +0 -33
  92. data/lib/timber/contexts/organizations/action_controller.rb +0 -34
  93. data/lib/timber/contexts/server.rb +0 -21
  94. data/lib/timber/contexts/servers/heroku_specific.rb +0 -48
  95. data/lib/timber/contexts/sql_queries/active_record.rb +0 -30
  96. data/lib/timber/contexts/sql_queries/active_record_specific/binds.rb +0 -37
  97. data/lib/timber/contexts/sql_queries/active_record_specific.rb +0 -59
  98. data/lib/timber/contexts/sql_query.rb +0 -18
  99. data/lib/timber/contexts/template_render.rb +0 -17
  100. data/lib/timber/contexts/template_renders/action_view.rb +0 -29
  101. data/lib/timber/contexts/template_renders/action_view_specific.rb +0 -51
  102. data/lib/timber/contexts/users/action_controller.rb +0 -34
  103. data/lib/timber/current_line_indexes.rb +0 -35
  104. data/lib/timber/internal_logger.rb +0 -35
  105. data/lib/timber/log_device.rb +0 -40
  106. data/lib/timber/log_devices/heroku_logplex/hybrid_formatter.rb +0 -14
  107. data/lib/timber/log_devices/heroku_logplex.rb +0 -14
  108. data/lib/timber/log_devices/http/log_pile.rb +0 -86
  109. data/lib/timber/log_devices/http/log_truck/delivery.rb +0 -116
  110. data/lib/timber/log_devices/http/log_truck.rb +0 -87
  111. data/lib/timber/log_devices/io/formatter.rb +0 -46
  112. data/lib/timber/log_devices/io/hybrid_formatter.rb +0 -41
  113. data/lib/timber/log_devices/io/hybrid_hidden_formatter.rb +0 -36
  114. data/lib/timber/log_devices/io/json_formatter.rb +0 -11
  115. data/lib/timber/log_devices/io/logfmt_formatter.rb +0 -11
  116. data/lib/timber/log_devices/io.rb +0 -41
  117. data/lib/timber/log_line.rb +0 -33
  118. data/lib/timber/macros/compactor.rb +0 -16
  119. data/lib/timber/macros/date_formatter.rb +0 -9
  120. data/lib/timber/macros/deep_merger.rb +0 -11
  121. data/lib/timber/macros/logfmt_encoder.rb +0 -77
  122. data/lib/timber/macros.rb +0 -4
  123. data/lib/timber/patterns/delegated_singleton.rb +0 -21
  124. data/lib/timber/patterns/to_json.rb +0 -22
  125. data/lib/timber/patterns/to_logfmt.rb +0 -9
  126. data/lib/timber/patterns.rb +0 -3
  127. data/lib/timber/probes/action_controller_base.rb +0 -31
  128. data/lib/timber/probes/active_support_log_subscriber/action_controller.rb +0 -15
  129. data/lib/timber/probes/active_support_log_subscriber/action_view.rb +0 -26
  130. data/lib/timber/probes/active_support_log_subscriber/active_record.rb +0 -13
  131. data/lib/timber/probes/active_support_log_subscriber.rb +0 -62
  132. data/lib/timber/probes/heroku.rb +0 -30
  133. data/lib/timber/probes/logger.rb +0 -31
  134. data/lib/timber/probes/rack.rb +0 -36
  135. data/lib/timber/probes/server.rb +0 -18
  136. data/spec/timber/bootstrap_spec.rb +0 -31
  137. data/spec/timber/context_snapshot_spec.rb +0 -10
  138. data/spec/timber/context_spec.rb +0 -4
  139. data/spec/timber/contexts/exception_spec.rb +0 -34
  140. data/spec/timber/contexts/organizations/action_controller_spec.rb +0 -49
  141. data/spec/timber/contexts/users/action_controller_spec.rb +0 -65
  142. data/spec/timber/current_line_indexes_spec.rb +0 -40
  143. data/spec/timber/frameworks/rails_spec.rb +0 -9
  144. data/spec/timber/log_devices/heroku_logplex_spec.rb +0 -45
  145. data/spec/timber/log_devices/http/log_truck/delivery_spec.rb +0 -66
  146. data/spec/timber/log_devices/http/log_truck_spec.rb +0 -65
  147. data/spec/timber/log_devices/io/hybrid_hidden_formatter_spec.rb +0 -28
  148. data/spec/timber/log_line_spec.rb +0 -49
  149. data/spec/timber/macros/compactor_spec.rb +0 -19
  150. data/spec/timber/macros/logfmt_encoder_spec.rb +0 -89
  151. data/spec/timber/patterns/to_json_spec.rb +0 -40
  152. data/spec/timber/probes/action_controller_base_spec.rb +0 -43
  153. data/spec/timber/probes/action_controller_log_subscriber/action_controller_spec.rb +0 -35
  154. data/spec/timber/probes/action_controller_log_subscriber/action_view_spec.rb +0 -44
  155. data/spec/timber/probes/action_controller_log_subscriber/active_record_spec.rb +0 -26
  156. data/spec/timber/probes/logger_spec.rb +0 -20
  157. data/spec/timber/probes/rack_spec.rb +0 -26
@@ -1,105 +0,0 @@
1
- require "timber/contexts/http_requests/rack/params"
2
-
3
- module Timber
4
- module Contexts
5
- module HTTPRequests
6
- class Rack < HTTPRequest
7
- class Headers
8
- include Patterns::ToJSON
9
-
10
- attr_reader :env, :request
11
-
12
- def initialize(env, request)
13
- @env = env
14
- @request = request
15
- end
16
-
17
- def content_type
18
- @content_type ||= request.content_type
19
- end
20
-
21
- def referrer
22
- @referrer ||= request.referrer
23
- end
24
-
25
- def remote_addr
26
- @remote_addr ||= request.ip
27
- end
28
-
29
- def request_id
30
- return @request_id if defined?(@request_id)
31
- found = env.find do |k,v|
32
- # Needs to support:
33
- # action_dispatch.request_id
34
- # HTTP_X_REQUEST_ID
35
- # Request-ID
36
- # Request-Id
37
- # X-Request-ID
38
- # X-Request-Id
39
- # etc
40
- (k.downcase.include?("request_id") || k.downcase.include?("request-id")) && !v.nil?
41
- end
42
- @request_id = found && found.last
43
- end
44
-
45
- def user_agent
46
- @user_agent ||= request.user_agent
47
- end
48
-
49
- private
50
- def json_payload
51
- @json_payload ||= {
52
- :content_type => content_type,
53
- :referrer => referrer,
54
- :remote_addr => remote_addr,
55
- :request_id => request_id,
56
- :user_agent => user_agent
57
- }
58
- end
59
- end
60
-
61
- attr_reader :env
62
-
63
- def initialize(env)
64
- # Initialize should be as fast as possible since it is executed inline.
65
- # Hence the lazy methods below.
66
- @env = env
67
- super()
68
- end
69
-
70
- def headers
71
- @headers ||= Headers.new(env, request)
72
- end
73
-
74
- def host
75
- @host ||= request.host
76
- end
77
-
78
- def method
79
- @method ||= request.request_method.upcase
80
- end
81
-
82
- def path
83
- @path ||= request.path
84
- end
85
-
86
- def port
87
- @port ||= request.port
88
- end
89
-
90
- def query_params
91
- @query_params ||= request.params && Params.new(request.params)
92
- end
93
-
94
- def scheme
95
- @scheme ||= request.scheme
96
- end
97
-
98
- private
99
- def request
100
- @request ||= ::Rack::Request.new(env)
101
- end
102
- end
103
- end
104
- end
105
- end
@@ -1,19 +0,0 @@
1
- module Timber
2
- module Contexts
3
- # Generica HTTP response shared across all platforms.
4
- class HTTPResponse < Context
5
- ROOT_KEY = :http_response.freeze
6
- VERSION = 1.freeze
7
-
8
- private
9
- def json_payload
10
- @json_payload ||= Macros::DeepMerger.merge({
11
- # order is relevant for logfmt styling
12
- :status => status,
13
- :headers => headers.as_json,
14
- :time_ms => time_ms
15
- }, super).freeze
16
- end
17
- end
18
- end
19
- end
@@ -1,76 +0,0 @@
1
- module Timber
2
- module Contexts
3
- module HTTPResponses
4
- class ActionController < HTTPResponse
5
- class Headers
6
- include Patterns::ToJSON
7
-
8
- attr_reader :response
9
-
10
- def initialize(response)
11
- @response = response
12
- end
13
-
14
- def content_length
15
- @content_length ||= response.content_length
16
- end
17
-
18
- def cache_control
19
- @cache_control ||= response.headers['Cache-Control']
20
- end
21
-
22
- def content_disposition
23
- @content_disposition ||= response.headers['Cache-Disposition']
24
- end
25
-
26
- def content_type
27
- @content_type ||= response.headers['Content-Type']
28
- end
29
-
30
- def location
31
- @location ||= response.headers['Location']
32
- end
33
-
34
- private
35
- def json_payload
36
- @json_payload ||= {
37
- :content_length => content_length,
38
- :cache_control => cache_control,
39
- :content_disposition => content_disposition,
40
- :content_type => content_type,
41
- :location => location
42
- }
43
- end
44
- end
45
-
46
- attr_reader :controller
47
- attr_accessor :event
48
-
49
- def initialize(controller)
50
- @controller = controller
51
- end
52
-
53
- def headers
54
- @headers ||= Headers.new(response)
55
- end
56
-
57
- def status
58
- @status ||= response.status
59
- end
60
-
61
- def time_ms
62
- @time_ms ||= event.duration
63
- end
64
-
65
- def valid?
66
- !response.nil? && !event.nil?
67
- end
68
-
69
- private
70
- def response
71
- controller.response
72
- end
73
- end
74
- end
75
- end
76
- end
@@ -1,33 +0,0 @@
1
- module Timber
2
- module Contexts
3
- class Logger < Context
4
- ROOT_KEY = :logger.freeze
5
- VERSION = 1.freeze
6
- LEVEL_MAP = {
7
- 0 => "debug",
8
- 1 => "info",
9
- 2 => "warn",
10
- 3 => "error",
11
- 4 => "fatal"
12
- }
13
- UNKNOWN_LEVEL = "unknown"
14
-
15
- attr_reader :level, :progname
16
-
17
- def initialize(level, progname)
18
- @level = LEVEL_MAP[level] || UNKNOWN_LEVEL
19
- @progname = progname
20
- super()
21
- end
22
-
23
- private
24
- def json_payload
25
- @json_payload ||= Macros::DeepMerger.merge({
26
- # order is relevant for logfmt styling
27
- :level => level,
28
- :progname => progname
29
- }, super).freeze
30
- end
31
- end
32
- end
33
- end
@@ -1,34 +0,0 @@
1
- module Timber
2
- module Contexts
3
- module Organizations
4
- class ActionController < Organization
5
- DEFAULT_METHOD_NAME = :current_organization.freeze
6
-
7
- class << self
8
- attr_writer :method_name
9
-
10
- def method_name
11
- @method_name ||= DEFAULT_METHOD_NAME
12
- end
13
- end
14
-
15
- attr_reader :controller
16
-
17
- def initialize(controller)
18
- @controller = controller
19
- super()
20
- end
21
-
22
- private
23
- def method_name
24
- self.class.method_name
25
- end
26
-
27
- def organization
28
- return @organization if defined?(@organization)
29
- @organization = controller.respond_to?(method_name, true) ? controller.send(method_name) : nil
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,21 +0,0 @@
1
- require "socket"
2
-
3
- module Timber
4
- module Contexts
5
- class Server < Context
6
- ROOT_KEY = :server.freeze
7
- VERSION = 1.freeze
8
-
9
- def hostname
10
- @hostname ||= ::Socket.gethostname
11
- end
12
-
13
- private
14
- def json_payload
15
- @json_payload ||= Macros::DeepMerger.merge({
16
- :hostname => hostname
17
- }, super).freeze
18
- end
19
- end
20
- end
21
- end
@@ -1,48 +0,0 @@
1
- module Timber
2
- module Contexts
3
- module Servers
4
- # Because this is a sub context we do not extend Server.
5
- class HerokuSpecific < Context
6
- ROOT_KEY = :heroku.freeze
7
- VERSION = 1.freeze
8
- DELIMITER = ".".freeze
9
-
10
- class << self
11
- def json_shell(&_block)
12
- Server.json_shell { super }
13
- end
14
- end
15
-
16
- attr_reader :dyno
17
-
18
- def initialize(dyno)
19
- # Initialize should be as fast as possible since it is executed inline.
20
- # Hence the lazy methods below.
21
- @dyno = dyno
22
- super()
23
- end
24
-
25
- def process_type
26
- @process_type ||= parts.first
27
- end
28
-
29
- def dyno_id
30
- @dyno_id ||= parts.last
31
- end
32
-
33
- private
34
- def parts
35
- @parts ||= dyno.split(DELIMITER)
36
- end
37
-
38
- def json_payload
39
- @json_payload ||= Macros::DeepMerger.merge({
40
- # order is relevant for logfmt styling
41
- :process_type => process_type,
42
- :dyno_id => dyno_id
43
- }, super).freeze.freeze
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,30 +0,0 @@
1
- module Timber
2
- module Contexts
3
- module SQLQueries
4
- class ActiveRecord < SQLQuery
5
- attr_reader :log_subscriber, :event
6
-
7
- def initialize(log_subscriber, event)
8
- # Initialize should be as fast as possible since it is executed inline.
9
- # Hence the lazy methods below.
10
- @log_subscriber = log_subscriber
11
- @event = event
12
- super()
13
- end
14
-
15
- def sql
16
- @sql ||= payload[:sql].try(:strip)
17
- end
18
-
19
- def time_ms
20
- @time_ms ||= event.duration
21
- end
22
-
23
- private
24
- def payload
25
- event.payload
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,37 +0,0 @@
1
- module Timber
2
- module Contexts
3
- module SQLQueries
4
- class ActiveRecordSpecific < Context
5
- class Binds < DynamicValues
6
- attr_reader :log_subscriber, :binds
7
-
8
- def initialize(log_subscriber, binds)
9
- # Initialize should be as fast as possible since it is executed inline.
10
- # Hence the lazy methods below.
11
- @log_subscriber = log_subscriber
12
- @binds = binds
13
- super()
14
- end
15
-
16
- private
17
- # Override values_array so that this is done in the background thread
18
- def values_array
19
- @values_array ||= binds.collect do |bind|
20
- name, value = render_bind(bind)
21
- {:name => name, :value => value}
22
- end
23
- end
24
-
25
- def render_bind(bind)
26
- if bind.is_a?(Array)
27
- # AR 4.2.X
28
- log_subscriber.render_bind(*bind)
29
- else
30
- log_subscriber.render_bind(bind)
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,59 +0,0 @@
1
- require "timber/contexts/sql_queries/active_record_specific/binds"
2
-
3
- module Timber
4
- module Contexts
5
- module SQLQueries
6
- # Because this is a sub context we extend Context
7
- class ActiveRecordSpecific < Context
8
- ROOT_KEY = :active_record.freeze
9
- VERSION = 1.freeze
10
-
11
- class << self
12
- def json_shell(&_block)
13
- SQLQuery.json_shell { super }
14
- end
15
- end
16
-
17
- attr_reader :log_subscriber, :event
18
-
19
- def initialize(log_subscriber, event)
20
- # Initialize should be as fast as possible since it is executed inline.
21
- # Hence the lazy methods below.
22
- @log_subscriber = log_subscriber
23
- @event = event
24
- super()
25
- end
26
-
27
- def binds
28
- @binds ||= payload[:binds] && Binds.new(log_subscriber, payload[:binds])
29
- end
30
-
31
- def connection_id
32
- @connection_id ||= payload[:connection_id].try(:to_s)
33
- end
34
-
35
- def statement_name
36
- @statement_name ||= payload[:statement_name]
37
- end
38
-
39
- def transaction_id
40
- @transaction_id ||= event.transaction_id.try(:to_s)
41
- end
42
-
43
- private
44
- def json_payload
45
- @json_payload ||= Macros::DeepMerger.merge({
46
- :binds => binds.as_json,
47
- :connection_id => connection_id,
48
- :statement_name => statement_name,
49
- :transaction_id => transaction_id
50
- }, super).freeze
51
- end
52
-
53
- def payload
54
- event.payload
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,18 +0,0 @@
1
- module Timber
2
- module Contexts
3
- # Base class for SQLQuery sub types.
4
- class SQLQuery < Context
5
- ROOT_KEY = :sql_query.freeze
6
- VERSION = 1.freeze
7
-
8
- private
9
- def json_payload
10
- @json_payload ||= Macros::DeepMerger.merge({
11
- # order is relevant for logfmt styling
12
- :sql => sql,
13
- :time_ms => time_ms
14
- }, super).freeze
15
- end
16
- end
17
- end
18
- end
@@ -1,17 +0,0 @@
1
- module Timber
2
- module Contexts
3
- class TemplateRender < Context
4
- ROOT_KEY = :template_render.freeze
5
- VERSION = 1.freeze
6
-
7
- private
8
- def json_payload
9
- @json_payload ||= Macros::DeepMerger.merge({
10
- # order is relevant for logfmt styling
11
- :name => name,
12
- :time_ms => time_ms
13
- }, super).freeze
14
- end
15
- end
16
- end
17
- end
@@ -1,29 +0,0 @@
1
- module Timber
2
- module Contexts
3
- module TemplateRenders
4
- class ActionView < TemplateRender
5
- attr_reader :event
6
-
7
- def initialize(event)
8
- # Initialize should be as fast as possible since it is executed inline.
9
- # Hence the lazy methods below.
10
- @event = event
11
- super()
12
- end
13
-
14
- def name
15
- @name ||= payload[:identifier]
16
- end
17
-
18
- def time_ms
19
- @time_ms ||= event.duration
20
- end
21
-
22
- private
23
- def payload
24
- event.payload
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,51 +0,0 @@
1
- module Timber
2
- module Contexts
3
- module TemplateRenders
4
- # Because this is a sub type we extend Context
5
- class ActionViewSpecific < Context
6
- ROOT_KEY = :action_view.freeze
7
- VERSION = 1.freeze
8
-
9
- class << self
10
- def json_shell(&_block)
11
- TemplateRender.json_shell { super }
12
- end
13
- end
14
-
15
- attr_reader :event
16
-
17
- def initialize(event)
18
- # Initialize should be as fast as possible since it is executed inline.
19
- # Hence the lazy methods below.
20
- @event = event
21
- super()
22
- end
23
-
24
- def cache_hits
25
- @cache_hits ||= payload[:cache_hits]
26
- end
27
-
28
- def count
29
- @count ||= payload[:count]
30
- end
31
-
32
- def layout
33
- @layout ||= payload[:layout]
34
- end
35
-
36
- private
37
- def json_payload
38
- @json_payload ||= Macros::DeepMerger.merge({
39
- :cache_hits => cache_hits,
40
- :count => count,
41
- :layout => layout
42
- }, super).freeze
43
- end
44
-
45
- def payload
46
- event.payload
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,34 +0,0 @@
1
- module Timber
2
- module Contexts
3
- module Users
4
- class ActionController < User
5
- DEFAULT_METHOD_NAME = :current_user.freeze
6
-
7
- class << self
8
- attr_writer :method_name
9
-
10
- def method_name
11
- @method_name ||= DEFAULT_METHOD_NAME
12
- end
13
- end
14
-
15
- attr_reader :controller
16
-
17
- def initialize(controller)
18
- @controller = controller
19
- super()
20
- end
21
-
22
- private
23
- def method_name
24
- self.class.method_name
25
- end
26
-
27
- def user
28
- return @user if defined?(@user)
29
- @user = controller.respond_to?(method_name, true) ? controller.send(method_name) : nil
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,35 +0,0 @@
1
- module Timber
2
- # Holds the log line counts on a per context basis in memory.
3
- class CurrentLineIndexes
4
- THREAD_NAMESPACE = :_timber_current_line_counts.freeze
5
-
6
- include Patterns::DelegatedSingleton
7
-
8
- def context_removed(context)
9
- indexes.delete(context)
10
- end
11
-
12
- def indexes
13
- Thread.current[THREAD_NAMESPACE] ||= {}
14
- end
15
-
16
- def log_line_added(_log_line)
17
- CurrentContext.valid_stack.each do |context|
18
- if indexes.key?(context)
19
- indexes[context] += 1
20
- else
21
- indexes[context] = 0
22
- end
23
- end
24
- end
25
-
26
- def reset!
27
- indexes.clear
28
- end
29
-
30
- def snapshot
31
- # No need to cache, this is blown out for each log line
32
- LineIndexesSnapshot.new(self)
33
- end
34
- end
35
- end
@@ -1,35 +0,0 @@
1
- require "logger"
2
-
3
- module Timber
4
- # Allows us to prefix all logs with [Timber] without having to
5
- # rely on external dependencies. This is slightly different
6
- # in that we don't want to create an entirely new logger or modify
7
- # the logger they pass us. We only want to prefix logs in the context
8
- # of this library.
9
- class InternalLogger < ::Logger
10
- class Formatter < ::Logger::Formatter
11
- TAG = "[Timber]"
12
-
13
- # This method is invoked when a log event occurs
14
- def call(_severity, _timestamp, _progname, msg)
15
- "#{TAG} #{String === msg ? msg : msg.inspect}\n"
16
- end
17
- end
18
-
19
- def initialize(*args)
20
- super
21
- @formatter = Formatter.new
22
- end
23
-
24
- # This is a convenience method for logging exceptions. Also
25
- # allows us to build a notify hook for any exception that happen in
26
- # the Timber library. This is extremely important for quality control.
27
- def exception(exception)
28
- if !exception.is_a?(Exception)
29
- raise ArgumentError.new("#exception must take an Exception type")
30
- end
31
- # TODO: notify us that this exception happened
32
- error("#{exception.inspect}: #{exception.backtrace.inspect}")
33
- end
34
- end
35
- end