Sha256: 285bcfb12db9eaec5d892b2a3b1580b09af5a66badf9ea79a127fbbedaad78bf

Contents?: true

Size: 1.01 KB

Versions: 12

Compression:

Stored size: 1.01 KB

Contents

require "logger"

module ZabbixRubyClient
  module Log
    extend self

    def set_logger(logfile, level="info")
      if logfile.is_a?(String) && !Dir.exists?(File.dirname(logfile))
        FileUtils.mkdir_p(File.dirname(logfile))
      end
      @logger = ::Logger.new(logfile)
      @logger.level = get_level_constant(level)
      @logger.formatter = proc do |severity, datetime, progname, msg|
        "[#{datetime.utc}] #{severity}: #{msg}\n"
      end
    end

    def logger
      @logger ||= ::Logger.new(STDOUT)
    end

    def debug(msg)
      logger.debug(msg)
    end

    def info(msg)
      logger.info(msg)
    end

    def warn(msg)
      logger.warn(msg)
    end

    def error(msg)
      logger.error(msg)
    end

    def fatal(msg)
      logger.fatal(msg)
    end

    def get_level_constant(level)
      if level
        begin
          ::Logger.const_get(level.to_s.upcase)
        rescue NameError
          return ::Logger::INFO
        end
      else
        ::Logger::INFO
      end
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
zabbix-ruby-client-0.1.3 lib/zabbix-ruby-client/logger.rb
zabbix-ruby-client-0.1.2 lib/zabbix-ruby-client/logger.rb
zabbix-ruby-client-0.1.1 lib/zabbix-ruby-client/logger.rb
zabbix-ruby-client-0.1.0 lib/zabbix-ruby-client/logger.rb
zabbix-ruby-client-0.0.23 lib/zabbix-ruby-client/logger.rb
zabbix-ruby-client-0.0.22 lib/zabbix-ruby-client/logger.rb
zabbix-ruby-client-0.0.21 lib/zabbix-ruby-client/logger.rb
zabbix-ruby-client-0.0.20 lib/zabbix-ruby-client/logger.rb
zabbix-ruby-client-0.0.19 lib/zabbix-ruby-client/logger.rb
zabbix-ruby-client-0.0.18 lib/zabbix-ruby-client/logger.rb
zabbix-ruby-client-0.0.17 lib/zabbix-ruby-client/logger.rb
zabbix-ruby-client-0.0.16 lib/zabbix-ruby-client/logger.rb