Module: FormatLogs::InstanceMethods

Defined in:
lib/format_logs.rb

Instance Method Summary collapse

Instance Method Details

#add_with_formatting(severity, message = nil, progname = nill, &block) ⇒ Object



117
118
119
120
121
# File 'lib/format_logs.rb', line 117

def add_with_formatting(severity, message = nil, progname = nill, &block)
  return if @level > severity
  message = format(severity, (message || (block && block.call) || progname).to_s)
  add_without_formatting(severity, message, progname)
end

#format(severity, message) ⇒ Object



123
124
125
# File 'lib/format_logs.rb', line 123

def format(severity, message)
  "#{self.class.pid}#{self.class.hostname}#{self.class.timestamp}#{self.class.to_color(severity)} - #{trim_leading_whitespace(message)}"
end

#trim_leading_whitespace(m) ⇒ Object



127
128
129
# File 'lib/format_logs.rb', line 127

def trim_leading_whitespace(m)
  self.class.trim_leading_whitespace? ? m.gsub(/^\s*/,'') : m
end