Package com.tnsai.redaction
Class OncePerPathWarner
java.lang.Object
com.tnsai.redaction.OncePerPathWarner
Logs at most one WARN per path, for problems that would otherwise repeat on every pass, such as
a file a retriever cannot read.
Paths are keyed by their absolute normalized form, so a/./b and /cwd/a/b are
one path; links are not resolved, since the path may not exist. The record of warned paths
belongs to this instance: an owner that is rebuilt starts with a new warner and warns again.
The record grows with the number of distinct paths warned about, which the owner bounds.
The path, the message and the cause's text are passed through the Masker before they
are logged, and the cause's stack trace is not logged, since its messages may name the raw path.
With Masker.noOp() everything is logged as given.
Instances are thread-safe: when several threads warn about the same path at once, exactly one of them logs.
- Since:
- 0.18.6
-
Constructor Summary
ConstructorsConstructorDescriptionOncePerPathWarner(org.slf4j.Logger logger, Masker masker) Creates a warner that logs tologgerand masks withmasker. -
Method Summary
-
Constructor Details
-
OncePerPathWarner
Creates a warner that logs tologgerand masks withmasker.- Parameters:
logger- the logger the WARN lines go to, normally the owner'smasker- the masker applied to everything logged;Masker.noOp()for none- Throws:
NullPointerException- if an argument isnull
-
-
Method Details
-
warn
Logsmessage: path (cause)at WARN the first timepathis seen, and nothing afterwards. The path is logged in its absolute normalized form.- Parameters:
path- the path the warning is aboutmessage- what went wrong, for example"Skipping unreadable file"cause- the failure, ornull; only its class and message are logged- Returns:
trueif a line was logged- Throws:
NullPointerException- ifpathormessageisnull
-