use of org.slf4j.ILoggerFactory in project pulsar by yahoo.
the class MessagingServiceShutdownHook method immediateFlushBufferedLogs.
public static void immediateFlushBufferedLogs() {
ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
if (loggerFactory.getClass().getName().equals(LogbackLoggerContextClassName)) {
// Use reflection to force the flush on the logger
try {
Class<?> logbackLoggerContextClass = Class.forName(LogbackLoggerContextClassName);
Method stop = logbackLoggerContextClass.getMethod("stop");
stop.invoke(loggerFactory);
} catch (Throwable t) {
LOG.info("Failed to flush logs", t);
}
}
}
use of org.slf4j.ILoggerFactory in project cdap by caskdata.
the class ProgramRunners method createLogbackJar.
/**
* Creates a jar that contains a logback.xml configured for the current process
*
* @param targetLocation the jar location
* @return the {@link Location} where the jar was created to or {@code null} if "logback.xml" is not found
* in the current ClassLoader.
* @throws IOException if failed in reading the logback xml or writing out the jar
*/
@Nullable
public static Location createLogbackJar(Location targetLocation) throws IOException {
ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
if (!(loggerFactory instanceof Context)) {
return null;
}
URL logbackURL = ConfigurationWatchListUtil.getMainWatchURL((Context) loggerFactory);
if (logbackURL == null) {
return null;
}
try (InputStream input = logbackURL.openStream()) {
try (JarOutputStream output = new JarOutputStream(targetLocation.getOutputStream())) {
output.putNextEntry(new JarEntry("logback.xml"));
ByteStreams.copy(input, output);
}
return targetLocation;
}
}
Aggregations