Sha256: 66b26d25445841ff584a0ac5d90d3f0b1acc35a374ce19769f2c7c23d0c06cf5

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 KB

Contents

begin
  require 'syslog'

  # Ensure that Syslog is open
  begin
    Syslog.open('god')
  rescue RuntimeError
    Syslog.reopen('god')
  end

  Syslog.info("Syslog enabled.")

  module God

    class SysLogger
      SYMBOL_EQUIVALENTS = { :fatal => Syslog::LOG_CRIT,
                             :error => Syslog::LOG_ERR,
                             :warn => Syslog::LOG_WARNING,
                             :info => Syslog::LOG_INFO,
                             :debug => Syslog::LOG_DEBUG }

      # Set the log level
      #   +level+ is the Symbol level to set as maximum. One of:
      #           [:fatal | :error | :warn | :info | :debug ]
      #
      # Returns Nothing
      def self.level=(level)
        Syslog.mask = Syslog::LOG_UPTO(SYMBOL_EQUIVALENTS[level])
      end

      # Log a message to syslog.
      #   +level+ is the Symbol level of the message. One of:
      #           [:fatal | :error | :warn | :info | :debug ]
      #   +text+ is the String text of the message
      #
      # Returns Nothing
      def self.log(level, text)
        Syslog.log(SYMBOL_EQUIVALENTS[level], '%s', text)
      end
    end

  end
rescue Object => e
  puts "Syslog could not be enabled: #{e.message}"
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
resurrected_god-0.14.0 lib/god/sys_logger.rb
mcproc-2016.2.20 lib/god/sys_logger.rb
god-0.13.7 lib/god/sys_logger.rb
god-0.13.6 lib/god/sys_logger.rb
god-0.13.5 lib/god/sys_logger.rb
god-0.13.4 lib/god/sys_logger.rb
god-0.13.3 lib/god/sys_logger.rb
god-0.13.2 lib/god/sys_logger.rb
god-0.13.1 lib/god/sys_logger.rb
god-0.13.0 lib/god/sys_logger.rb
god-0.12.1 lib/god/sys_logger.rb
god-0.12.0 lib/god/sys_logger.rb