Sha256: bc13c3fdff8c6e92ecc65178750dc73904e9645d2da721ee45f329df07d30190
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 KB
Contents
require "logger" require "singleton" # Logger interface class to access logger though symbolic names module BmcDaemonLib class LoggerPool include Singleton def get pipe = nil pipe = :default if pipe.to_s.blank? @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) && Conf.at(:logs, pipe) # Build logfile from Conf logfile = Conf.logfile_path pipe return nil if logfile.nil? # 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.3.4 | lib/bmc-daemon-lib/logger_pool.rb |