in log4j-flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeAppender.java [189:298]
public static FlumeAppender createAppender(@PluginElement("Agents") final Agent[] agents,
@PluginElement("Properties") final Property[] properties,
@PluginAttribute("hosts") final String hosts,
@PluginAttribute("embedded") final String embedded,
@PluginAttribute("type") final String type,
@PluginAttribute("dataDir") final String dataDir,
@PluginAliases("connectTimeout")
@PluginAttribute("connectTimeoutMillis") final String connectionTimeoutMillis,
@PluginAliases("requestTimeout")
@PluginAttribute("requestTimeoutMillis") final String requestTimeoutMillis,
@PluginAttribute("agentRetries") final String agentRetries,
@PluginAliases("maxDelay") // deprecated
@PluginAttribute("maxDelayMillis") final String maxDelayMillis,
@PluginAttribute("name") final String name,
@PluginAttribute("ignoreExceptions") final String ignore,
@PluginAttribute("mdcExcludes") final String excludes,
@PluginAttribute("mdcIncludes") final String includes,
@PluginAttribute("mdcRequired") final String required,
@PluginAttribute("mdcPrefix") final String mdcPrefix,
@PluginAttribute("eventPrefix") final String eventPrefix,
@PluginAttribute("compress") final String compressBody,
@PluginAttribute("batchSize") final String batchSize,
@PluginAttribute("lockTimeoutRetries") final String lockTimeoutRetries,
@PluginElement("FlumeEventFactory") final FlumeEventFactory factory,
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filter") final Filter filter) {
final boolean embed = embedded != null ? Boolean.parseBoolean(embedded) :
(agents == null || agents.length == 0 || hosts == null || hosts.isEmpty()) && properties != null && properties.length > 0;
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
final boolean compress = Booleans.parseBoolean(compressBody, true);
ManagerType managerType;
if (type != null) {
if (embed && embedded != null) {
try {
managerType = ManagerType.getType(type);
LOGGER.warn("Embedded and type attributes are mutually exclusive. Using type " + type);
} catch (final Exception ex) {
LOGGER.warn("Embedded and type attributes are mutually exclusive and type " + type +
" is invalid.");
managerType = ManagerType.EMBEDDED;
}
} else {
try {
managerType = ManagerType.getType(type);
} catch (final Exception ex) {
LOGGER.warn("Type " + type + " is invalid.");
managerType = ManagerType.EMBEDDED;
}
}
} else if (embed) {
managerType = ManagerType.EMBEDDED;
} else {
managerType = ManagerType.AVRO;
}
final int batchCount = Integers.parseInt(batchSize, 1);
final int connectTimeoutMillis = Integers.parseInt(connectionTimeoutMillis, 0);
final int reqTimeoutMillis = Integers.parseInt(requestTimeoutMillis, 0);
final int retries = Integers.parseInt(agentRetries, 0);
final int lockTimeoutRetryCount = Integers.parseInt(lockTimeoutRetries, DEFAULT_LOCK_TIMEOUT_RETRY_COUNT);
final int delayMillis = Integers.parseInt(maxDelayMillis, DEFAULT_MAX_DELAY);
if (layout == null) {
final int enterpriseNumber = Rfc5424Layout.DEFAULT_ENTERPRISE_NUMBER;
layout = new Rfc5424Layout.Rfc5424LayoutBuilder()
.setFacility(Facility.LOCAL0)
.setEin(String.valueOf(enterpriseNumber))
.setIncludeMDC(true)
.setMdcId(Rfc5424Layout.DEFAULT_MDCID)
.setMdcPrefix(mdcPrefix)
.setEventPrefix(eventPrefix)
.setIncludeNL(false)
.setExcludes(excludes)
.setIncludes(includes)
.setRequired(required)
.setUseTLSMessageFormat(false)
.build();
}
if (name == null) {
LOGGER.error("No name provided for Appender");
return null;
}
AbstractFlumeManager manager;
switch (managerType) {
case EMBEDDED:
manager = FlumeEmbeddedManager.getManager(name, agents, properties, batchCount, dataDir);
break;
case AVRO:
manager = FlumeAvroManager.getManager(name, getAgents(agents, hosts), batchCount, delayMillis, retries, connectTimeoutMillis, reqTimeoutMillis);
break;
case PERSISTENT:
manager = FlumePersistentManager.getManager(name, getAgents(agents, hosts), properties, batchCount, retries,
connectTimeoutMillis, reqTimeoutMillis, delayMillis, lockTimeoutRetryCount, dataDir);
break;
default:
LOGGER.debug("No manager type specified. Defaulting to AVRO");
manager = FlumeAvroManager.getManager(name, getAgents(agents, hosts), batchCount, delayMillis, retries, connectTimeoutMillis, reqTimeoutMillis);
}
if (manager == null) {
return null;
}
return new FlumeAppender(name, filter, layout, ignoreExceptions, includes,
excludes, required, mdcPrefix, eventPrefix, compress, factory, Property.EMPTY_ARRAY, manager);
}