class MongoBeautifulLogger
Public Class Methods
new(*targets)
click to toggle source
# File lib/mongo_beautiful_logger.rb, line 9 def initialize(*targets) nil_targets_error if targets.empty? @targets = targets.map do |t| logger = Logger.new(t) format! logger logger end end
Private Instance Methods
color(text, color, bold = false)
click to toggle source
set color based one the defined constants. If a third option is set to true
, the string will be made bold. CLEAR to the is automatically appended to the string for reset
# File lib/mongo_beautiful_logger.rb, line 73 def color(text, color, bold = false) bold = bold ? BOLD : "" "#{bold}#{color}#{text}#{CLEAR}" end
colorize_log(msg)
click to toggle source
colorize messages that are specified in ACTIONS constant
# File lib/mongo_beautiful_logger.rb, line 55 def colorize_log(msg) ACTIONS.each { |a| msg = color(msg, a[:color]) if msg.downcase.include?(a[:match]) } return msg end
format!(logger)
click to toggle source
default logger format, removes prompt of: +d, [2020-06-20 14:02:29#17329] INFO – MONGODB:+
# File lib/mongo_beautiful_logger.rb, line 26 def format!(logger) logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}" } end
format_log(msg)
click to toggle source
takes a log message and returns the message formatted
# File lib/mongo_beautiful_logger.rb, line 48 def format_log(msg) msg = colorize_log(msg) msg = remove_prefix(msg) "#{msg}\n" end
method_missing(method, *args, &block)
click to toggle source
send all other methods back to logger instance
# File lib/mongo_beautiful_logger.rb, line 66 def method_missing(method, *args, &block) @targets.each { |t| t.send(method, *args, &block) } end
nil_targets_error()
click to toggle source
# File lib/mongo_beautiful_logger.rb, line 20 def nil_targets_error raise ArgumentError.new "wrong number of arguments (given 0, expected at least 1)" end
remove_prefix(msg)
click to toggle source
remove prefix defined in PREFIX_REGEX
from message
# File lib/mongo_beautiful_logger.rb, line 61 def remove_prefix(msg) msg.sub(PREFIX_REGEX, "|") end
unnecessary?(msg)
click to toggle source
checks if a message if a message is included in the UNNECESSARY
array constant
# File lib/mongo_beautiful_logger.rb, line 43 def unnecessary?(msg) UNNECESSARY.any? { |s| msg.downcase.include? s } end