lib/stash/sword/log_utils.rb in stash-sword-0.1.0 vs lib/stash/sword/log_utils.rb in stash-sword-0.1.1

- old
+ new

@@ -1,10 +1,11 @@ module Stash module Sword module LogUtils + def log - ::Stash::Sword.log + @log ||= default_logger end def log_error(e) if e.respond_to?(:response) log.error(response_to_log_msg(e.response)) @@ -32,8 +33,30 @@ hash.map do |k, v| value = v.is_a?(Hash) ? v.map { |k2, v2| "\n\t#{k2}: #{v2}" }.join : v "#{k}: #{value}" end.join("\n") end + + def level + # TODO: make this configurable + @level ||= case ENV['RAILS_ENV'].to_s.downcase + when 'test' + Logger::DEBUG + when 'development' + Logger::INFO + else + Logger::WARN + end + end + + def default_logger + logger = Logger.new($stdout, 10, 1024 * 1024) + logger.level = level + logger.formatter = proc do |severity, datetime, progname, msg| + "#{datetime.to_time.utc} #{severity} -#{progname}- #{msg}\n" + end + logger + end + end end end