Module: Bitcoin::Logger

Defined in:
lib/bitcoin/logger.rb

Overview

this is a very simple logger that is used if log4r is not available

Defined Under Namespace

Modules: TimeLogger Classes: LogWrapper, Logger

Class Method Summary collapse

Class Method Details

.create(name, level = :info) ⇒ Object

create a logger with given name. if log4r is installed, the logger will have a stdout and a fileout outputter to ‘log/<name>.log`. otherwise, the internal dummy logger is used which only logs to stdout.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/bitcoin/logger.rb', line 70

def self.create name, level = :info
  if defined?(Log4r)
    dir = "log"
    FileUtils.mkdir_p(dir) rescue dir = nil
    @log = Log4r::Logger.new(name.to_s)
    @log.extend(TimeLogger)
    @log.level = level
    @log.outputters << Log4r::Outputter.stdout
    @log.outputters << Log4r::FileOutputter.new("fout", :filename => "#{dir}/#{name}.log")  if dir
  else
    @log = Bitcoin::Logger::Logger.new(name)
  end
  @log
end