class Photish::Log::Formatter::LogLine

Constants

SEV

Public Class Methods

new(color, severity, datetime, progname, msg) click to toggle source
# File lib/photish/log/formatter.rb, line 13
def initialize(color, severity, datetime, progname, msg)
  @color = color
  @severity = severity
  @datetime = datetime
  @progname = progname
  @msg = msg
end

Public Instance Methods

format() click to toggle source
# File lib/photish/log/formatter.rb, line 21
def format
  line = ''
  line << timestamp
  line << pid
  line << severity
  line << progname
  line << msg
  line
end

Private Instance Methods

color?() click to toggle source
# File lib/photish/log/formatter.rb, line 41
def color?
  !!@color
end
msg() click to toggle source
# File lib/photish/log/formatter.rb, line 70
def msg
  str = ': '
  if @msg.kind_of?(Exception)
    str << "#{@msg.class} \"#{@msg.message}\"\n"
    str << "#{@msg.backtrace.join("\n")}"
  else
    str << "#{@msg}"
  end
  str << "\n"
  str = str.colorize(:light_blue) if color?
  str
end
pid() click to toggle source
# File lib/photish/log/formatter.rb, line 58
def pid
  str = "[#{Process.pid.to_s.rjust(5, '0')}]"
  str = str.colorize(:light_magenta) if color?
  str
end
progname() click to toggle source
# File lib/photish/log/formatter.rb, line 64
def progname
  str = "#{@progname}"
  str = str.colorize(:magenta) if color?
  str
end
severity() click to toggle source
# File lib/photish/log/formatter.rb, line 45
def severity
  str = "#{@severity}"
  str = str.colorize(color: SEV[@severity].first,
                     background: SEV[@severity].last) if color?
  " #{str} "
end
timestamp() click to toggle source
# File lib/photish/log/formatter.rb, line 52
def timestamp
  str = "[#{@datetime.strftime("%Y-%m-%dT%H:%M:%S.%L")}]"
  str = str.colorize(:cyan) if color?
  str
end