Class NtfyJulInstaller

java.lang.Object
io.github.pimak.ntfy.jul.NtfyJulInstaller

public final class NtfyJulInstaller extends Object
Programmatic one-liner install of the ntfy JUL handler from the ambient environment: NtfyJulInstaller.install() early in main attaches a NtfyJulHandler to the root logger when the environment configures ntfy (NTFY_URL/NTFY_TOPIC, -Dntfy.*, or a trusted classpath ntfy.properties — see JulAmbientConfig for the classpath-endpoint opt-in guard), and does nothing otherwise.

To scope alerting to a subtree instead of the whole application, pass that subtree's logger to install(Logger) — the same "attach to the specific logger, not root" scoping the other adapters document. For fully declarative installation (no code at all, e.g. Tomcat's logging.properties) use NtfyJulAutoHandler instead.

The returned handler owns its engine: call uninstall(Logger, NtfyJulHandler) (or removeHandler + NtfyJulHandler.close()) on shutdown to flush the async queue and release the HTTP client. JUL's LogManager shutdown hook also closes attached handlers on normal JVM exit.

  • Method Details

    • install

      public static Optional<NtfyJulHandler> install()
      Installs on the root logger. See install(Logger).
    • install

      public static Optional<NtfyJulHandler> install(Logger logger)
      Resolves the ambient config and, when active and vetted, attaches a started NtfyJulHandler to logger. Empty — with nothing attached — when ntfy is not configured, the classpath-endpoint guard refused, or resolution/construction failed (reported on System.err); like the auto-handler, this entry point never lets an alerting-setup failure propagate into the caller.
    • uninstall

      public static void uninstall(Logger logger, NtfyJulHandler handler)
      Detaches handler from logger and stops its engine.