use of org.apache.log4j.bridge.AppenderWrapper in project logging-log4j2 by apache.
the class PropertiesConfiguration method buildAppender.
private Appender buildAppender(final String appenderName, final String className, final String prefix, final String layoutPrefix, final String filterPrefix, final Properties props) {
final Appender appender = newInstanceOf(className, "Appender");
if (appender == null) {
return null;
}
appender.setName(appenderName);
appender.setLayout(parseLayout(layoutPrefix, appenderName, props));
final String errorHandlerPrefix = prefix + ".errorhandler";
final String errorHandlerClass = OptionConverter.findAndSubst(errorHandlerPrefix, props);
if (errorHandlerClass != null) {
final ErrorHandler eh = parseErrorHandler(props, errorHandlerPrefix, errorHandlerClass, appender);
if (eh != null) {
appender.setErrorHandler(eh);
}
}
appender.addFilter(parseAppenderFilters(props, filterPrefix, appenderName));
final String[] keys = new String[] { layoutPrefix };
addProperties(appender, keys, props, prefix);
if (appender instanceof AppenderWrapper) {
addAppender(((AppenderWrapper) appender).getAppender());
} else {
addAppender(new AppenderAdapter(appender).getAdapter());
}
registry.put(appenderName, appender);
return appender;
}
use of org.apache.log4j.bridge.AppenderWrapper in project logging-log4j2 by apache.
the class RewriteAppenderBuilder method createAppender.
private <T extends Log4j1Configuration> Appender createAppender(String name, String level, String[] appenderRefs, RewritePolicy policy, Filter filter, T configuration) {
org.apache.logging.log4j.Level logLevel = OptionConverter.convertLevel(level, org.apache.logging.log4j.Level.TRACE);
AppenderRef[] refs = new AppenderRef[appenderRefs.length];
int index = 0;
for (String appenderRef : appenderRefs) {
refs[index++] = AppenderRef.createAppenderRef(appenderRef, logLevel, null);
}
org.apache.logging.log4j.core.Filter rewriteFilter = buildFilters(level, filter);
org.apache.logging.log4j.core.appender.rewrite.RewritePolicy rewritePolicy;
if (policy instanceof RewritePolicyWrapper) {
rewritePolicy = ((RewritePolicyWrapper) policy).getPolicy();
} else {
rewritePolicy = new RewritePolicyAdapter(policy);
}
return new AppenderWrapper(RewriteAppender.createAppender(name, true, refs, configuration, rewritePolicy, rewriteFilter));
}
use of org.apache.log4j.bridge.AppenderWrapper in project logging-log4j2 by apache.
the class DailyRollingFileAppenderBuilder method createAppender.
private <T extends Log4j1Configuration> Appender createAppender(final String name, final Layout layout, final Filter filter, final String fileName, final boolean append, boolean immediateFlush, final String level, final boolean bufferedIo, final int bufferSize, final T configuration) {
org.apache.logging.log4j.core.Layout<?> fileLayout = null;
if (bufferedIo) {
immediateFlush = true;
}
if (layout instanceof LayoutWrapper) {
fileLayout = ((LayoutWrapper) layout).getLayout();
} else if (layout != null) {
fileLayout = new LayoutAdapter(layout);
}
org.apache.logging.log4j.core.Filter fileFilter = buildFilters(level, filter);
if (fileName == null) {
LOGGER.warn("Unable to create File Appender, no file name provided");
return null;
}
String filePattern = fileName + "%d{.yyyy-MM-dd}";
TriggeringPolicy timePolicy = TimeBasedTriggeringPolicy.newBuilder().setModulate(true).build();
TriggeringPolicy policy = CompositeTriggeringPolicy.createPolicy(timePolicy);
RolloverStrategy strategy = DefaultRolloverStrategy.newBuilder().setConfig(configuration).setMax(Integer.toString(Integer.MAX_VALUE)).build();
return new AppenderWrapper(RollingFileAppender.newBuilder().setName(name).setConfiguration(configuration).setLayout(fileLayout).setFilter(fileFilter).setFileName(fileName).setBufferSize(bufferSize).setImmediateFlush(immediateFlush).setFilePattern(filePattern).setPolicy(policy).setStrategy(strategy).build());
}
use of org.apache.log4j.bridge.AppenderWrapper in project logging-log4j2 by apache.
the class PropertiesConfiguration method parseAppender.
public Appender parseAppender(final Properties props, final String appenderName) {
Appender appender = registry.get(appenderName);
if ((appender != null)) {
LOGGER.debug("Appender \"" + appenderName + "\" was already parsed.");
return appender;
}
// Appender was not previously initialized.
final String prefix = APPENDER_PREFIX + appenderName;
final String layoutPrefix = prefix + ".layout";
final String filterPrefix = APPENDER_PREFIX + appenderName + ".filter.";
final String className = OptionConverter.findAndSubst(prefix, props);
appender = manager.parseAppender(appenderName, className, prefix, layoutPrefix, filterPrefix, props, this);
if (appender == null) {
appender = buildAppender(appenderName, className, prefix, layoutPrefix, filterPrefix, props);
} else {
registry.put(appenderName, appender);
if (appender instanceof AppenderWrapper) {
addAppender(((AppenderWrapper) appender).getAppender());
} else {
addAppender(new AppenderAdapter(appender).getAdapter());
}
}
return appender;
}
use of org.apache.log4j.bridge.AppenderWrapper in project logging-log4j2 by apache.
the class RollingFileAppenderBuilder method createAppender.
private Appender createAppender(final String name, final Log4j1Configuration config, final Layout layout, final Filter filter, final boolean bufferedIo, boolean immediateFlush, final String fileName, final String level, final String maxSize, final String maxBackups) {
org.apache.logging.log4j.core.Layout<?> fileLayout = null;
if (bufferedIo) {
immediateFlush = true;
}
if (layout instanceof LayoutWrapper) {
fileLayout = ((LayoutWrapper) layout).getLayout();
} else if (layout != null) {
fileLayout = new LayoutAdapter(layout);
}
org.apache.logging.log4j.core.Filter fileFilter = buildFilters(level, filter);
if (fileName == null) {
LOGGER.warn("Unable to create File Appender, no file name provided");
return null;
}
String filePattern = fileName + ".%i";
TriggeringPolicy timePolicy = TimeBasedTriggeringPolicy.newBuilder().setModulate(true).build();
SizeBasedTriggeringPolicy sizePolicy = SizeBasedTriggeringPolicy.createPolicy(maxSize);
CompositeTriggeringPolicy policy = CompositeTriggeringPolicy.createPolicy(sizePolicy);
RolloverStrategy strategy = DefaultRolloverStrategy.newBuilder().setConfig(config).setMax(maxBackups).build();
return new AppenderWrapper(RollingFileAppender.newBuilder().setName(name).setConfiguration(config).setLayout(fileLayout).setFilter(fileFilter).setBufferedIo(bufferedIo).setImmediateFlush(immediateFlush).setFileName(fileName).setFilePattern(filePattern).setPolicy(policy).setStrategy(strategy).build());
}
Aggregations