timber 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 764a9a04b4bb8dcb4a6bd93e531ba1eea9959f8d
4
- data.tar.gz: 6dbf3db66270006e11d274c0a966456bb57e9419
3
+ metadata.gz: a5285d17535de9890e141603c444772904265630
4
+ data.tar.gz: 5ccb28e7a21bdcaa1d5d71822160114e422e5f7f
5
5
  SHA512:
6
- metadata.gz: b9b093be5167377e5b6566441c7e5e91f98f2eaa06bd18d25906ffd11fba35b9338dadb7aa99e85b05c8d64ddd659686d29d58d7aa8f8f8865d058d9c15688e2
7
- data.tar.gz: fc8ebd26419c4b8b248c8af55007b6579e428c96249cfc673ee4439de9480cde0f883d66880110cb1d5cb15b4ba84254e823bfd6da084fa716f330908dbd4507
6
+ metadata.gz: ef8847f90d849dabed1702427574a3864095cf6098801cad33cc45302203bdfdd4ccc11fd0c37c9724342ff29bf2f40c3ae9b98bf8da71d07f1b022f71f4b970
7
+ data.tar.gz: 8a200733730ff167b57ecbf844bd2aa1ab057bbab66dc3f6d407eec4830877c0b68e9437a1464123fd85bd1f150fdea044d3537cdf679d7414974e45f8d35210
@@ -40,6 +40,9 @@ module Timber
40
40
  puts Messages.heroku_install(app)
41
41
  puts ""
42
42
 
43
+ ask_yes_no("Ready to proceed?")
44
+ puts ""
45
+
43
46
  else
44
47
  puts ""
45
48
  puts Messages.separator
@@ -58,15 +61,18 @@ module Timber
58
61
  puts Messages.http_environment_variables(app.api_key)
59
62
  puts ""
60
63
 
64
+ ask_yes_no("Ready to proceed?")
65
+ puts ""
66
+
61
67
  when "2"
62
68
  create_initializer(:http, :api_key_code => "'#{app.api_key}'")
63
69
 
64
- puts ""
65
70
  end
66
71
 
67
72
  send_test_messages(api_key)
68
73
  end
69
74
 
75
+
70
76
  api.wait_for_logs do |iteration|
71
77
  write Messages.task_start("Waiting for logs")
72
78
  write Messages.spinner(iteration)
@@ -74,10 +80,6 @@ module Timber
74
80
 
75
81
  puts colorize(Messages.task_complete("Waiting for logs"), :green)
76
82
 
77
- puts ""
78
- puts Messages.separator
79
- puts ""
80
- puts Messages.free_data
81
83
  puts ""
82
84
  puts Messages.separator
83
85
  puts ""
@@ -87,6 +89,12 @@ module Timber
87
89
 
88
90
  collect_feedback(api)
89
91
 
92
+ puts ""
93
+ puts Messages.separator
94
+ puts ""
95
+ puts Messages.free_data
96
+ puts ""
97
+
90
98
  when :no
91
99
  puts ""
92
100
  puts "Bummer. Head to this URL to update the details:"
@@ -108,7 +116,7 @@ module Timber
108
116
  when :http
109
117
  api_key_code = options[:api_key_code] || raise(ArgumentError.new("the :api_key_code option is required"))
110
118
  "log_device = Timber::LogDevices::HTTP.new(#{api_key_code})\n" +
111
- "Timber::Logger.new(log_device)"
119
+ " Timber::Logger.new(log_device)"
112
120
 
113
121
  when :stdout
114
122
  "Timber::Logger.new(STDOUT)"
@@ -127,15 +135,19 @@ module Timber
127
135
  # Support: support@timber.io
128
136
 
129
137
  logger = case Rails.env
130
- when "development", "test"
131
- logger = Timber::Logger.new(STDOUT)
132
- logger.formatter = Timber::Logger::SimpleFormatter.new
133
- logger
134
- else
138
+ when "development"
139
+ # Write logs to STDOUT in a simple message only format
140
+ Timber::Logger.new(STDOUT).tap do |logger|
141
+ logger.formatter = Timber::Logger::SimpleFormatter.new
142
+ end
143
+ when "production", "staging"
135
144
  #{logger_code}
136
145
  end
137
146
 
138
- Timber::Frameworks::Rails.set_logger(logger)
147
+ if logger
148
+ logger.level = Rails.application.config.log_level
149
+ Timber::Frameworks::Rails.set_logger(logger)
150
+ end
139
151
  BODY
140
152
 
141
153
  FileUtils.mkdir_p(File.join(Dir.pwd, "config", "initializers"))
@@ -177,8 +189,6 @@ BODY
177
189
  puts ""
178
190
  puts "Thank you! We take feedback seriously and will work to improve this."
179
191
  end
180
-
181
- puts ""
182
192
  end
183
193
  end
184
194
  end
@@ -17,7 +17,7 @@ module Timber
17
17
 
18
18
  def application_details(app)
19
19
  message = <<-MESSAGE
20
- Woot! Your API 🔑 is valid. Here are you application details:
20
+ Woot! Your API 🔑 is valid:
21
21
 
22
22
  Name: #{app.name} (#{app.environment})
23
23
  Framework: #{app.framework_type}
@@ -43,7 +43,7 @@ message.rstrip
43
43
 
44
44
  def commit_and_deploy_reminder
45
45
  message = <<-MESSAGE
46
- Last step!
46
+ Last step! Commit and deploy:
47
47
 
48
48
  #{colorize("git add config/initializers/timber.rb", :blue)}
49
49
  #{colorize("git commit -am 'Install Timber'", :blue)}
@@ -53,6 +53,12 @@ MESSAGE
53
53
  message.rstrip
54
54
  end
55
55
 
56
+ def console_url(app)
57
+ message = <<-MESSAGE
58
+ Your console URL: https://app.timber.io/organizations/timber/apps/#{app.slug}/console
59
+ MESSAGE
60
+ end
61
+
56
62
  def contact
57
63
  message = <<-MESSAGE
58
64
  Website: #{WEBSITE_URL}
@@ -66,7 +72,7 @@ message.rstrip
66
72
  message = <<-MESSAGE
67
73
  Great! Add this variable to your environment:
68
74
 
69
- export TIMBER_API_KEY="#{api_key}"
75
+ #{colorize("export TIMBER_API_KEY=\"#{api_key}\"", :blue)}
70
76
 
71
77
  MESSAGE
72
78
  message.rstrip
@@ -74,15 +80,11 @@ message.rstrip
74
80
 
75
81
  def free_data
76
82
  message = <<-MESSAGE
77
- Get free data on Timeber!
83
+ As a welcome gift, we've credited your account with ✨ 50mb✨. Get more:
78
84
 
79
- * Timber URL: https://app.timber.io
80
85
  * Get ✨ 250mb✨ for tweeting your experience to #{TWITTER_HANDLE}
81
86
  * Get ✨ 100mb✨ for starring our repo: #{REPO_URL}
82
- * Get ✨ 50mb✨ for following #{TWITTER_HANDLE} on twitter
83
-
84
- (Your account will be credited within 2-3 business days.
85
- If you do not notice a credit please contact us: #{SUPPORT_EMAIL})
87
+ * Get ✨ 100mb✨ for following #{TWITTER_HANDLE} on twitter
86
88
  MESSAGE
87
89
  message.rstrip
88
90
  end
@@ -101,13 +103,10 @@ message.rstrip
101
103
 
102
104
  def heroku_install(app)
103
105
  message = <<-MESSAGE
104
- Now we need to send your logs from Heroku to Timber.
105
-
106
- Please run this command in a separate terminal, return back when complete:
106
+ To send logs from Heroku please run this command in a separate window:
107
107
 
108
108
  #{colorize("heroku drains:add #{app.heroku_drain_url}", :blue)}
109
109
 
110
- Note: Your Heroku app must be generating logs for this to work.
111
110
  MESSAGE
112
111
  message.rstrip
113
112
  end
@@ -175,7 +174,7 @@ message.rstrip
175
174
  end
176
175
 
177
176
  def we_love_you_too
178
- "💖 We love you too! Let's get to loggin' 🌲"
177
+ "Thanks! We 💖 you too!"
179
178
  end
180
179
  end
181
180
  end
data/lib/timber/config.rb CHANGED
@@ -17,29 +17,14 @@ module Timber
17
17
  class Config
18
18
  class NoLoggerError < StandardError; end
19
19
 
20
- FORM_URL_ENCODED_CONTENT_TYPE = "application/x-www-form-urlencoded".freeze
21
- JSON_CONTENT_TYPE = "application/json".freeze
22
-
23
20
  include Singleton
24
21
 
25
- attr_writer :capture_http_bodies, :debug_logger, :log_formatter, :logger
22
+ attr_writer :debug_logger, :http_body_limit, :logger
26
23
 
27
24
  def initialize
28
- @capture_http_bodies = true
29
- @capture_http_body_content_types = [FORM_URL_ENCODED_CONTENT_TYPE, JSON_CONTENT_TYPE]
30
25
  @http_body_limit = 2000
31
26
  end
32
27
 
33
- # Enables and disables the capturing of HTTP bodies in `Events::HTTPServerRequest`,
34
- # `HTTPClientRequest`, and `HTTPClientRespone`.
35
- def capture_http_bodies?
36
- @capture_http_bodies == true
37
- end
38
-
39
- # Limits HTTP body capturing to the listed content types. This must be an array.
40
- def capture_http_body_content_types
41
- @capture_http_body_content_types ||= []
42
- end
43
28
 
44
29
  # Set a debug_logger to view internal Timber library log message.
45
30
  # Useful for debugging. Defaults to `nil`. If set, debug messages will be
@@ -18,11 +18,6 @@ module Timber
18
18
  @query_string = Util::HTTPEvent.normalize_query_string(attributes[:query_string])
19
19
  @scheme = attributes[:scheme] || raise(ArgumentError.new(":scheme is required"))
20
20
  @request_id = attributes[:request_id]
21
-
22
- # This is disabled for now. The ControllerCall event records the parsed params.
23
- # This should be sufficient for body inspection. If we come across a case where
24
- # it is not we can consider re-enabling this.
25
- # @body = Util::HTTPEvent.normalize_body(attributes[:body])
26
21
  end
27
22
 
28
23
  def to_hash
@@ -5,20 +5,37 @@ module Timber
5
5
  class Railtie < ::Rails::Railtie
6
6
  config.timber = Config.instance
7
7
 
8
- initializer(:timber_logger, before: :initialize_logger) do
9
- Rails.configure_middlewares(config.app_middleware)
10
- Integrations.integrate!
11
-
8
+ initializer(:timber_silence_logger_complaints, before: :initialize_logger) do
12
9
  # We set a default logger because Rails tries to write to a file by default.
13
- # This causes errors on paltforms with a readon only file system (Heroku)
10
+ # This causes errors on platforms with a read only file system (Heroku).
11
+ # See this commit: https://github.com/heroku/rails_stdout_logging/commit/13d092650118bcfeb30f383d3274cee46cbf7b8f
14
12
  # Moreover, the Timber logger gets configured properly later in an initiailizer.
15
13
  # This is a hold over until we reach that file in the initialization process.
16
- logger = if defined?(::ActiveSupport::Logger)
17
- ::ActiveSupport::Logger.new(STDOUT)
18
- else
19
- ::Logger.new(STDOUT)
14
+ is_heroku = !ENV['DYNO'].nil?
15
+ if is_heroku
16
+ logger = defined?(::ActiveSupport::Logger) ?
17
+ ::ActiveSupport::Logger.new(STDOUT) : ::Logger.new(STDOUT)
18
+ ::Rails.logger = config.logger = logger
20
19
  end
21
- ::Rails.logger = Config.instance.logger = logger
20
+ end
21
+
22
+ # Initialize Timber immediately after the logger in case anything uses the logger
23
+ # during the initialization process.
24
+ initializer(:timber, after: :initialize_logger) do
25
+ # The goals here:
26
+ # 1. Respect the default log device that rails sets in :initialize_logger
27
+ # 2. Replace the logger with Timber::Logger so that users get our logger API
28
+ # 3. Disable metadata so that the logger is essentially transparent until further
29
+ # configuration in initializers/timber.rb. This allows them to essentially "turn on"
30
+ # timber for production, staging, etc.
31
+ log_device = ::Rails.logger.instance_variable_get(:@logdev).try(:dev)
32
+ logger = Logger.new(log_device)
33
+ logger.formatter = Logger::SimpleFormatter.new
34
+ logger.level = ::Rails.logger.level
35
+ ::Rails.logger = config.logger = logger
36
+
37
+ Rails.configure_middlewares(config.app_middleware)
38
+ Integrations.integrate!
22
39
  end
23
40
  end
24
41
 
@@ -10,11 +10,9 @@ module Timber
10
10
  def call(env)
11
11
  start = Time.now
12
12
  request = Util::Request.new(env)
13
- body = Config.instance.capture_http_bodies? ? request.body_content : nil
14
13
 
15
14
  Config.instance.logger.info do
16
15
  Events::HTTPServerRequest.new(
17
- body: body,
18
16
  headers: request.headers,
19
17
  host: request.host,
20
18
  method: request.request_method,
data/lib/timber/logger.rb CHANGED
@@ -166,10 +166,11 @@ module Timber
166
166
  end
167
167
  end
168
168
 
169
- class << self
170
- def new_from_config
171
- end
172
- end
169
+ # These are rails modules that change the logger behavior. We have to
170
+ # include these if they are present or the logger will not function properly
171
+ # in a rails environment.
172
+ include ::ActiveSupport::LoggerThreadSafeLevel if defined?(::ActiveSupport::LoggerThreadSafeLevel)
173
+ include ::LoggerSilence if defined?(::LoggerSilence)
173
174
 
174
175
  # Creates a new Timber::Logger instances. Accepts the same arguments as `::Logger.new`.
175
176
  # The only difference is that it default the formatter to {HybridFormatter}. Using
@@ -194,6 +195,8 @@ module Timber
194
195
 
195
196
  self.level = environment_level
196
197
 
198
+ after_initialize if respond_to? :after_initialize
199
+
197
200
  @initialized = true
198
201
  end
199
202
 
@@ -15,18 +15,12 @@ module Timber
15
15
  end
16
16
  end
17
17
 
18
- def normalize_body(content_type, body)
19
- if Config.instance.capture_http_body_content_types.include?(content_type)
20
- if body.respond_to?(:body)
21
- body = body.body.to_s
22
- end
23
-
24
- body[0..(Config.instance.http_body_limit - 1)]
25
- else
26
- # Drop the body if it is not a format we want to capture.
27
- # This gives users more control to avoid loggin files, etc.
28
- nil
18
+ def normalize_body(body)
19
+ if body.respond_to?(:body)
20
+ body = body.body.to_s
29
21
  end
22
+
23
+ body[0..(Config.instance.http_body_limit - 1)]
30
24
  end
31
25
 
32
26
  def normalize_headers(headers)
@@ -1,3 +1,3 @@
1
1
  module Timber
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
data/timber.gemspec CHANGED
@@ -20,16 +20,16 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_dependency('msgpack', '~> 1.0')
22
22
 
23
- s.add_development_dependency('rails_stdout_logging', '~> 0')
24
- s.add_development_dependency('rake', '~> 0')
23
+ s.add_development_dependency('rails_stdout_logging', '>= 0')
24
+ s.add_development_dependency('rake', '>= 0')
25
25
  s.add_development_dependency('rspec', '~> 3.4')
26
- s.add_development_dependency('rspec-its', '~> 0')
27
- s.add_development_dependency('timecop', '~> 0')
26
+ s.add_development_dependency('rspec-its', '>= 0')
27
+ s.add_development_dependency('timecop', '>= 0')
28
28
 
29
29
  if RUBY_PLATFORM == "java"
30
- s.add_development_dependency('activerecord-jdbcsqlite3-adapter', '~> 0')
30
+ s.add_development_dependency('activerecord-jdbcsqlite3-adapter', '>= 0')
31
31
  else
32
- s.add_development_dependency('sqlite3', '~> 0')
32
+ s.add_development_dependency('sqlite3', '>= 0')
33
33
  end
34
34
 
35
35
  if RUBY_VERSION
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timber
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timber Technologies, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-22 00:00:00.000000000 Z
11
+ date: 2017-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -28,28 +28,28 @@ dependencies:
28
28
  name: rails_stdout_logging
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
@@ -70,42 +70,42 @@ dependencies:
70
70
  name: rspec-its
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: timecop
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: sqlite3
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency