Sha256: cb0bdcc5100285a6fdd6213795e6dd533f116a3650f597a63c87567f1b12fd3b
Contents?: true
Size: 1.64 KB
Versions: 4
Compression:
Stored size: 1.64 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) # 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
4 entries across 4 versions & 1 rubygems