Class: Scrubber::LogFormatter
- Inherits:
-
Object
- Object
- Scrubber::LogFormatter
- Defined in:
- lib/scrubber/log_formatter.rb,
sig/scrubber_rb.rbs
Overview
Wraps a Logger formatter and redacts its output.
Instance Attribute Summary collapse
-
#scrubber ⇒ Instance
readonly
Returns the value of attribute scrubber.
Class Method Summary collapse
Instance Method Summary collapse
- #call(severity, time, progname, msg) ⇒ Object
-
#initialize(formatter = nil, scrubber: nil, **options) ⇒ LogFormatter
constructor
A new instance of LogFormatter.
Constructor Details
#initialize(formatter = nil, scrubber: nil, **options) ⇒ LogFormatter
Returns a new instance of LogFormatter.
23 24 25 26 |
# File 'lib/scrubber/log_formatter.rb', line 23 def initialize(formatter = nil, scrubber: nil, **) @formatter = formatter || self.class.default_formatter @scrubber = scrubber || Scrubber.new(**) end |
Instance Attribute Details
#scrubber ⇒ Instance (readonly)
Returns the value of attribute scrubber.
17 18 19 |
# File 'lib/scrubber/log_formatter.rb', line 17 def scrubber @scrubber end |
Class Method Details
.default_formatter ⇒ Object
35 36 37 38 |
# File 'lib/scrubber/log_formatter.rb', line 35 def self.default_formatter require "logger" ::Logger::Formatter.new end |
Instance Method Details
#call(severity, time, progname, msg) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/scrubber/log_formatter.rb', line 28 def call(severity, time, progname, msg) formatted = @formatter.call(severity, time, progname, msg) return formatted unless formatted.is_a?(String) @scrubber.scrub(formatted) end |