Module: ZabbixRubyClient::Log
Instance Method Summary collapse
- #debug(msg) ⇒ Object
- #error(msg) ⇒ Object
- #fatal(msg) ⇒ Object
- #get_level_constant(level) ⇒ Object
- #info(msg) ⇒ Object
- #logger ⇒ Object
- #set_logger(logfile, level = "info") ⇒ Object
- #warn(msg) ⇒ Object
Instance Method Details
#debug(msg) ⇒ Object
22 23 24 |
# File 'lib/zabbix-ruby-client/logger.rb', line 22 def debug(msg) logger.debug(msg) end |
#error(msg) ⇒ Object
34 35 36 |
# File 'lib/zabbix-ruby-client/logger.rb', line 34 def error(msg) logger.error(msg) end |
#fatal(msg) ⇒ Object
38 39 40 |
# File 'lib/zabbix-ruby-client/logger.rb', line 38 def fatal(msg) logger.fatal(msg) end |
#get_level_constant(level) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/zabbix-ruby-client/logger.rb', line 42 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 |
#info(msg) ⇒ Object
26 27 28 |
# File 'lib/zabbix-ruby-client/logger.rb', line 26 def info(msg) logger.info(msg) end |
#logger ⇒ Object
18 19 20 |
# File 'lib/zabbix-ruby-client/logger.rb', line 18 def logger @logger ||= ::Logger.new(STDOUT) end |
#set_logger(logfile, level = "info") ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/zabbix-ruby-client/logger.rb', line 7 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 |
#warn(msg) ⇒ Object
30 31 32 |
# File 'lib/zabbix-ruby-client/logger.rb', line 30 def warn(msg) logger.warn(msg) end |