Sha256: 3955766bad949149e20c1fdcd8335449551b813747d5cb4dd252d8a051804d80

Contents?: true

Size: 1.3 KB

Versions: 58

Compression:

Stored size: 1.3 KB

Contents

module MCollective
  module Logger
    # Implements a syslog based logger using the standard ruby syslog class
    class Syslog_logger<Base
      require 'syslog'

      include Syslog::Constants

      def start
        config = Config.instance

        facility = syslog_facility(config.logfacility)
        level = config.loglevel.to_sym

        Syslog.close if Syslog.opened?
        Syslog.open(File.basename($0), 3, facility)

        set_level(level)
      end

      def syslog_facility(facility)
        begin
          Syslog.const_get("LOG_#{facility.upcase}")
        rescue NameError => e
          STDERR.puts "Invalid syslog facility #{facility} supplied, reverting to USER"
          Syslog::LOG_USER
        end
      end

      def set_logging_level(level)
        # noop
      end

      def valid_levels
        {:info  => :info,
         :warn  => :warning,
         :debug => :debug,
         :fatal => :crit,
         :error => :err}
      end

      def log(level, from, msg)
        if @known_levels.index(level) >= @known_levels.index(@active_level)
          Syslog.send(map_level(level), "#{from} #{msg}")
        end
      rescue
        # if this fails we probably cant show the user output at all,
        # STDERR it as last resort
        STDERR.puts("#{level}: #{msg}")
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 2 rubygems

Version Path
choria-mcorpc-support-2.22.1 lib/mcollective/logger/syslog_logger.rb
choria-mcorpc-support-2.22.0 lib/mcollective/logger/syslog_logger.rb
choria-mcorpc-support-2.21.1 lib/mcollective/logger/syslog_logger.rb
choria-mcorpc-support-2.21.0 lib/mcollective/logger/syslog_logger.rb
choria-mcorpc-support-2.20.8 lib/mcollective/logger/syslog_logger.rb
mcollective-client-2.12.5 lib/mcollective/logger/syslog_logger.rb
choria-mcorpc-support-2.20.7 lib/mcollective/logger/syslog_logger.rb
choria-mcorpc-support-2.20.6 lib/mcollective/logger/syslog_logger.rb
choria-mcorpc-support-2.20.5 lib/mcollective/logger/syslog_logger.rb
choria-mcorpc-support-2.20.4 lib/mcollective/logger/syslog_logger.rb
choria-mcorpc-support-2.20.3 lib/mcollective/logger/syslog_logger.rb
choria-mcorpc-support-2.20.2 lib/mcollective/logger/syslog_logger.rb
choria-mcorpc-support-2.20.0 lib/mcollective/logger/syslog_logger.rb
choria-mcorpc-support-0.0.1 lib/mcollective/logger/syslog_logger.rb
mcollective-client-2.12.4 lib/mcollective/logger/syslog_logger.rb
mcollective-client-2.12.3 lib/mcollective/logger/syslog_logger.rb
mcollective-client-2.12.1 lib/mcollective/logger/syslog_logger.rb
mcollective-client-2.12.0 lib/mcollective/logger/syslog_logger.rb
mcollective-client-2.10.6 lib/mcollective/logger/syslog_logger.rb
mcollective-client-2.11.4 lib/mcollective/logger/syslog_logger.rb