Module: MongodbLogger::InitializerMixin

Included in:
Railtie
Defined in:
lib/mongodb_logger/initializer_mixin.rb

Instance Method Summary collapse

Instance Method Details

#create_logger(config) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mongodb_logger/initializer_mixin.rb', line 6

def create_logger(config)
  path = config.paths['log'].first
  level = RailsLogger.const_get(config.log_level.to_s.upcase)
  logger = MongodbLogger::Logger.new(path, level)
  # decorating with TaggedLogging
  logger = MongodbLogger::TaggedLogger.new(logger) if defined?(ActiveSupport::TaggedLogging)
  logger.level = level
  logger
rescue StandardError => e
  logger = RailsLogger.new(STDERR)
  logger.level = RailsLogger::WARN
  logger.warn(
    "MongodbLogger Initializer Error: Rails will switched to standard logger." + "\n" +
    e.message + "\n" + e.backtrace.join("\n")
  )
  (ENV['HEROKU_RACK'] ? logger : nil) # use standard rails logger, except heroku
end