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,34 +0,0 @@
1
- module Timber
2
- class CLI
3
- class API
4
- class Application
5
- DEVELOPMENT_ENVIRONMENT = "development".freeze
6
- TEST_ENVIRONMENT = "test".freeze
7
- HEROKU = "heroku".freeze
8
-
9
- attr_accessor :api_key, :environment, :heroku_drain_url,
10
- :name, :platform_type
11
-
12
- def initialize(attributes)
13
- @api_key = attributes.fetch("api_key")
14
- @environment = attributes.fetch("environment")
15
- @heroku_drain_url = attributes.fetch("heroku_drain_url")
16
- @name = attributes.fetch("name")
17
- @platform_type = attributes.fetch("platform_type")
18
- end
19
-
20
- def development?
21
- environment == DEVELOPMENT_ENVIRONMENT
22
- end
23
-
24
- def test?
25
- environment == TEST_ENVIRONMENT
26
- end
27
-
28
- def heroku?
29
- platform_type == HEROKU
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,71 +0,0 @@
1
- require "timber/cli/file_helper"
2
-
3
- module Timber
4
- class CLI
5
- class ConfigFile
6
- attr_reader :path, :file_helper
7
-
8
- def initialize(path, file_helper)
9
- @path = path
10
- @file_helper = file_helper
11
- end
12
-
13
- def create!
14
- file_helper.write(path, content)
15
- end
16
-
17
- def exists?
18
- File.exists?(path)
19
- end
20
-
21
- def logrageify!
22
- append!("config.logrageify!")
23
- end
24
-
25
- def silence_template_renders!
26
- append!("config.integrations.action_view.silence = Rails.env.production?")
27
- end
28
-
29
- private
30
- def append!(code)
31
- if !content.include?(code)
32
- content.gsub!(insert_hook, "#{code}\n\n#{insert_hook}")
33
- end
34
-
35
- true
36
- end
37
-
38
- def insert_hook
39
- @insert_hook ||= "# Add additional configuration here."
40
- end
41
-
42
- # We provide this as an instance method so that the string is only defined when needed.
43
- # This avoids allocating this string during normal app runtime.
44
- def content
45
- @content ||= <<-CONTENT
46
- # Timber.io Ruby Configuration - Simple Structured Logging
47
- #
48
- # ^ ^ ^ ^ ___I_ ^ ^ ^ ^ ^ ^ ^
49
- # /|\\/|\\/|\\ /|\\ /\\-_--\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\
50
- # /|\\/|\\/|\\ /|\\ / \\_-__\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\
51
- # /|\\/|\\/|\\ /|\\ |[]| [] | /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\
52
- # -------------------------------------------------------------------
53
- # Website: https://timber.io
54
- # Documentation: https://timber.io/docs
55
- # Support: support@timber.io
56
- # -------------------------------------------------------------------
57
-
58
- config = Timber::Config.instance
59
-
60
- #{insert_hook}
61
- # For common configuration options see:
62
- # https://timber.io/docs/languages/ruby/configuration
63
- #
64
- # For a full list of configuration options see:
65
- # http://www.rubydoc.info/github/timberio/timber-ruby/Timber/Config
66
-
67
- CONTENT
68
- end
69
- end
70
- end
71
- end
@@ -1,53 +0,0 @@
1
- module Timber
2
- class CLI
3
- class FileHelper
4
- attr_reader :api
5
-
6
- def initialize(api)
7
- @api = api
8
- end
9
-
10
- def append(path, contents)
11
- File.open(path, "a") do |f|
12
- f.write(contents)
13
- end
14
- end
15
-
16
- def exists?(path)
17
- File.exists?(path)
18
- end
19
-
20
- def read_or_create(path, contents)
21
- if !exists?(path)
22
- write(path, contents)
23
- end
24
-
25
- read(path)
26
- end
27
-
28
- def read(path)
29
- File.read(path)
30
- end
31
-
32
- def write(path, contents)
33
- File.open(path, "w") do |f|
34
- f.write(contents)
35
- end
36
- end
37
-
38
- def verify(path, io)
39
- if !exists?(path)
40
- io.puts ""
41
- io.puts "Uh oh! It looks like we couldn't locate the #{path} file. "
42
- io.puts "Please enter the correct path:"
43
- io.puts
44
-
45
- new_path = io.gets
46
- verify(new_path, io)
47
- else
48
- path
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,70 +0,0 @@
1
- require "timber/cli/file_helper"
2
- require "timber/cli/io/messages"
3
-
4
- module Timber
5
- class CLI
6
- class Installer
7
- DEPRIORITIZED_PLATFORMS = ["linux", "other"].freeze
8
-
9
- attr_reader :io, :api, :file_helper
10
-
11
- def initialize(io, api)
12
- @io = io
13
- @api = api
14
- @file_helper = FileHelper.new(api)
15
- end
16
-
17
- def run(app)
18
- raise NotImplementedError.new
19
- end
20
-
21
- private
22
- def get_delivery_strategy(app)
23
- if DEPRIORITIZED_PLATFORMS.include?(app.platform_type)
24
- :http
25
- else
26
- :stdout
27
- end
28
- end
29
-
30
- # Determines the API key storage prference (environment variable or inline)
31
- def get_api_key_storage_preference
32
- io.puts ""
33
- io.puts IO::Messages.separator
34
- io.puts ""
35
- io.puts "For production/staging would you like to store your Timber API key"
36
- io.puts "in an environment variable? (TIMBER_API_KEY)"
37
- io.puts ""
38
- io.puts "y) Yes, store in TIMBER_API_KEY", :blue
39
- io.puts "n) No, just paste the API key inline", :blue
40
- io.puts ""
41
-
42
- case io.ask_yes_no("Enter your choice:", event_prompt: "Store API key in env?")
43
- when :yes
44
- io.puts ""
45
- io.puts IO::Messages.http_environment_variables(api.api_key)
46
- io.puts ""
47
-
48
- io.ask_to_proceed
49
-
50
- :environment
51
- when :no
52
- :inline
53
- end
54
- end
55
-
56
- # Based on the API key storage preference, we generate the proper code.
57
- def get_api_key_code(storage_type)
58
- case storage_type
59
- when :environment
60
- "ENV['TIMBER_API_KEY']"
61
- when :inline
62
- "'#{api.api_key}'"
63
- else
64
- raise ArgumentError.new("API key storage type not recognized! " \
65
- "#{storage_type.inspect}")
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,102 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "timber/cli/api"
4
- require "timber/cli/installers/root"
5
- require "timber/cli/io/messages"
6
- require "timber/cli/os_helper"
7
-
8
- module Timber
9
- class CLI
10
- module Installers
11
- def self.run(api_key, io)
12
- api = API.new(api_key)
13
- api.event(:started)
14
-
15
- begin
16
- io.puts IO::Messages.header, :green
17
- io.puts IO::Messages.separator, :green
18
- io.puts IO::Messages.contact, :green
19
- io.puts IO::Messages.separator, :green
20
- io.puts ""
21
-
22
- # if OSHelper.has_git?
23
- # if OSHelper.git_master? || !OSHelper.git_clean_working_tree?
24
- # io.puts "Before we begin, this installer will make a few simple code changes."
25
- # io.puts ""
26
-
27
- # case io.ask_yes_no("Would you like to exit and start over on a clean git branch?")
28
- # when :yes
29
- # command = "git checkout -b install-timber"
30
- # copied = OSHelper.copy_to_clipboard(command)
31
-
32
- # io.puts ""
33
- # io.puts "Good idea. Here's a simple git command to make things easier:"
34
- # io.puts ""
35
- # io.puts " #{IO::ANSI.colorize(command, :blue)}"
36
-
37
- # if copied
38
- # io.puts " #{IO::Messages.copied_to_clipboard}"
39
- # end
40
-
41
- # io.puts ""
42
- # io.puts "Once you've switched branches, run the installer command again."
43
- # io.puts ""
44
- # return
45
- # end
46
- # end
47
- # end
48
-
49
- if !api_key
50
- api.event(:no_api_key)
51
-
52
- app_url = IO::Messages::APP_URL
53
-
54
- io.puts "Hey there! Welcome to Timber. In order to proceed, you'll need an API key."
55
- io.puts "You can grab one by registering at #{IO::ANSI.colorize(app_url, :blue)}."
56
- io.puts ""
57
- io.puts "It takes less than a minute, with one click Google and Github registration."
58
- io.puts ""
59
-
60
- if OSHelper.can_open?
61
- case io.ask_yes_no("Open #{app_url}?")
62
- when :yes
63
- io.puts ""
64
- io.task("Opening #{app_url}") do
65
- OSHelper.open(app_url)
66
- end
67
- when :no
68
- io.puts ""
69
- io.puts "No problem, navigate to the following URL:"
70
- io.puts ""
71
- io.puts " #{IO::ANSI.colorize(app_url, :blue)}"
72
- end
73
- else
74
- io.puts ""
75
- io.puts "Please navigate to:"
76
- io.puts ""
77
- io.puts " #{IO::ANSI.colorize(app_url, :blue)}"
78
- end
79
-
80
- io.puts ""
81
- io.puts "Once you obtain your API key, you can run the installer like"
82
- io.puts ""
83
- io.puts " #{IO::ANSI.colorize("bundle exec timber install my-api-key", :blue)}"
84
- io.puts ""
85
- io.puts "See you soon! 🎈"
86
- io.puts ""
87
- else
88
- api.event(:api_key_provided)
89
- io.api = api
90
-
91
- app = api.application!
92
-
93
- Root.new(io, api).run(app)
94
- end
95
- rescue Exception => e
96
- api.event(:exception, message: e.message, stacktrace: e.backtrace)
97
- raise e
98
- end
99
- end
100
- end
101
- end
102
- end
@@ -1,51 +0,0 @@
1
- begin
2
- require "lograge"
3
- rescue Exception
4
- end
5
-
6
- require "timber/cli/config_file"
7
- require "timber/cli/installer"
8
- require "timber/cli/io/messages"
9
-
10
- module Timber
11
- class CLI
12
- module Installers
13
- class ConfigFile < Installer
14
- def run(app, path)
15
- config_file = Timber::CLI::ConfigFile.new(path, file_helper)
16
-
17
- if config_file.exists?
18
- io.task_complete("#{config_file.path} already created")
19
- return true
20
- end
21
-
22
- if lograge?
23
- task_message = "Enabling logrageify in #{config_file.path}"
24
- io.task(task_message) { config_file.logrageify! }
25
- elsif action_view?
26
- task_message = "Silencing template renders in #{config_file.path}"
27
- io.task(task_message) { config_file.silence_template_renders! }
28
- end
29
-
30
- task_message = "Creating #{config_file.path}"
31
- io.task(task_message) { config_file.create! }
32
- end
33
-
34
- private
35
- def lograge?
36
- require "lograge"
37
- true
38
- rescue Exception
39
- false
40
- end
41
-
42
- def action_view?
43
- require("action_view")
44
- true
45
- rescue Exception
46
- false
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,59 +0,0 @@
1
- require "timber/cli/installer"
2
- require "timber/cli/io/messages"
3
-
4
- module Timber
5
- class CLI
6
- module Installers
7
- class Other < Installer
8
- def run(app)
9
- case get_delivery_strategy(app)
10
- when :http
11
- api_key_storage_preference = get_api_key_storage_preference
12
- api_key_code = get_api_key_code(api_key_storage_preference)
13
- install_http(api_key_code)
14
- when :stdout
15
- install_stdout
16
- end
17
-
18
- ask_to_proceed
19
- end
20
-
21
- private
22
- def install_stdout
23
- io.puts ""
24
- io.puts IO::Messages.separator
25
- io.puts ""
26
- io.puts "To integrate Timber, simply use the Timber::Logger. Just set your"
27
- io.puts "global logger to something like this:"
28
- io.puts ""
29
- io.puts IO::ANSI.colorize(" LOGGER = Timber::Logger.new(STDOUT)", :blue)
30
- io.puts ""
31
- io.ask_to_proceed
32
- end
33
-
34
- def install_http(api_key_code)
35
- io.puts ""
36
- io.puts IO::Messages.separator
37
- io.puts ""
38
- io.puts "To integrate Timber, simply use the Timber::Logger. Just set your"
39
- io.puts "global logger to something like this:"
40
- io.puts ""
41
- io.puts IO::ANSI.colorize(" log_device = Timber::LogDevices::HTTP.new(#{api_key_code})", :blue)
42
- io.puts IO::ANSI.colorize(" LOGGER = Timber::Logger.new(log_device)", :blue)
43
- io.puts ""
44
- io.ask_to_proceed
45
- end
46
-
47
- def ask_to_proceed
48
- io.puts ""
49
- io.puts IO::Messages.separator
50
- io.puts ""
51
- io.puts "We're going to send a few test messages to ensure communication is working."
52
- io.puts ""
53
- io.ask_to_proceed
54
- io.puts ""
55
- end
56
- end
57
- end
58
- end
59
- end