Class: Sapience::Formatters::Color
- Defined in:
- lib/sapience/formatters/color.rb
Instance Attribute Summary
Attributes inherited from Base
#log_application, #log_host, #precision, #time_format
Instance Method Summary collapse
-
#call(log, _logger) ⇒ Object
Adds color to the default log formatter Example: Sapience.add_appender(:stream, io: $stdout, formatter: :color).
-
#initialize(options = {}) ⇒ Color
constructor
Parameters: ap: Any valid AwesomePrint option for rendering data.
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Color
Parameters:
ap: Any valid AwesomePrint option for rendering data.
These options can also be changed be creating a `~/.aprc` file.
See: https://github.com/michaeldv/awesome_print
Note: The option :multiline is set to false if not supplied.
Note: Has no effect if Awesome Print is not installed.
18 19 20 21 22 |
# File 'lib/sapience/formatters/color.rb', line 18 def initialize( = {}) = .dup @ai_options = .delete(:ap) || { multiline: false } super() end |
Instance Method Details
#call(log, _logger) ⇒ Object
Adds color to the default log formatter Example:
Sapience.add_appender(:stream, io: $stdout, formatter: :color)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sapience/formatters/color.rb', line 27 def call(log, _logger) # rubocop:disable AbcSize, PerceivedComplexity, CyclomaticComplexity colors = Sapience::AnsiColors level_color = colors::LEVEL_MAP[log.level] = time_format.nil? ? "" : "#{format_time(log.time)} " # Header with date, time, log level and process info += "#{level_color}#{log.level_to_s}#{colors::CLEAR} [#{log.process_info}]" # Tags += " " + log..collect { |tag| "[#{level_color}#{tag}#{colors::CLEAR}]" }.join(" ") if log. && !log..empty? # rubocop:disable LineLength # Duration += " (#{colors::BOLD}#{log.duration_human}#{colors::CLEAR})" if log.duration # Class / app name += " #{level_color}#{log.name}#{colors::CLEAR}" # Log message += " -- #{log.}" if log. # Payload: Colorize the payload if the AwesomePrint gem is loaded if log.payload? payload = log.payload += " -- " += if defined?(AwesomePrint) && payload.respond_to?(:ai) payload.ai(@ai_options) rescue payload.inspect # rubocop:disable RescueModifier else payload.inspect end end # Exceptions if log.exception += " -- Exception: #{colors::BOLD}#{log.exception.class}: #{log.exception.}#{colors::CLEAR}\n" += log.backtrace_to_s end end |