module Moon::Logfmt

Implementation of logfmt for Moon

Constants

NullLogger
UNESCAPED_STRING

Regular expression used for checking strings that may need escaping. This regular expression will validate true if the string doesn't need escaping.

VERSION

@return [String]

Public Class Methods

determine_loglevel_from_object(object) click to toggle source

Determines what the loglevel should be from the given object

@param [Object] object @return [Integer] loglevel

# File lib/moon-logfmt/utils.rb, line 34
def self.determine_loglevel_from_object(object)
  return object if object.is_a?(Integer)
  case object.to_s.upcase
  when 'DEBUG'   then Moon::Logfmt::Severity::DEBUG
  when 'INFO'    then Moon::Logfmt::Severity::INFO
  when 'WARN'    then Moon::Logfmt::Severity::WARN
  when 'ERROR'   then Moon::Logfmt::Severity::ERROR
  when 'FATAL'   then Moon::Logfmt::Severity::FATAL
  when 'UNKNOWN' then Moon::Logfmt::Severity::UNKNOWN
  else
    raise ArgumentError, "unknown log level #{object}"
  end
end
escape_context_data(data) { |key, value| ... } click to toggle source

Escapes the context values and yields the result.

@param [Hash<[String, Symbol], String>] data @yieldparam [String] key @yieldparam [String] value

# File lib/moon-logfmt/utils.rb, line 16
def self.escape_context_data(data)
  return to_enum :escape_context_data, data unless block_given?
  data.each_pair do |key, value|
    case value
    when Array
      value = value.join(',')
    else
      value = value.to_s
    end
    value = value.dump unless value =~ UNESCAPED_STRING
    yield key.to_s, value
  end
end
loglevel_to_symbol(loglevel) click to toggle source

@param [Integer] loglevel @return [Symbol]

# File lib/moon-logfmt/utils.rb, line 50
def self.loglevel_to_symbol(loglevel)
  case loglevel
  when Moon::Logfmt::Severity::DEBUG   then :debug
  when Moon::Logfmt::Severity::INFO    then :info
  when Moon::Logfmt::Severity::WARN    then :warn
  when Moon::Logfmt::Severity::ERROR   then :error
  when Moon::Logfmt::Severity::FATAL   then :fatal
  when Moon::Logfmt::Severity::UNKNOWN then :unknown
  else
    loglevel.to_s
  end
end
new(*args, &block) click to toggle source

(see Moon::Logfmt::Logger#initialize)

# File lib/moon-logfmt/utils.rb, line 64
def self.new(*args, &block)
  Moon::Logfmt::Logger.new(*args, &block)
end