module Flex::Template::Logger

Public Instance Methods

caller_line() click to toggle source
# File lib/flex/template/logger.rb, line 5
def caller_line
  caller.find{|l| l !~ /(#{LIB_PATHS.join('|')})/}
end

Private Instance Methods

curl_format(h) click to toggle source
# File lib/flex/template/logger.rb, line 42
def curl_format(h)
  pretty = h[:path] =~ /\?/ ? '&pretty=1' : '?pretty=1'
  curl =  %(curl -X#{method} "#{Conf.base_uri}#{h[:path]}#{pretty}")
  if h[:data]
    data = h[:data].is_a?(String) ? h[:data] : MultiJson.encode(h[:data], :pretty => true)
    curl << %( -d '\n#{data}\n')
  end
  curl
end
log_render(int, path, encoded_data, result) click to toggle source
# File lib/flex/template/logger.rb, line 15
def log_render(int, path, encoded_data, result)
  logger = Conf.logger
  return unless logger.is_a?(Flex::Logger)
  logger.info Dye.dye("Rendered #{template_name} from: #{caller_line}", :blue, :bold)
  return unless logger.level == ::Logger::DEBUG

  h = {}
  if logger.debug_variables
    h[:variables] = int[:vars] if int
  end
  if logger.debug_request
    h[:request] = {}
    h[:request][:method] = method
    h[:request][:path]   = path
    h[:request][:data]   = begin
                             MultiJson.decode(encoded_data) unless encoded_data.nil?
                           rescue MultiJson::DecodeError
                             encoded_data
                           end
    h[:request].delete(:data) if h[:request][:data].nil?
  end
  if logger.debug_result
    h[:result] = result if result
  end
  logger.debug logger.curl_format ? curl_format(h[:request]) : yaml_format(h)
end
template_name() click to toggle source
# File lib/flex/template/logger.rb, line 11
def template_name
  @host_flex && @name && "#{@host_flex.context}.#@name" || 'template'
end
yaml_format(hash) click to toggle source
# File lib/flex/template/logger.rb, line 52
def yaml_format(hash)
  hash.to_yaml.split("\n").map do |l|
    case l
    when /^---$/
    when /^( |-)/
      Dye.dye(l, :blue)
    when  /^:(variables|request|result)/
      Dye.dye(l, :magenta, :bold) + (Dye.color ? Dye.sgr(:blue) : '')
    end
  end.compact.join("\n") + "\n"
end