use of org.apache.logging.log4j.core.util.CloseShieldOutputStream in project logging-log4j2 by apache.
the class ConsoleAppender method getOutputStream.
private static OutputStream getOutputStream(final boolean follow, final boolean direct, final Target target) {
final String enc = Charset.defaultCharset().name();
OutputStream outputStream;
try {
// @formatter:off
outputStream = target == Target.SYSTEM_OUT ? direct ? new FileOutputStream(FileDescriptor.out) : (follow ? new PrintStream(new SystemOutStream(), true, enc) : System.out) : direct ? new FileOutputStream(FileDescriptor.err) : (follow ? new PrintStream(new SystemErrStream(), true, enc) : System.err);
// @formatter:on
outputStream = new CloseShieldOutputStream(outputStream);
} catch (final UnsupportedEncodingException ex) {
// should never happen
throw new IllegalStateException("Unsupported default encoding " + enc, ex);
}
final PropertiesUtil propsUtil = PropertiesUtil.getProperties();
if (!propsUtil.isOsWindows() || propsUtil.getBooleanProperty("log4j.skipJansi") || direct) {
return outputStream;
}
try {
// We type the parameter as a wildcard to avoid a hard reference to Jansi.
final Class<?> clazz = LoaderUtil.loadClass(JANSI_CLASS);
final Constructor<?> constructor = clazz.getConstructor(OutputStream.class);
return new CloseShieldOutputStream((OutputStream) constructor.newInstance(outputStream));
} catch (final ClassNotFoundException cnfe) {
LOGGER.debug("Jansi is not installed, cannot find {}", JANSI_CLASS);
} catch (final NoSuchMethodException nsme) {
LOGGER.warn("{} is missing the proper constructor", JANSI_CLASS);
} catch (final Exception ex) {
LOGGER.warn("Unable to instantiate {}", JANSI_CLASS);
}
return outputStream;
}
use of org.apache.logging.log4j.core.util.CloseShieldOutputStream in project logging-log4j2 by apache.
the class OutputStreamAppender method getManager.
private static OutputStreamManager getManager(final OutputStream target, final boolean follow, final Layout<? extends Serializable> layout) {
final OutputStream os = new CloseShieldOutputStream(target);
final String managerName = target.getClass().getName() + "@" + Integer.toHexString(target.hashCode()) + '.' + follow;
return OutputStreamManager.getManager(managerName, new FactoryData(os, managerName, layout), factory);
}
Aggregations