class Incline::JsonLogFormatter

A log formatter that writes entries in JSON format (each line is a valid JSON object).

Constants

AUTO_DEBUG_PATTERNS

Regular expressions used to auto-classify any matching message as a debug message.

Private Instance Methods

app_name() click to toggle source
# File lib/incline/json_log_formatter.rb, line 57
def app_name
  if Object.const_defined?(:Rails)
    Rails&.application&.app_name || 'Unknown'
  else
    'Unknown'
  end
end
app_version() click to toggle source
# File lib/incline/json_log_formatter.rb, line 65
def app_version
  if Object.const_defined?(:Rails)
    Rails&.application&.app_version || '0.0.0'
  else
    '0.0.0'
  end
end
debug_skip?() click to toggle source
# File lib/incline/json_log_formatter.rb, line 73
def debug_skip?
  if Object.const_defined?(:Rails)
    (Rails&.logger&.level).to_s.to_i > 0
  else
    false
  end
end
rm_fmt(msg) click to toggle source
# File lib/incline/json_log_formatter.rb, line 81
def rm_fmt(msg)
  msg
      .gsub(/\e\[(\d+;?)*[ABCDEFGHfu]/, "\n")   #   any of the "set cursor position" CSI commands.
      .gsub(/\e\[=?(\d+;?)*[A-Za-z]/,'')        #   \e[#;#;#A or \e[=#;#;#A  basically all the CSI commands except ...
      .gsub(/\e\[(\d+;"[^"]+";?)+p/, '')        #   \e[#;"A"p
      .gsub(/\e[NOc]./,'?')                     #   any of the alternate character set commands.
      .gsub(/\e[P_\]^X][^\e\a]*(\a|(\e\\))/,'') #   any string command
      .gsub(/[\x00\x08\x0B\x0C\x0E-\x1F]/, '')  #   any non-printable characters (notice \x0A (LF) and \x0D (CR) are left as is).
      .gsub("\t", ' ')                          #   turn tabs into spaces.
      .gsub("\r\n", "\n")                       #   all CRLF to LF
      .gsub("\r", "\n")                         #   all CR to LF
      .strip                                    #   remove trailing and leading whitespace
end