下面列出了怎么用org.apache.logging.log4j.core.util.ShutdownCallbackRegistry的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Constructs a Log4jContextFactory using the provided ContextSelector and ShutdownRegistrationStrategy.
*
* @param selector the selector to use
* @param shutdownCallbackRegistry the ShutdownRegistrationStrategy to use
* @since 2.1
*/
public Log4jContextFactory(final ContextSelector selector,
final ShutdownCallbackRegistry shutdownCallbackRegistry) {
this.selector = Objects.requireNonNull(selector, "No ContextSelector provided");
this.shutdownCallbackRegistry = Objects.requireNonNull(shutdownCallbackRegistry, "No ShutdownCallbackRegistry provided");
LOGGER.debug("Using ShutdownCallbackRegistry {}", shutdownCallbackRegistry.getClass());
initializeShutdownCallbackRegistry();
}
private static ShutdownCallbackRegistry createShutdownCallbackRegistry() {
try {
final ShutdownCallbackRegistry registry = Loader.newCheckedInstanceOfProperty(
ShutdownCallbackRegistry.SHUTDOWN_CALLBACK_REGISTRY, ShutdownCallbackRegistry.class
);
if (registry != null) {
return registry;
}
} catch (final Exception e) {
LOGGER.error("Unable to create custom ShutdownCallbackRegistry. Falling back to default.", e);
}
return new DefaultShutdownCallbackRegistry();
}
public Log4J2LoggerFactory() {
// map message factory to simple, since default message factory is reusable - and will remap our object to string message, without access to object variant
System.setProperty("log4j2.messageFactory", "org.apache.logging.log4j.message.SimpleMessageFactory");
System.setProperty(ShutdownCallbackRegistry.SHUTDOWN_HOOK_ENABLED, "false");
myLoggerContext = init();
}
/**
* Constructs a Log4jContextFactory using the ContextSelector from {@link Constants#LOG4J_CONTEXT_SELECTOR}
* and the provided ShutdownRegistrationStrategy.
*
* @param shutdownCallbackRegistry the ShutdownRegistrationStrategy to use
* @since 2.1
*/
public Log4jContextFactory(final ShutdownCallbackRegistry shutdownCallbackRegistry) {
this(createContextSelector(), shutdownCallbackRegistry);
}
/**
* Returns the ShutdownCallbackRegistry
*
* @return the ShutdownCallbackRegistry
* @since 2.4
*/
public ShutdownCallbackRegistry getShutdownCallbackRegistry() {
return shutdownCallbackRegistry;
}