Module: MongodbLogger::InitializerMixin

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) create_logger(config)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mongodb_logger/initializer_mixin.rb', line 10

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.auto_flushing = false if Rails.env.production? && rails3(1)
  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

- (Object) rails3(minor = 0)



6
7
8
# File 'lib/mongodb_logger/initializer_mixin.rb', line 6

def rails3(minor = 0)
  3 == Rails::VERSION::MAJOR && minor == Rails::VERSION::MINOR
end