Class NtfyLogbackInstaller
- All Implemented Interfaces:
io.micronaut.context.event.ApplicationEventListener<io.micronaut.context.event.StartupEvent>,EventListener
"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
FieldsModifier and TypeFieldDescriptionstatic final StringName of the appender this module manages on the root logger. -
Constructor Summary
ConstructorsConstructorDescriptionNtfyLogbackInstaller(NtfyConfiguration configuration) Creates the installer. -
Method Summary
Modifier and TypeMethodDescriptionvoidonApplicationEvent(io.micronaut.context.event.StartupEvent event) Installs the appender once the application context has started.voidStops 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, waitMethods inherited from interface io.micronaut.context.event.ApplicationEventListener
supports
-
Field Details
-
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
Creates the installer.- Parameters:
configuration- the boundntfy.*configuration
-
-
Method Details
-
onApplicationEvent
public void onApplicationEvent(io.micronaut.context.event.StartupEvent event) Installs the appender once the application context has started.- Specified by:
onApplicationEventin interfaceio.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.
-