Skip to content

Commit

Permalink
cleanup and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki committed Feb 29, 2024
1 parent 23fe698 commit ee4c874
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/redacting_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RedactingLogger < Logger
def initialize(
logdev = $stdout,
shift_age = 0,
shift_size = 1048576,
shift_size = 1_048_576,
redact_patterns: [],
redacted_msg: "[REDACTED]",
use_default_patterns: true,
Expand Down Expand Up @@ -48,13 +48,13 @@ def add(severity, message = nil, progname = nil)

when Array
message = message.map do |m|
m = m.to_s.gsub(pattern, @redacted_msg)
m.to_s.gsub(pattern, @redacted_msg)
end

when Hash
message = message.map do |k, v|
[k, v.to_s.gsub(pattern, @redacted_msg)]
end.to_h
message = message.transform_values do |v|
v.to_s.gsub(pattern, @redacted_msg)
end
end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/lib/redacting_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@
message: { this: "is", "a" => "secret" },
expected_message: { this: "is", "a" => "[REDACTED]" },
},
{
case: "hash of messages more complex",
message: { this: "is", "a" => "super top secret" },
expected_message: { this: "is", "a" => "super top [REDACTED]" },
},
].each do |test|
it "redacts #{test[:case]}" do
expect_any_instance_of(Logger).to receive(:add).with(0, test[:expected_message], test[:expected_progname])
Expand Down

0 comments on commit ee4c874

Please sign in to comment.