Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

wrap rails_log_stdout in an exception handler

  • Loading branch information...
commit a33058d537c2a2c33d96831bf4b271c0827368c0 1 parent 3428d35
@ddollar authored
Showing with 36 additions and 28 deletions.
  1. +36 −28 init.rb
View
64 init.rb
@@ -1,32 +1,40 @@
-STDOUT.sync = true
+begin
-def Rails.heroku_stdout_logger
- logger = Logger.new(STDOUT)
- logger.level = Logger.const_get(([ENV['LOG_LEVEL'].to_s.upcase, "INFO"] & %w[DEBUG INFO WARN ERROR FATAL UNKNOWN]).compact.first)
- logger
-end
+ STDOUT.sync = true
+
+ def Rails.heroku_stdout_logger
+ logger = Logger.new(STDOUT)
+ logger.level = Logger.const_get(([ENV['LOG_LEVEL'].to_s.upcase, "INFO"] & %w[DEBUG INFO WARN ERROR FATAL UNKNOWN]).compact.first)
+ logger
+ end
-case Rails::VERSION::MAJOR
- when 3 then Rails.logger = Rails.application.config.logger = Rails.heroku_stdout_logger
- when 2 then
- # redefine Rails.logger
- def Rails.logger
- @@logger ||= Rails.heroku_stdout_logger
- end
- %w(
- ActiveSupport::Dependencies
- ActiveRecord::Base
- ActionController::Base
- ActionMailer::Base
- ActionView::Base
- ActiveResource::Base
- ).each do |klass_name|
- begin
- klass = Object
- klass_name.split("::").each { |part| klass = klass.const_get(part) }
- klass.logger = Rails.logger
- rescue
+ case Rails::VERSION::MAJOR
+ when 3 then Rails.logger = Rails.application.config.logger = Rails.heroku_stdout_logger
+ when 2 then
+ # redefine Rails.logger
+ def Rails.logger
+ @@logger ||= Rails.heroku_stdout_logger
+ end
+ %w(
+ ActiveSupport::Dependencies
+ ActiveRecord::Base
+ ActionController::Base
+ ActionMailer::Base
+ ActionView::Base
+ ActiveResource::Base
+ ).each do |klass_name|
+ begin
+ klass = Object
+ klass_name.split("::").each { |part| klass = klass.const_get(part) }
+ klass.logger = Rails.logger
+ rescue
+ end
end
- end
- Rails.cache.logger = Rails.logger rescue nil
+ Rails.cache.logger = Rails.logger rescue nil
+ end
+
+rescue Exception => ex
+
+ puts "WARNING: Exception during rails_log_stdout init: #{ex.message}"
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.