class NRSER::Log::Formatters::Color
Definitions
¶ ↑
Constants
- ANSI_ESC_DARK_GRAY
ANSI escape sequence to start “Dark Gray” color.
@return [String]
Public Class Methods
# File lib/nrser/log/formatters/color.rb, line 85 def self.colorize string, type ap_formatter.colorize string, type end
@todo Document default_color_map
method.
@return [SemanticLogger::Formatters::Color::ColorMap]
# File lib/nrser/log/formatters/color.rb, line 56 def self.default_color_map SemanticLogger::Formatters::Color::ColorMap.new( debug: SemanticLogger::AnsiColors::MAGENTA, trace: ANSI_ESC_DARK_GRAY, warn: SemanticLogger::AnsiColors::YELLOW, ) end
Instantiate a new `ColorFormatter`.
# File lib/nrser/log/formatters/color.rb, line 98 def initialize ap: {multiline: true }, # raw: true}, color_map: self.class.default_color_map, time_format: ::SemanticLogger::Formatters::Base::TIME_FORMAT, log_host: false, log_application: false super ap: ap, color_map: color_map, time_format: time_format, log_host: log_host, log_application: log_application end
Private Class Methods
A HACK to get an {AwesomePrint::Formatter} to {AwesomePrint::Formatter#colorize} with by constructing a new {AwesomePrint::Inspector} and fishing it out of the `@formatter` instance variable.
This is only done once and the value is cached in a class variable.
@see .colorize
@private @return [AwesomePrint::Formatter]
# File lib/nrser/log/formatters/color.rb, line 77 def self.ap_formatter @@ap_formatter ||= \ AwesomePrint::Inspector.new.instance_variable_get :@formatter end
Public Instance Methods
Create the log entry text. Overridden to customize appearance - generally reduce amount of info and put payload on it's own line.
We need to replace two super functions, the first being [SemanticLogger::Formatters::Color#call][]:
def call(log, logger) self.color = color_map[log.level] super(log, logger) end
[SemanticLogger::Formatters::Color#call]: github.com/rocketjob/semantic_logger/blob/v4.2.0/lib/semantic_logger/formatters/color.rb#L98
which doesn't do all too much, and the next being it's super-method, [SemanticLogger::Formatters::Default#call][]:
# Default text log format # Generates logs of the form: # 2011-07-19 14:36:15.660235 D [1149:ScriptThreadProcess] Rails -- Hello World def call(log, logger) self.log = log self.logger = logger [time, level, process_info, tags, named_tags, duration, name, message, payload, exception].compact.join(' ') end
[SemanticLogger::Formatters::Default#call]: github.com/rocketjob/semantic_logger/blob/v4.2.0/lib/semantic_logger/formatters/default.rb#L64
which does most the real assembly.
@param [SemanticLogger::Log] log
The log entry to format. See [SemanticLogger::Log](https://github.com/rocketjob/semantic_logger/blob/v4.2.0/lib/semantic_logger/log.rb)
@param [SemanticLogger::Logger] logger
The logger doing the logging (pretty sure, haven't checked). See [SemanticLogger::Logger](https://github.com/rocketjob/semantic_logger/blob/v4.2.0/lib/semantic_logger/logger.rb)
@return [return_type]
@todo Document return value.
# File lib/nrser/log/formatters/color.rb, line 176 def call log, logger # SemanticLogger::Formatters::Color code self.color = color_map[log.level] # SemanticLogger::Formatters::Default code self.log = log self.logger = logger render_log end
Upcase the log level.
@return [String]
# File lib/nrser/log/formatters/color.rb, line 123 def level "#{ color }#{ log.level.upcase }#{ color_map.clear }" end
# File lib/nrser/log/formatters/color.rb, line 128 def time "#{ color }#{ super() }#{ color_map.clear }" end