Class OncePerPathWarner

java.lang.Object
com.tnsai.redaction.OncePerPathWarner

public final class OncePerPathWarner extends Object
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 Details

    • OncePerPathWarner

      public OncePerPathWarner(org.slf4j.Logger logger, Masker masker)
      Creates a warner that logs to logger and masks with masker.
      Parameters:
      logger - the logger the WARN lines go to, normally the owner's
      masker - the masker applied to everything logged; Masker.noOp() for none
      Throws:
      NullPointerException - if an argument is null
  • Method Details

    • warn

      public boolean warn(Path path, String message, Throwable cause)
      Logs message: path (cause) at WARN the first time path is seen, and nothing afterwards. The path is logged in its absolute normalized form.
      Parameters:
      path - the path the warning is about
      message - what went wrong, for example "Skipping unreadable file"
      cause - the failure, or null; only its class and message are logged
      Returns:
      true if a line was logged
      Throws:
      NullPointerException - if path or message is null