Class NtfyLogbackInstaller

java.lang.Object
io.github.pimak.ntfy.micronaut.NtfyLogbackInstaller
All Implemented Interfaces:
io.micronaut.context.event.ApplicationEventListener<io.micronaut.context.event.StartupEvent>, EventListener

@Singleton @Requires(classes=ch.qos.logback.classic.LoggerContext.class) public class NtfyLogbackInstaller extends Object implements io.micronaut.context.event.ApplicationEventListener<io.micronaut.context.event.StartupEvent>
Installs the ntfy appender named "ntfy-auto" on the root Logback logger once the Micronaut context has started, and detaches it again on shutdown.

This is the only Logback-aware type in the module. It is a port of the Spring starter's LogbackNtfyBackend, minus the backend abstraction: Micronaut ships Logback (that is what micronaut-logging binds by default) and Log4j2-on-Micronaut is rare enough that a third copy of the starter's two-backend indirection would cost more than it buys. The consequence is spelled out in NtfyClientFactory: only the appender install is Logback-specific, never the client bean.

Installation runs on StartupEvent rather than in a constructor so that whatever the zero-code ntfy-logback Configurator SPI may have attached from environment variables before the context existed is replaced by the Micronaut-bound configuration, exactly once, after the container is up.

The Requires guard keeps this bean out of a context whose classpath has no Logback at all — the bean type could not even be loaded there. Logback being on the classpath is still not proof that it is the bound backend, so install(ILoggerFactory) re-checks the live logger factory and warns rather than throwing.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Name of the appender this module manages on the root logger.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates the installer.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    onApplicationEvent(io.micronaut.context.event.StartupEvent event)
    Installs the appender once the application context has started.
    void
    Stops the installed appender and detaches it from the root logger on context shutdown.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.micronaut.context.event.ApplicationEventListener

    supports
  • Field Details

    • APPENDER_NAME

      public static final String APPENDER_NAME
      Name of the appender this module manages on the root logger. Identical across every ntfy integration, so an install from one path idempotently replaces an install from another.
      See Also:
  • Constructor Details

    • NtfyLogbackInstaller

      public NtfyLogbackInstaller(NtfyConfiguration configuration)
      Creates the installer.
      Parameters:
      configuration - the bound ntfy.* configuration
  • Method Details

    • onApplicationEvent

      public void onApplicationEvent(io.micronaut.context.event.StartupEvent event)
      Installs the appender once the application context has started.
      Specified by:
      onApplicationEvent in interface io.micronaut.context.event.ApplicationEventListener<io.micronaut.context.event.StartupEvent>
      Parameters:
      event - the Micronaut startup event (unused; the trigger is what matters)
    • uninstall

      @PreDestroy public void uninstall()
      Stops the installed appender and detaches it from the root logger on context shutdown. Idempotent and safe when nothing was ever installed, so a context that skipped installation shuts down as quietly as one that never had the module.