Class: FPM::Scriptable::Log::LogHandler::LogFormatter

Inherits:
Logger::Formatter
  • Object
show all
Defined in:
lib/fpm/scriptable/log.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#colorObject

Returns the value of attribute color.



156
157
158
# File 'lib/fpm/scriptable/log.rb', line 156

def color
  @color
end

Instance Method Details

#call(severity, timestamp, progname, msg) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/fpm/scriptable/log.rb', line 158

def call(severity, timestamp, progname, msg)
  c = get_color severity

  f_severity = sprintf("%-5s", severity.to_s)
  f_time = timestamp.strftime("%Y-%m-%d %H:%M:%S")

  if !@color.nil? && @color
    "\e[#{c}\e[30m[#{f_severity} #{f_time}] #{msg.to_s.strip}\e[0m\n"
  else
    "[#{f_severity} #{f_time}] #{msg.to_s.strip}\n"
  end
end

#get_color(c) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/fpm/scriptable/log.rb', line 171

def get_color(c)
  case c
    when 'DEBUG'
      '46m'
    when 'WARN'
      '43m'
    when 'ERROR'
      '41m'
    when 'FATAL'
      '41m'
    else
      '42m'
  end
end