slog icon indicating copy to clipboard operation
slog copied to clipboard

Feature Request: Log Masking

Open dgoetsch opened this issue 3 years ago • 1 comments

I'm using slog in a new production microservice. We make some API calls, and I want to be able to configure log masking for sensitive fields. For example, I want to mask out certain fields in the request/response bodies or certain headers by name. I don't see this supported in any of the modules I've checked, I believe this is a new feature.

Currently for a work around, I'm just doing an in memory map before sending to the logger, however I would prefer the logger handled this so I wouldn't have to write a bunch of custom code to iterate over collections. I also use the slog-json crate.

Any ideas or recommendations?

dgoetsch avatar Mar 08 '21 21:03 dgoetsch

You can just implement a Drain wrapping other Drains and rewritting things. It's a fairly common pattern. See https://docs.rs/slog/2.7.0/slog/trait.Drain.html#tymethod.log is a good starting point.

Another approach would be to write your own macros debug and alikes and in it do the heavy lifting. These would have potential to have faster runtime perf.

dpc avatar Mar 09 '21 01:03 dpc