Skip to content
Browse files

getting this to work when no mongo connection can be established

  • Loading branch information...
1 parent 9e30346 commit ca70b60d6b5d70b09d15c32930e5dab93fd26a5f @andersonsp andersonsp committed
Showing with 7 additions and 3 deletions.
  1. +2 −0 lib/central_logger/initializer_mixin.rb
  2. +1 −1 lib/central_logger/mongo_logger.rb
  3. +4 −2 lib/central_logger/railtie.rb
View
2 lib/central_logger/initializer_mixin.rb
@@ -6,6 +6,8 @@ def create_logger(config, path)
logger = MongoLogger.new(:path => path, :level => level)
logger.auto_flushing = false if Rails.env.production?
logger
+ rescue Mongo::ConnectionFailure => e
+ return nil
rescue StandardError => e
logger = ActiveSupport::BufferedLogger.new(STDERR)
logger.level = ActiveSupport::BufferedLogger::WARN
View
2 lib/central_logger/mongo_logger.rb
@@ -30,7 +30,7 @@ def initialize(options={})
rescue => e
# should use a config block for this
#if Rails.env.production?
- puts "Using BufferedLogger due to exception: " + e.message
+ puts "Using BufferedLogger due to exception: #{e.inspect}"
raise e
end
View
6 lib/central_logger/railtie.rb
@@ -8,9 +8,11 @@ class Railtie < Rails::Railtie
# initializer will then skip its own initialization once Rails.logger is defined
initializer :initialize_central_logger, :before => :initialize_logger do
app_config = Rails.application.config
-
- Rails.logger = config.logger = create_logger(app_config,
+
+ clogger = create_logger(app_config,
((app_config.paths['log'] rescue nil) || app_config.paths.log.to_a).first)
+
+ Rails.logger = config.logger = clogger unless clogger.nil?
end
end
end

0 comments on commit ca70b60

Please sign in to comment.
Something went wrong with that request. Please try again.