自定义类LoggerClass代码

贴出自定义类LoggerClass代码:

 

require 'watir'
require 'logger'
require 'watir/logger'


class LoggerFactory
 
  def LoggerFactory.start_default_logger(fileNamePrefix)
    time = Time.now.strftime("%Y%m%d%H%M%S") 
    logger = CoreLogger.new(File.join(File.dirname(__FILE__), "..//TestLog//#{fileNamePrefix}_#{time}.txt") ,2, 1000000)
    return logger
  end
 
end


#this logs anything that Watir.rb tries to log, and everything with a "log" method to a text
#file that can be used for debugging.
class  CoreLogger < Watir::WatirLogger
 
  def initialize(fileName, logsToKeep, maxLogSize)
    super(fileName , logsToKeep, maxLogSize)
    self.level = Logger::INFO
    self.datetime_format = "%Y-%m%-%d %H:%M:%S"
    self.info("Core Logger starting...")         
  end
 
  #overloaded "log" from logger.rb to something more intuitive.
  def log(message)
    puts "log #{message}/n"  #optional. comment out if you don't want to see logging in the console
    info(message)                   #calls info in logger.rb -- would be good to use different logging levels
  end
end

你可能感兴趣的:(自定义类LoggerClass代码)