Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Latest commit

 

History

History
38 lines (26 loc) · 1.45 KB

README.md

File metadata and controls

38 lines (26 loc) · 1.45 KB

Log4j-StaticShutdown

Travis Maven Central MIT License

Provide a ShutdownRegistrationStrategy for Log4j 2 designed to be manually invoked.

Requirements

  • Java and Maven installed

Build your project

Add the dependency in your pom.xml file:

<dependency>
    <groupId>com.djdch.log4j</groupId>
    <artifactId>log4j-staticshutdown</artifactId>
    <version>1.1.0</version>
</dependency>

Add this static initialization block in your Main class:

static {
    System.setProperty("log4j.shutdownCallbackRegistry", "com.djdch.log4j.StaticShutdownCallbackRegistry");
}

WARNING! Even if this works, there is no warranty that it always will, since there is no way to ensure that your Main class will be loaded before Log4j (and it won't work if that doesn't happen). To be safe, you should instead set the system property from the command line when launching your jar.

Then, you can invoke manually the StaticShutdownCallbackRegistry in your shutdown procedure:

StaticShutdownCallbackRegistry.invoke();