lib/bbc/cosmos/logger.rb in bbc-cosmos-logger-0.0.3 vs lib/bbc/cosmos/logger.rb in bbc-cosmos-logger-0.0.4

- old
+ new

@@ -24,27 +24,51 @@ DEFAULT_MAX_BACKUPS = 2 DEFAULT_MAXTIME = 600 DEFAULT_GELF_SERVER = 'localhost' DEFAULT_GELF_PORT = '12201' + def self.level + case "#{ENV['APP_LOG_LEVEL']}".upcase + when 'DEBUG' + Log4r::DEBUG + when 'INFO' + Log4r::INFO + when 'WARN' + Log4r::WARN + when 'ERROR' + Log4r::ERROR + when 'FATAL' + Log4r::FATAL + else + Log4r::INFO + end + end + def self.create(id) log = Log4r::Logger.new(id) + # Add File Outputter Log4r::RollingFileOutputter.new( 'logfile', :formatter => SimpleFormatter, :filename => ENV['APP_LOG_LOCATION'] || DEFAULT_LOG_LOCATION, :max_backups => ENV['LOG_MAX_BACKUPS'] || DEFAULT_MAX_BACKUPS, :maxtime => ENV['LOG_MAXTIME'] || DEFAULT_MAXTIME, :trunc => true) + log.add('logfile') + # Add Gelf Outputter Log4r::GelfOutputter.new( 'gelfling', :formatter => SimpleFormatter, 'gelf_server' => ENV['GELF_SERVER'], 'gelf_port' => ENV['GELF_PORT']) + log.add('gelfling') - log.tap {|l| l.add('logfile', 'gelfling') } + # Set Log Level + log.level = level + + log end end end end