lib/simple_deploy/logger.rb in simple_deploy-0.4.0 vs lib/simple_deploy/logger.rb in simple_deploy-0.4.1
- old
+ new
@@ -1,40 +1,31 @@
module SimpleDeploy
class SimpleDeployLogger
-
+
+ require 'forwardable'
+
+ extend Forwardable
+
+ def_delegators :@logger, :debug, :error, :info, :warn
+
def initialize(args = {})
- @logger = args[:logger] ||= Logger.new(STDOUT)
@log_level = args[:log_level] ||= 'info'
+ @logger = args[:logger] ||= new_logger(args)
+ end
- unless args[:logger]
- @logger.datetime_format = "%Y-%m-%d %H:%M:%S"
- @logger.formatter = proc do |severity, datetime, progname, msg|
- "#{datetime}: #{msg}\n"
+ private
+ def new_logger(args)
+ Logger.new(STDOUT).tap do |l|
+ l.datetime_format = '%Y-%m-%dT%H:%M:%S%z'
+ l.formatter = proc do |severity, datetime, progname, msg|
+ "#{datetime} #{severity} : #{msg}\n"
end
+ l.level = logger_level
end
-
- case @log_level.downcase
- when 'info'
- @logger.level = Logger::INFO
- when 'debug'
- @logger.level = Logger::DEBUG
- when 'warn'
- @logger.level = Logger::WARN
- when 'error'
- @logger.level = Logger::ERROR
- end
- @logger
end
- def debug(msg)
- @logger.debug msg
+ def logger_level
+ Logger.const_get @log_level.upcase
end
- def info(msg)
- @logger.info msg
- end
-
- def error(msg)
- @logger.error msg
- end
end
end