Skip to content

Commit

Permalink
make redact public method on logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ttstarck committed Dec 8, 2023
1 parent c3698e2 commit 9317acb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/contextual_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def normalize_message(message)
module LoggerMixin
include Context

delegate :register_secret, :register_secret_regex, to: :redactor
delegate :register_secret, :register_secret_regex, :redact, to: :redactor

def global_context
@global_context ||= Context::EMPTY_CONTEXT
Expand Down
2 changes: 2 additions & 0 deletions lib/contextual_logger/redactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def register_secret_regex(regex)
end
end

# @param log_line [String]
# @return [String]
def redact(log_line)
if redaction_regex
log_line.gsub(redaction_regex, '<redacted>')
Expand Down
1 change: 1 addition & 0 deletions spec/lib/contextual_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def expect_log_line_to_be_written(log_line)
it { is_expected.to respond_to(:with_context) }
it { is_expected.to respond_to(:current_context) }
it { is_expected.to respond_to(:current_context_for_thread) } # for backward-compatibility
it { is_expected.to respond_to(:redact) }

context 'with logger writing to log_stream' do
let(:log_stream) { StringIO.new }
Expand Down

0 comments on commit 9317acb

Please sign in to comment.