Class: Beautiful::Log::Formatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- Beautiful::Log::Formatter
- Includes:
- Modules::CodeRangeExtractable, Modules::CompleteLogFormatter, Modules::ErrorFormattable, Modules::PathOmmittable, Modules::RenderLogFoematter, Modules::Stylable
- Defined in:
- lib/beautiful/log/formatter.rb
Constant Summary collapse
- DEFAULT_STATUS_CODE_STYLES =
{ (1..3) => [:green, :bold], 'other' => [:red, :bold] }.freeze
- DEFAULT_SEVERITY_STYLES =
{ FATAL: [:red, :swap], ERROR: :red, WARN: :light_red }.freeze
Instance Attribute Summary collapse
-
#allow_path ⇒ Object
readonly
Returns the value of attribute allow_path.
-
#backtrace_ignore_paths ⇒ Object
readonly
Returns the value of attribute backtrace_ignore_paths.
-
#backtrace_styles ⇒ Object
readonly
Returns the value of attribute backtrace_styles.
-
#error_file_path_styles ⇒ Object
readonly
Returns the value of attribute error_file_path_styles.
-
#highlighted_line_range ⇒ Object
readonly
Returns the value of attribute highlighted_line_range.
-
#highlighted_line_styles ⇒ Object
readonly
Returns the value of attribute highlighted_line_styles.
-
#ignore_paths ⇒ Object
readonly
Returns the value of attribute ignore_paths.
-
#only_project_code ⇒ Object
readonly
Returns the value of attribute only_project_code.
-
#severity_styles ⇒ Object
readonly
Returns the value of attribute severity_styles.
-
#status_code_styles ⇒ Object
readonly
Returns the value of attribute status_code_styles.
Instance Method Summary collapse
- #call(severity, timestamp, _progname, message) ⇒ Object
-
#initialize(only_project_code: true, shrink_bundle_path: true, backtrace_ignore_paths: [], highlighted_line_range: 3, highlighted_line_styles: :cyan, backtrace_styles: :light_red, error_file_path_styles: :red, status_code_styles: {}, severity_styles: {}, occurence_line: :light_blue) ⇒ Formatter
constructor
rubocop: disable Metrics/AbcSize, Style/ParameterLists, Style/MethodLength.
Constructor Details
#initialize(only_project_code: true, shrink_bundle_path: true, backtrace_ignore_paths: [], highlighted_line_range: 3, highlighted_line_styles: :cyan, backtrace_styles: :light_red, error_file_path_styles: :red, status_code_styles: {}, severity_styles: {}, occurence_line: :light_blue) ⇒ Formatter
rubocop: disable Metrics/AbcSize, Style/ParameterLists, Style/MethodLength
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/beautiful/log/formatter.rb', line 23 def initialize( only_project_code: true, shrink_bundle_path: true, backtrace_ignore_paths: [], highlighted_line_range: 3, highlighted_line_styles: :cyan, backtrace_styles: :light_red, error_file_path_styles: :red, status_code_styles: {}, severity_styles: {}, occurence_line: :light_blue ) @only_project_code = only_project_code @shrink_bundle_path = shrink_bundle_path @ignore_paths = backtrace_ignore_paths.map do |path| Regexp.new "#{Rails.root}/#{path}" end << Regexp.new(bundle_path) @allow_path = Regexp.new bundle_install_path @backtrace_ignore_paths = backtrace_ignore_paths @highlighted_line_range = highlighted_line_range @highlighted_line_styles = highlighted_line_styles @backtrace_styles = backtrace_styles @error_file_path_styles = error_file_path_styles @status_code_styles = DEFAULT_STATUS_CODE_STYLES.merge(status_code_styles).with_indifferent_access @severity_styles = DEFAULT_SEVERITY_STYLES.merge(severity_styles).with_indifferent_access @occurence_line = occurence_line end |
Instance Attribute Details
#allow_path ⇒ Object (readonly)
Returns the value of attribute allow_path.
9 10 11 |
# File 'lib/beautiful/log/formatter.rb', line 9 def allow_path @allow_path end |
#backtrace_ignore_paths ⇒ Object (readonly)
Returns the value of attribute backtrace_ignore_paths.
9 10 11 |
# File 'lib/beautiful/log/formatter.rb', line 9 def backtrace_ignore_paths @backtrace_ignore_paths end |
#backtrace_styles ⇒ Object (readonly)
Returns the value of attribute backtrace_styles.
9 10 11 |
# File 'lib/beautiful/log/formatter.rb', line 9 def backtrace_styles @backtrace_styles end |
#error_file_path_styles ⇒ Object (readonly)
Returns the value of attribute error_file_path_styles.
9 10 11 |
# File 'lib/beautiful/log/formatter.rb', line 9 def error_file_path_styles @error_file_path_styles end |
#highlighted_line_range ⇒ Object (readonly)
Returns the value of attribute highlighted_line_range.
9 10 11 |
# File 'lib/beautiful/log/formatter.rb', line 9 def highlighted_line_range @highlighted_line_range end |
#highlighted_line_styles ⇒ Object (readonly)
Returns the value of attribute highlighted_line_styles.
9 10 11 |
# File 'lib/beautiful/log/formatter.rb', line 9 def highlighted_line_styles @highlighted_line_styles end |
#ignore_paths ⇒ Object (readonly)
Returns the value of attribute ignore_paths.
9 10 11 |
# File 'lib/beautiful/log/formatter.rb', line 9 def ignore_paths @ignore_paths end |
#only_project_code ⇒ Object (readonly)
Returns the value of attribute only_project_code.
9 10 11 |
# File 'lib/beautiful/log/formatter.rb', line 9 def only_project_code @only_project_code end |
#severity_styles ⇒ Object (readonly)
Returns the value of attribute severity_styles.
9 10 11 |
# File 'lib/beautiful/log/formatter.rb', line 9 def severity_styles @severity_styles end |
#status_code_styles ⇒ Object (readonly)
Returns the value of attribute status_code_styles.
9 10 11 |
# File 'lib/beautiful/log/formatter.rb', line 9 def status_code_styles @status_code_styles end |
Instance Method Details
#call(severity, timestamp, _progname, message) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/beautiful/log/formatter.rb', line 51 def call(severity, , _progname, ) problem_code = highlighted_code() if .is_a?(Exception) header = (, severity, caller) = "#{header} -- : #{(, header.uncolorize.length + 6)}\n" = "#{}\n#{problem_code}" if problem_code.present? = "\n#{}\n" if %w(FATAL ERROR).include?(severity) end |