Class: Liri::Common::LogFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/common/log.rb

Constant Summary collapse

DATETIME_FORMAT =
"%d-%m-%Y %H:%M"
SEVERITY_COLORS =
ColorizeText::COLORS

Class Method Summary collapse

Class Method Details

.colorize(type) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/common/log.rb', line 137

def colorize(type)
  proc do |severity, datetime, progname, msg|
    formatted_date = datetime.strftime(DATETIME_FORMAT)
    severity_abb_block = "#{severity.slice(0)}"
    date_block = "[#{formatted_date}##{Process.pid}]"
    severity_block = "#{severity} -- :"
    msg_block = "#{msg}\n"

    case type
    when 'severity' then
      info_block = "#{colorize_according_severity(severity, severity_abb_block)} #{date_block} #{colorize_according_severity(severity, severity_block)}"
    when 'severity_date' then
      info_block = colorize_according_severity(severity, "#{severity_abb_block} #{date_block} #{severity_block}")
    when 'full' then
      info_block = colorize_according_severity(severity, "#{severity_abb_block} #{date_block} #{severity_block}")
      msg_block = colorize_according_severity(severity, msg_block)
    else
      info_block = "#{severity_abb_block} #{date_block} #{severity_block}"
    end

    "#{info_block} #{msg_block}"
  end
end