Sha256: c30f307a23195b6fc376c81186c6ee865ecf986402a5a2b9f2ca894fa86acdf0
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
require "logger" require "singleton" # Logger interface class to access logger though symbolic names module BmcDaemonLib class LoggerPool include Singleton def get pipe @loggers ||= {} @loggers[pipe] ||= create(pipe) end def create pipe # Compute logfile or STDERR, and declare what we're doing filename = logfile(pipe) # Create the logger and return it logger = Logger.new(filename, LOG_ROTATION) #, 10, 1024000) logger.progname = pipe.to_s.downcase logger.formatter = LoggerFormatter # Finally return this logger logger rescue Errno::EACCES puts "logging [#{pipe}] failed: access error" end protected def logfile pipe # Disabled if no valid config return nil unless Conf[:logs].is_a?(Hash) # Compute logfile and check if we can write there logfile = File.expand_path(Conf[:logs][pipe].to_s, Conf[:logs][:path].to_s) # Check that we'll be able to create logfiles if File.exists?(logfile) # File is there, is it writable ? unless File.writable?(logfile) puts "logging [#{pipe}] disabled: file not writable [#{logfile}]" return nil end else # No file here, can we create it ? logdir = File.dirname(logfile) unless File.writable?(logdir) puts "logging [#{pipe}] disabled: directory not writable [#{logdir}]" return nil end end # OK, return a clean file path puts "logging [#{pipe}] to [#{logfile}]" return logfile end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bmc-daemon-lib-0.2.0 | lib/bmc-daemon-lib/logger_pool.rb |