lib/babelyoda/logger.rb in babelyoda-2.0.2 vs lib/babelyoda/logger.rb in babelyoda-2.0.3

- old
+ new

@@ -1,16 +1,19 @@ -require 'term/ansicolor' +require 'log4r-color' -module Babelyoda - class Logger - include Term::ANSIColor - - def exe(cmd) ; putcmd cmd ; system cmd ; end - def putcmd(cmd) ; print magenta, "CMD: #{cmd}", reset, "\n" ; end - def status(msg) ; print blue, "--- #{msg} ---", reset, "\n" ; end - def success(msg, heading = true) ; print green, bold, (heading ? 'SUCCESS: ' : ''), msg, reset, "\n" ; end - def error(msg, heading = true, do_exit = true) ; print red, bold, (heading ? 'ERROR: ' : ''), msg, reset, "\n" ; exit 1 if do_exit; end - def escape_cmd_args(args) ; args.collect{ |arg| "'#{arg}'"}.join(' ') ; end - end -end +unless $logger + Log4r::Logger.root.level = ENV['DEBUG'] ? Log4r::DEBUG : (ENV['VERBOSE'] ? Log4r::INFO : Log4r::WARN) -$logger ||= Babelyoda::Logger.new + Log4r::ColorOutputter.new 'color', { + :colors => { + :debug => :black, + :info => :blue, + :warn => :yellow, + :error => :red, + :fatal => {:color => :red, :background => :white} + }, + :formatter => Log4r::PatternFormatter.new(:pattern => "%l %m") + } + + $logger = Log4r::Logger.new('babelyoda') + $logger.add('color') +end