class MetricCollect::Log
Public Class Methods
build_time()
click to toggle source
# File lib/metric_collect/log.rb, line 38 def self.build_time time = Time.now year = "%04d" % time.year month = "%02d" % time.month day = "%02d" % time.day hour = "%02d" % time.hour min = "%02d" % time.min sec = "%02d" % time.sec "#{year}-#{month}-#{day} #{hour}:#{min}:#{sec}" end
fatal(msg, error=nil)
click to toggle source
# File lib/metric_collect/log.rb, line 32 def self.fatal(msg, error=nil) Log.write(msg, "FATAL") raise error if error exit end
info(msg)
click to toggle source
# File lib/metric_collect/log.rb, line 24 def self.info(msg) Log.write(msg, "INFO") end
new(log_file=nil)
click to toggle source
# File lib/metric_collect/log.rb, line 20 def initialize(log_file=nil) @log_file = log_file end
warn(msg)
click to toggle source
# File lib/metric_collect/log.rb, line 28 def self.warn(msg) Log.write(msg, "WARN") end
Private Class Methods
write(msg, level)
click to toggle source
# File lib/metric_collect/log.rb, line 51 def self.write(msg, level) if @log_file File.open(@log_file, 'w') do |log| log.write("#{build_time}|#{level}|#{msg}") end else puts "#{build_time}|#{level}|#{msg}" end end