Sha256: 9006a9092f4561e87a685e7917159b4eb5b298feb12b2071dff2997c4b552a58

Contents?: true

Size: 928 Bytes

Versions: 39

Compression:

Stored size: 928 Bytes

Contents

Appfuel::Initialize.define('global.logging') do |config, container|
  log_file  = config[:logfile] || 'stdout'
  log_level = config[:log_level] || 'info'

  logfile_coercer = ->(file) {
    file = file.to_s
    if file.empty? || file.downcase == 'stdout'
      file = $stdout
    elsif file.downcase == 'stderr'
      file = $stderr
    else
      file
    end
  }

  log_formatter = Appfuel::LogFormatter

  logger_factory = ->(file, level = nil, formatter = nil) {
    logger = Logger.new(file)
    if level
      logger.level = Logger.const_get(level.to_s.upcase)
    end

    if formatter
      logger.formatter = log_formatter
    end

    logger
  }

  logger = logger_factory.call(log_file, log_level, log_formatter)
  container.register(:log_formatter, log_formatter)
  container.register(:logfile_coercer, logfile_coercer)
  container.register(:logger_factory, logger_factory)
  container.register(:logger, logger)
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
appfuel-0.7.0 lib/appfuel/initializers/logging.rb
appfuel-0.6.16 lib/appfuel/initializers/logging.rb
appfuel-0.6.15 lib/appfuel/initializers/logging.rb
appfuel-0.6.14 lib/appfuel/initializers/logging.rb
appfuel-0.6.13 lib/appfuel/initializers/logging.rb
appfuel-0.6.12 lib/appfuel/initializers/logging.rb
appfuel-0.6.11 lib/appfuel/initializers/logging.rb
appfuel-0.6.10 lib/appfuel/initializers/logging.rb
appfuel-0.6.9 lib/appfuel/initializers/logging.rb
appfuel-0.6.8 lib/appfuel/initializers/logging.rb
appfuel-0.6.7 lib/appfuel/initializers/logging.rb
appfuel-0.6.6 lib/appfuel/initializers/logging.rb
appfuel-0.6.5 lib/appfuel/initializers/logging.rb
appfuel-0.6.4 lib/appfuel/initializers/logging.rb
appfuel-0.6.3 lib/appfuel/initializers/logging.rb
appfuel-0.6.1 lib/appfuel/initializers/logging.rb
appfuel-0.5.16 lib/appfuel/initializers/logging.rb
appfuel-0.5.15 lib/appfuel/initializers/logging.rb
appfuel-0.5.14 lib/appfuel/initializers/logging.rb
appfuel-0.5.13 lib/appfuel/initializers/logging.rb