palantir / safe-logging

Interfaces and utilities for safe log messages
Apache License 2.0
15 stars 20 forks source link

Provide alternate UnsafeArg factory that takes Supplier<T> #8

Open gracew opened 7 years ago

gracew commented 7 years ago

We may want to log an object with a sensitive field that should not be logged even under unsafe parameters (e.g. user credentials).

log.info("message", UnsafeArg.of("name", unsafeValue))

Rather than relying on the toString() implementation to remove the offending value, users should instead be able to write:

log.info("message", UnsafeArg.of("name", () -> removeUserCredentials(unsafeValue))

This mostly applies to UnsafeArg, but maybe we could also add to SafeArg for consistency. The more probable scenario with SafeArg is a field that is too large/expensive to log.

schlosna commented 7 years ago

+1 to also adding to SafeArg for lazy evaluation for perf concerns as I've seen a few internally. Would also allow cleansing for safe logging portion of object.