Module: Stash::Sword::LogUtils
- Included in:
- Client, HTTPHelper
- Defined in:
- lib/stash/sword/log_utils.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.create_default_logger(io, level)
49 50 51 52 53 54 55 56 |
# File 'lib/stash/sword/log_utils.rb', line 49 def self.create_default_logger(io, level) logger = Logger.new(io, 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 |
Instance Method Details
#default_logger
45 46 47 |
# File 'lib/stash/sword/log_utils.rb', line 45 def default_logger LogUtils.create_default_logger($stdout, level) end |
#hash_to_log_msg(hash)
26 27 28 29 30 31 |
# File 'lib/stash/sword/log_utils.rb', line 26 def hash_to_log_msg(hash) 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 |
#level
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/stash/sword/log_utils.rb', line 33 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 |
#log
5 6 7 |
# File 'lib/stash/sword/log_utils.rb', line 5 def log @log ||= default_logger end |
#log_error(e)
9 10 11 |
# File 'lib/stash/sword/log_utils.rb', line 9 def log_error(e) log.error(to_log_msg(e)) end |
#log_hash(hash)
21 22 23 24 |
# File 'lib/stash/sword/log_utils.rb', line 21 def log_hash(hash) msg = hash_to_log_msg(hash) log.debug(msg) end |
#to_log_msg(e)
13 14 15 16 17 18 19 |
# File 'lib/stash/sword/log_utils.rb', line 13 def to_log_msg(e) msg_lines = [] (msg_lines, e) append_response(msg_lines, e) append_backtrace(msg_lines, e) msg_lines.join("\n") end |