class Camo::Logger
Constants
- LOG_LEVEL
- LOG_LEVELS
Attributes
errpipe[R]
outpipe[R]
Public Class Methods
new(outpipe, errpipe)
click to toggle source
# File lib/camo/logger.rb, line 8 def initialize(outpipe, errpipe) @outpipe = outpipe @errpipe = errpipe end
stdio()
click to toggle source
# File lib/camo/logger.rb, line 13 def self.stdio new $stdout, $stderr end
Public Instance Methods
debug(msg, params = {})
click to toggle source
# File lib/camo/logger.rb, line 17 def debug(msg, params = {}) outpipe.puts(compile_output("debug", msg, params)) if debug? end
error(msg, params = {})
click to toggle source
# File lib/camo/logger.rb, line 25 def error(msg, params = {}) errpipe.puts(compile_output("error", msg, params)) if error? end
info(msg, params = {})
click to toggle source
# File lib/camo/logger.rb, line 21 def info(msg, params = {}) outpipe.puts(compile_output("info", msg, params)) if info? end
Private Instance Methods
compile_output(level, msg, params)
click to toggle source
# File lib/camo/logger.rb, line 43 def compile_output(level, msg, params) output = [] output << "[#{level.upcase}]" output << (msg.is_a?(Array) ? msg.join(", ") : msg) if params.any? output << "|" output << convert_params_to_string(params) end output.join(" ") end
convert_params_to_string(params)
click to toggle source
# File lib/camo/logger.rb, line 56 def convert_params_to_string(params) elements = [] params.each do |key, value| compiled_value = if value.is_a?(Hash) convert_params_to_string(value) else "\"#{value}\"" end elements << "#{key}: #{compiled_value}" end "{ #{elements.join(", ")} }" end
debug?()
click to toggle source
# File lib/camo/logger.rb, line 31 def debug? LOG_LEVELS.find_index(LOG_LEVEL) <= LOG_LEVELS.find_index("debug") end
error?()
click to toggle source
# File lib/camo/logger.rb, line 39 def error? LOG_LEVELS.find_index(LOG_LEVEL) <= LOG_LEVELS.find_index("error") end
info?()
click to toggle source
# File lib/camo/logger.rb, line 35 def info? LOG_LEVELS.find_index(LOG_LEVEL) <= LOG_LEVELS.find_index("info") end