module FormatLogs::ClassMethods

Public Instance Methods

color(s, color) click to toggle source
# File lib/format_logs.rb, line 109
def color(s, color)
  use_color? ? "\033[#{color}#{s}\033[0m" : s
end
debug_s() click to toggle source
# File lib/format_logs.rb, line 85
def debug_s
  "DEBUG "
end
default_settings() click to toggle source
# File lib/format_logs.rb, line 28
def default_settings
  {
    :time_format => '%Y-%m-%d %H:%M:%S %z',
    :show_pid => true,
    :show_host => true,
    :show_time => true,
    :trim_leading_whitespace => true
  }
end
error_s() click to toggle source
# File lib/format_logs.rb, line 101
def error_s
  @error_s ||= color("ERROR ", '31m')
end
fatal_s() click to toggle source
# File lib/format_logs.rb, line 105
def fatal_s
  @fatal_s ||= color("FATAL ", '1;30;41m')
end
flush_cached_settings!() click to toggle source
# File lib/format_logs.rb, line 24
def flush_cached_settings!
  [@time_format, @show_time, @show_pid, @show_host, @trim_leading_whitespace].each {|a| a = nil}
end
hostname() click to toggle source
# File lib/format_logs.rb, line 70
def hostname
  @hostname ||= "#{`hostname -s`.strip rescue ''} - " if show_host?
end
info_s() click to toggle source
# File lib/format_logs.rb, line 93
def info_s
  @info_s ||= color("INFO  ", '32m')
end
pid() click to toggle source
# File lib/format_logs.rb, line 66
def pid
  "#{$$} - " if show_pid?
end
settings() click to toggle source
# File lib/format_logs.rb, line 15
def settings
  @settings ||= default_settings
end
settings=(new_settings) click to toggle source
# File lib/format_logs.rb, line 19
def settings=(new_settings)
  @settings = default_settings + new_settings
  flush_attributes!
end
show_host?() click to toggle source
# File lib/format_logs.rb, line 58
def show_host?
  @show_host ||= settings[:show_host]
end
show_pid?() click to toggle source
# File lib/format_logs.rb, line 50
def show_pid?
  @show_pid ||= settings[:show_pid]
end
show_time?() click to toggle source
# File lib/format_logs.rb, line 42
def show_time?
  @show_time ||= settings[:show_time]
end
time_format() click to toggle source
# File lib/format_logs.rb, line 38
def time_format
  @time_format ||= settings[:time_format]
end
timestamp() click to toggle source
# File lib/format_logs.rb, line 62
def timestamp
  "#{Time.now.utc.strftime(time_format)} - " if show_time?
end
to_color(severity) click to toggle source
# File lib/format_logs.rb, line 74
def to_color(severity)
  return case severity
    when ActiveSupport::BufferedLogger::INFO  then info_s
    when ActiveSupport::BufferedLogger::WARN  then warn_s
    when ActiveSupport::BufferedLogger::ERROR then error_s
    when ActiveSupport::BufferedLogger::FATAL then fatal_s
    when ActiveSupport::BufferedLogger::DEBUG then debug_s
  else unknown_s
  end
end
trim_leading_whitespace?() click to toggle source
# File lib/format_logs.rb, line 54
def trim_leading_whitespace?
  @trim_leading_whitespace ||= settings[:trim_leading_whitespace]
end
unknown_S() click to toggle source
# File lib/format_logs.rb, line 89
def unknown_S
  "UNKNOWN"
end
use_color?() click to toggle source
# File lib/format_logs.rb, line 46
def use_color?
  @use_color ||= (Rails.configuration.colorize_logging != false)
end
warn_s() click to toggle source
# File lib/format_logs.rb, line 97
def warn_s
  @warn_s ||= color("WARN  ", '33m')
end