本文整理汇总了Java中org.apache.logging.log4j.core.helpers.Booleans.parseBoolean方法的典型用法代码示例。如果您正苦于以下问题:Java Booleans.parseBoolean方法的具体用法?Java Booleans.parseBoolean怎么用?Java Booleans.parseBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.logging.log4j.core.helpers.Booleans
的用法示例。
在下文中一共展示了Booleans.parseBoolean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAppender
import org.apache.logging.log4j.core.helpers.Booleans; //导入方法依赖的package包/类
/**
* Create a Console Appender.
* @param layout The layout to use (required).
* @param filter The Filter or null.
* @param t The target ("SYSTEM_OUT" or "SYSTEM_ERR"). The default is "SYSTEM_OUT".
* @param follow If true will follow changes to the underlying output stream.
* @param name The name of the Appender (required).
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @return The ConsoleAppender.
*/
@PluginFactory
public static ConsoleAppender createAppender(
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filters") final Filter filter,
@PluginAttribute("target") final String t,
@PluginAttribute("name") final String name,
@PluginAttribute("follow") final String follow,
@PluginAttribute("ignoreExceptions") final String ignore) {
if (name == null) {
LOGGER.error("No name provided for ConsoleAppender");
return null;
}
if (layout == null) {
layout = PatternLayout.createLayout(null, null, null, null, null);
}
final boolean isFollow = Boolean.parseBoolean(follow);
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
final Target target = t == null ? Target.SYSTEM_OUT : Target.valueOf(t);
return new ConsoleAppender(name, layout, filter, getManager(isFollow, target, layout), ignoreExceptions);
}
示例2: createLogger
import org.apache.logging.log4j.core.helpers.Booleans; //导入方法依赖的package包/类
@PluginFactory
public static LoggerConfig createLogger(
@PluginAttribute("additivity") final String additivity,
@PluginAttribute("level") final String levelName,
@PluginAttribute("includeLocation") final String includeLocation,
@PluginElement("AppenderRef") final AppenderRef[] refs,
@PluginElement("Properties") final Property[] properties,
@PluginConfiguration final Configuration config,
@PluginElement("Filters") final Filter filter) {
final List<AppenderRef> appenderRefs = Arrays.asList(refs);
Level level;
try {
level = Level.toLevel(levelName, Level.ERROR);
} catch (final Exception ex) {
LOGGER.error(
"Invalid Log level specified: {}. Defaulting to Error",
levelName);
level = Level.ERROR;
}
final boolean additive = Booleans.parseBoolean(additivity, true);
return new LoggerConfig(LogManager.ROOT_LOGGER_NAME, appenderRefs,
filter, level, additive, properties, config,
includeLocation(includeLocation));
}
示例3: createAppender
import org.apache.logging.log4j.core.helpers.Booleans; //导入方法依赖的package包/类
/**
* Create a RoutingAppender.
* @param name The name of the Appender.
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @param routes The routing definitions.
* @param config The Configuration (automatically added by the Configuration).
* @param rewritePolicy A RewritePolicy, if any.
* @param filter A Filter to restrict events processed by the Appender or null.
* @return The RoutingAppender
*/
@PluginFactory
public static RoutingAppender createAppender(
@PluginAttribute("name") final String name,
@PluginAttribute("ignoreExceptions") final String ignore,
@PluginElement("Routes") final Routes routes,
@PluginConfiguration final Configuration config,
@PluginElement("RewritePolicy") final RewritePolicy rewritePolicy,
@PluginElement("Filters") final Filter filter) {
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
if (name == null) {
LOGGER.error("No name provided for RoutingAppender");
return null;
}
if (routes == null) {
LOGGER.error("No routes defined for RoutingAppender");
return null;
}
return new RoutingAppender(name, filter, ignoreExceptions, routes, rewritePolicy, config);
}
示例4: createLogger
import org.apache.logging.log4j.core.helpers.Booleans; //导入方法依赖的package包/类
@PluginFactory
public static LoggerConfig createLogger(
@PluginAttribute("additivity") final String additivity,
@PluginAttribute("level") final String levelName,
@PluginAttribute("includeLocation") final String includeLocation,
@PluginElement("AppenderRef") final AppenderRef[] refs,
@PluginElement("Properties") final Property[] properties,
@PluginConfiguration final Configuration config,
@PluginElement("Filters") final Filter filter) {
final List<AppenderRef> appenderRefs = Arrays.asList(refs);
Level level;
try {
level = Level.toLevel(levelName, Level.ERROR);
} catch (final Exception ex) {
LOGGER.error(
"Invalid Log level specified: {}. Defaulting to Error",
levelName);
level = Level.ERROR;
}
final boolean additive = Booleans.parseBoolean(additivity, true);
return new AsyncLoggerConfig(LogManager.ROOT_LOGGER_NAME,
appenderRefs, filter, level, additive, properties, config,
includeLocation(includeLocation));
}
示例5: createAppender
import org.apache.logging.log4j.core.helpers.Booleans; //导入方法依赖的package包/类
/**
* Create an AsyncAppender.
* @param appenderRefs The Appenders to reference.
* @param errorRef An optional Appender to write to if the queue is full or other errors occur.
* @param blocking True if the Appender should wait when the queue is full. The default is true.
* @param size The size of the event queue. The default is 128.
* @param name The name of the Appender.
* @param includeLocation whether to include location information. The default is false.
* @param filter The Filter or null.
* @param config The Configuration.
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @return The AsyncAppender.
*/
@PluginFactory
public static AsyncAppender createAppender(@PluginElement("AppenderRef") final AppenderRef[] appenderRefs,
@PluginAttribute("errorRef") @PluginAliases("error-ref") final String errorRef,
@PluginAttribute("blocking") final String blocking,
@PluginAttribute("bufferSize") final String size,
@PluginAttribute("name") final String name,
@PluginAttribute("includeLocation") final String includeLocation,
@PluginElement("Filter") final Filter filter,
@PluginConfiguration final Configuration config,
@PluginAttribute("ignoreExceptions") final String ignore) {
if (name == null) {
LOGGER.error("No name provided for AsyncAppender");
return null;
}
if (appenderRefs == null) {
LOGGER.error("No appender references provided to AsyncAppender {}", name);
}
final boolean isBlocking = Booleans.parseBoolean(blocking, true);
final int queueSize = AbstractAppender.parseInt(size, DEFAULT_QUEUE_SIZE);
final boolean isIncludeLocation = Boolean.parseBoolean(includeLocation);
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
return new AsyncAppender(name, filter, appenderRefs, errorRef,
queueSize, isBlocking, ignoreExceptions, config, isIncludeLocation);
}
示例6: createAppender
import org.apache.logging.log4j.core.helpers.Booleans; //导入方法依赖的package包/类
/**
* Create a JMSQueueAppender.
* @param name The name of the Appender.
* @param factoryName The fully qualified class name of the InitialContextFactory.
* @param providerURL The URL of the provider to use.
* @param urlPkgPrefixes A colon-separated list of package prefixes for the class name of the factory class that
* will create a URL context factory
* @param securityPrincipalName The name of the identity of the Principal.
* @param securityCredentials The security credentials of the Principal.
* @param factoryBindingName The name to locate in the Context that provides the QueueConnectionFactory.
* @param queueBindingName The name to use to locate the Queue.
* @param userName The user ID to use to create the Queue Connection.
* @param password The password to use to create the Queue Connection.
* @param layout The layout to use (defaults to SerializedLayout).
* @param filter The Filter or null.
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @return The JMSQueueAppender.
*/
@PluginFactory
public static JMSQueueAppender createAppender(
@PluginAttribute("name") final String name,
@PluginAttribute("factoryName") final String factoryName,
@PluginAttribute("providerURL") final String providerURL,
@PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
@PluginAttribute("securityPrincipalName") final String securityPrincipalName,
@PluginAttribute("securityCredentials") final String securityCredentials,
@PluginAttribute("factoryBindingName") final String factoryBindingName,
@PluginAttribute("queueBindingName") final String queueBindingName,
@PluginAttribute("userName") final String userName,
@PluginAttribute("password") final String password,
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filter") final Filter filter,
@PluginAttribute("ignoreExceptions") final String ignore) {
if (name == null) {
LOGGER.error("No name provided for JMSQueueAppender");
return null;
}
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
final JMSQueueManager manager = JMSQueueManager.getJMSQueueManager(factoryName, providerURL, urlPkgPrefixes,
securityPrincipalName, securityCredentials, factoryBindingName, queueBindingName, userName, password);
if (manager == null) {
return null;
}
if (layout == null) {
layout = SerializedLayout.createLayout();
}
return new JMSQueueAppender(name, filter, layout, manager, ignoreExceptions);
}
示例7: createLayout
import org.apache.logging.log4j.core.helpers.Booleans; //导入方法依赖的package包/类
/**
* Create a pattern layout.
*
* @param pattern The pattern. If not specified, defaults to DEFAULT_CONVERSION_PATTERN.
* @param config The Configuration. Some Converters require access to the Interpolator.
* @param replace A Regex replacement String.
* @param charsetName The character set.
* @param always If {@code "true"} (default) exceptions are always written even if the pattern contains no exception
* tokens.
* @return The PatternLayout.
*/
@PluginFactory
public static PatternLayout createLayout(
@PluginAttribute("pattern") final String pattern,
@PluginConfiguration final Configuration config,
@PluginElement("Replace") final RegexReplacement replace,
@PluginAttribute("charset") final String charsetName,
@PluginAttribute("alwaysWriteExceptions") final String always) {
final Charset charset = Charsets.getSupportedCharset(charsetName);
final boolean alwaysWriteExceptions = Booleans.parseBoolean(always, true);
return new PatternLayout(
config, replace, pattern == null ? DEFAULT_CONVERSION_PATTERN : pattern, charset, alwaysWriteExceptions
);
}
示例8: createAppender
import org.apache.logging.log4j.core.helpers.Booleans; //导入方法依赖的package包/类
/**
* Create a Failover Appender.
* @param name The name of the Appender (required).
* @param primary The name of the primary Appender (required).
* @param failovers The name of one or more Appenders to fail over to (at least one is required).
* @param retryIntervalString The retry intervalMillis.
* @param config The current Configuration (passed by the Configuration when the appender is created).
* @param filter A Filter (optional).
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @return The FailoverAppender that was created.
*/
@PluginFactory
public static FailoverAppender createAppender(
@PluginAttribute("name") final String name,
@PluginAttribute("primary") final String primary,
@PluginElement("Failovers") final String[] failovers,
@PluginAttribute("retryInterval") final String retryIntervalString,
@PluginConfiguration final Configuration config,
@PluginElement("Filters") final Filter filter,
@PluginAttribute("ignoreExceptions") final String ignore) {
if (name == null) {
LOGGER.error("A name for the Appender must be specified");
return null;
}
if (primary == null) {
LOGGER.error("A primary Appender must be specified");
return null;
}
if (failovers == null || failovers.length == 0) {
LOGGER.error("At least one failover Appender must be specified");
return null;
}
final int seconds = parseInt(retryIntervalString, DEFAULT_INTERVAL_SECONDS);
int retryIntervalMillis;
if (seconds >= 0) {
retryIntervalMillis = seconds * Constants.MILLIS_IN_SECONDS;
} else {
LOGGER.warn("Interval " + retryIntervalString + " is less than zero. Using default");
retryIntervalMillis = DEFAULT_INTERVAL_SECONDS * Constants.MILLIS_IN_SECONDS;
}
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
return new FailoverAppender(name, filter, primary, failovers, retryIntervalMillis, config, ignoreExceptions);
}
示例9: createAppender
import org.apache.logging.log4j.core.helpers.Booleans; //导入方法依赖的package包/类
/**
* Factory method for creating a NoSQL appender within the plugin manager.
*
* @param name The name of the appender.
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @param filter The filter, if any, to use.
* @param bufferSize If an integer greater than 0, this causes the appender to buffer log events and flush whenever
* the buffer reaches this size.
* @param provider The NoSQL provider that provides connections to the chosen NoSQL database.
* @return a new NoSQL appender.
*/
@PluginFactory
public static NoSQLAppender createAppender(
@PluginAttribute("name") final String name,
@PluginAttribute("ignoreExceptions") final String ignore,
@PluginElement("Filter") final Filter filter,
@PluginAttribute("bufferSize") final String bufferSize,
@PluginElement("NoSqlProvider") final NoSQLProvider<?> provider) {
if (provider == null) {
LOGGER.error("NoSQL provider not specified for appender [{}].", name);
return null;
}
final int bufferSizeInt = AbstractAppender.parseInt(bufferSize, 0);
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
final String managerName = "noSqlManager{ description=" + name + ", bufferSize=" + bufferSizeInt
+ ", provider=" + provider + " }";
final NoSQLDatabaseManager<?> manager = NoSQLDatabaseManager.getNoSQLDatabaseManager(
managerName, bufferSizeInt, provider
);
if (manager == null) {
return null;
}
return new NoSQLAppender(name, filter, ignoreExceptions, manager);
}
示例10: createAppender
import org.apache.logging.log4j.core.helpers.Booleans; //导入方法依赖的package包/类
/**
* Factory method for creating a JDBC appender within the plugin manager.
*
* @param name The name of the appender.
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @param filter The filter, if any, to use.
* @param connectionSource The connections source from which database connections should be retrieved.
* @param bufferSize If an integer greater than 0, this causes the appender to buffer log events and flush whenever
* the buffer reaches this size.
* @param tableName The name of the database table to insert log events into.
* @param columnConfigs Information about the columns that log event data should be inserted into and how to insert
* that data.
* @return a new JDBC appender.
*/
@PluginFactory
public static JDBCAppender createAppender(
@PluginAttribute("name") final String name,
@PluginAttribute("ignoreExceptions") final String ignore,
@PluginElement("Filter") final Filter filter,
@PluginElement("ConnectionSource") final ConnectionSource connectionSource,
@PluginAttribute("bufferSize") final String bufferSize,
@PluginAttribute("tableName") final String tableName,
@PluginElement("ColumnConfigs") final ColumnConfig[] columnConfigs) {
final int bufferSizeInt = AbstractAppender.parseInt(bufferSize, 0);
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
final StringBuilder managerName = new StringBuilder("jdbcManager{ description=").append(name)
.append(", bufferSize=").append(bufferSizeInt).append(", connectionSource=")
.append(connectionSource.toString()).append(", tableName=").append(tableName).append(", columns=[ ");
int i = 0;
for (final ColumnConfig column : columnConfigs) {
if (i++ > 0) {
managerName.append(", ");
}
managerName.append(column.toString());
}
managerName.append(" ] }");
final JDBCDatabaseManager manager = JDBCDatabaseManager.getJDBCDatabaseManager(
managerName.toString(), bufferSizeInt, connectionSource, tableName, columnConfigs
);
if (manager == null) {
return null;
}
return new JDBCAppender(name, filter, ignoreExceptions, manager);
}
示例11: createAppender
import org.apache.logging.log4j.core.helpers.Booleans; //导入方法依赖的package包/类
/**
* Create a JMSTopicAppender.
* @param name The name of the Appender.
* @param factoryName The fully qualified class name of the InitialContextFactory.
* @param providerURL The URL of the provider to use.
* @param urlPkgPrefixes A colon-separated list of package prefixes for the class name of the factory class that
* will create a URL context factory
* @param securityPrincipalName The name of the identity of the Principal.
* @param securityCredentials The security credentials of the Principal.
* @param factoryBindingName The name to locate in the Context that provides the TopicConnectionFactory.
* @param topicBindingName The name to use to locate the Topic.
* @param userName The userid to use to create the Topic Connection.
* @param password The password to use to create the Topic Connection.
* @param layout The layout to use (defaults to SerializedLayout).
* @param filter The Filter or null.
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @return The JMSTopicAppender.
*/
@PluginFactory
public static JMSTopicAppender createAppender(
@PluginAttribute("name") final String name,
@PluginAttribute("factoryName") final String factoryName,
@PluginAttribute("providerURL") final String providerURL,
@PluginAttribute("urlPkgPrefixes") final String urlPkgPrefixes,
@PluginAttribute("securityPrincipalName") final String securityPrincipalName,
@PluginAttribute("securityCredentials") final String securityCredentials,
@PluginAttribute("factoryBindingName") final String factoryBindingName,
@PluginAttribute("topicBindingName") final String topicBindingName,
@PluginAttribute("userName") final String userName,
@PluginAttribute("password") final String password,
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filters") final Filter filter,
@PluginAttribute("ignoreExceptions") final String ignore) {
if (name == null) {
LOGGER.error("No name provided for JMSQueueAppender");
return null;
}
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
final JMSTopicManager manager = JMSTopicManager.getJMSTopicManager(factoryName, providerURL, urlPkgPrefixes,
securityPrincipalName, securityCredentials, factoryBindingName, topicBindingName, userName, password);
if (manager == null) {
return null;
}
if (layout == null) {
layout = SerializedLayout.createLayout();
}
return new JMSTopicAppender(name, filter, layout, manager, ignoreExceptions);
}
示例12: createLayout
import org.apache.logging.log4j.core.helpers.Booleans; //导入方法依赖的package包/类
/**
* Create the RFC 5424 Layout.
*
* @param facility The Facility is used to try to classify the message.
* @param id The default structured data id to use when formatting according to RFC 5424.
* @param ein The IANA enterprise number.
* @param includeMDC Indicates whether data from the ThreadContextMap will be included in the RFC 5424 Syslog
* record. Defaults to "true:.
* @param mdcId The id to use for the MDC Structured Data Element.
* @param mdcPrefix The prefix to add to MDC key names.
* @param eventPrefix The prefix to add to event key names.
* @param includeNL If true, a newline will be appended to the end of the syslog record. The default is false.
* @param escapeNL String that should be used to replace newlines within the message text.
* @param appName The value to use as the APP-NAME in the RFC 5424 syslog record.
* @param msgId The default value to be used in the MSGID field of RFC 5424 syslog records.
* @param excludes A comma separated list of MDC keys that should be excluded from the LogEvent.
* @param includes A comma separated list of MDC keys that should be included in the FlumeEvent.
* @param required A comma separated list of MDC keys that must be present in the MDC.
* @param exceptionPattern The pattern for formatting exceptions.
* @param useTLSMessageFormat If true the message will be formatted according to RFC 5425.
* @param loggerFields Container for the KeyValuePairs containing the patterns
* @param config The Configuration. Some Converters require access to the Interpolator.
* @return An RFC5424Layout.
*/
@PluginFactory
public static RFC5424Layout createLayout(
@PluginAttribute("facility") final String facility,
@PluginAttribute("id") final String id,
@PluginAttribute("enterpriseNumber") final String ein,
@PluginAttribute("includeMDC") final String includeMDC,
@PluginAttribute("mdcId") String mdcId,
@PluginAttribute("mdcPrefix") final String mdcPrefix,
@PluginAttribute("eventPrefix") final String eventPrefix,
@PluginAttribute("newLine") final String includeNL,
@PluginAttribute("newLineEscape") final String escapeNL,
@PluginAttribute("appName") final String appName,
@PluginAttribute("messageId") final String msgId,
@PluginAttribute("mdcExcludes") final String excludes,
@PluginAttribute("mdcIncludes") String includes,
@PluginAttribute("mdcRequired") final String required,
@PluginAttribute("exceptionPattern") final String exceptionPattern,
@PluginAttribute("useTLSMessageFormat") final String useTLSMessageFormat, // RFC 5425
@PluginElement("LoggerFields") final LoggerFields[] loggerFields,
@PluginConfiguration final Configuration config) {
final Charset charset = Charsets.UTF_8;
if (includes != null && excludes != null) {
LOGGER.error("mdcIncludes and mdcExcludes are mutually exclusive. Includes wil be ignored");
includes = null;
}
final Facility f = Facility.toFacility(facility, Facility.LOCAL0);
final int enterpriseNumber = Integers.parseInt(ein, DEFAULT_ENTERPRISE_NUMBER);
final boolean isMdc = Booleans.parseBoolean(includeMDC, true);
final boolean includeNewLine = Boolean.parseBoolean(includeNL);
final boolean useTlsMessageFormat = Booleans.parseBoolean(useTLSMessageFormat, false);
if (mdcId == null) {
mdcId = DEFAULT_MDCID;
}
return new RFC5424Layout(config, f, id, enterpriseNumber, isMdc, includeNewLine, escapeNL, mdcId, mdcPrefix,
eventPrefix, appName, msgId, excludes, includes, required, charset, exceptionPattern,
useTlsMessageFormat, loggerFields);
}
示例13: createAppender
import org.apache.logging.log4j.core.helpers.Booleans; //导入方法依赖的package包/类
/**
* Create a RollingFileAppender.
* @param fileName The name of the file that is actively written to. (required).
* @param filePattern The pattern of the file name to use on rollover. (required).
* @param append If true, events are appended to the file. If false, the file
* is overwritten when opened. Defaults to "true"
* @param name The name of the Appender (required).
* @param bufferedIO When true, I/O will be buffered. Defaults to "true".
* @param immediateFlush When true, events are immediately flushed. Defaults to "true".
* @param policy The triggering policy. (required).
* @param strategy The rollover strategy. Defaults to DefaultRolloverStrategy.
* @param layout The layout to use (defaults to the default PatternLayout).
* @param filter The Filter or null.
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @param advertise "true" if the appender configuration should be advertised, "false" otherwise.
* @param advertiseURI The advertised URI which can be used to retrieve the file contents.
* @param config The Configuration.
* @return A RollingFileAppender.
*/
@PluginFactory
public static RollingFileAppender createAppender(
@PluginAttribute("fileName") final String fileName,
@PluginAttribute("filePattern") final String filePattern,
@PluginAttribute("append") final String append,
@PluginAttribute("name") final String name,
@PluginAttribute("bufferedIO") final String bufferedIO,
@PluginAttribute("immediateFlush") final String immediateFlush,
@PluginElement("Policy") final TriggeringPolicy policy,
@PluginElement("Strategy") RolloverStrategy strategy,
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filter") final Filter filter,
@PluginAttribute("ignoreExceptions") final String ignore,
@PluginAttribute("advertise") final String advertise,
@PluginAttribute("advertiseURI") final String advertiseURI,
@PluginConfiguration final Configuration config) {
final boolean isAppend = Booleans.parseBoolean(append, true);
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
final boolean isBuffered = Booleans.parseBoolean(bufferedIO, true);
final boolean isFlush = Booleans.parseBoolean(immediateFlush, true);
final boolean isAdvertise = Boolean.parseBoolean(advertise);
if (name == null) {
LOGGER.error("No name provided for FileAppender");
return null;
}
if (fileName == null) {
LOGGER.error("No filename was provided for FileAppender with name " + name);
return null;
}
if (filePattern == null) {
LOGGER.error("No filename pattern provided for FileAppender with name " + name);
return null;
}
if (policy == null) {
LOGGER.error("A TriggeringPolicy must be provided");
return null;
}
if (strategy == null) {
strategy = DefaultRolloverStrategy.createStrategy(null, null, null,
String.valueOf(Deflater.DEFAULT_COMPRESSION), config);
}
if (layout == null) {
layout = PatternLayout.createLayout(null, null, null, null, null);
}
final RollingFileManager manager = RollingFileManager.getFileManager(fileName, filePattern, isAppend,
isBuffered, policy, strategy, advertiseURI, layout);
if (manager == null) {
return null;
}
return new RollingFileAppender(name, layout, filter, manager, fileName, filePattern,
ignoreExceptions, isFlush, isAdvertise ? config.getAdvertiser() : null);
}
示例14: createAppender
import org.apache.logging.log4j.core.helpers.Booleans; //导入方法依赖的package包/类
/**
* Create a File Appender.
*
* @param fileName The name and path of the file.
* @param append "True" if the file should be appended to, "false" if it
* should be overwritten. The default is "true".
* @param name The name of the Appender.
* @param immediateFlush "true" if the contents should be flushed on every
* write, "false" otherwise. The default is "true".
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @param layout The layout to use to format the event. If no layout is
* provided the default PatternLayout will be used.
* @param filter The filter, if any, to use.
* @param advertise "true" if the appender configuration should be
* advertised, "false" otherwise.
* @param advertiseURI The advertised URI which can be used to retrieve the
* file contents.
* @param config The Configuration.
* @return The FileAppender.
*/
@PluginFactory
public static RandomAccessFileAppender createAppender(
@PluginAttribute("fileName") final String fileName,
@PluginAttribute("append") final String append,
@PluginAttribute("name") final String name,
@PluginAttribute("immediateFlush") final String immediateFlush,
@PluginAttribute("ignoreExceptions") final String ignore,
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filters") final Filter filter,
@PluginAttribute("advertise") final String advertise,
@PluginAttribute("advertiseURI") final String advertiseURI,
@PluginConfiguration final Configuration config) {
final boolean isAppend = Booleans.parseBoolean(append, true);
final boolean isFlush = Booleans.parseBoolean(immediateFlush, true);
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
final boolean isAdvertise = Boolean.parseBoolean(advertise);
if (name == null) {
LOGGER.error("No name provided for FileAppender");
return null;
}
if (fileName == null) {
LOGGER.error("No filename provided for FileAppender with name "
+ name);
return null;
}
if (layout == null) {
layout = PatternLayout.createLayout(null, null, null, null, null);
}
final RandomAccessFileManager manager = RandomAccessFileManager.getFileManager(
fileName, isAppend, isFlush, advertiseURI, layout
);
if (manager == null) {
return null;
}
return new RandomAccessFileAppender(
name, layout, filter, manager, fileName, ignoreExceptions, isFlush,
isAdvertise ? config.getAdvertiser() : null
);
}
示例15: createColumnConfig
import org.apache.logging.log4j.core.helpers.Booleans; //导入方法依赖的package包/类
/**
* Factory method for creating a column config within the plugin manager.
*
* @param config The configuration object
* @param name The name of the database column as it exists within the database table.
* @param pattern The {@link PatternLayout} pattern to insert in this column. Mutually exclusive with
* {@code literalValue!=null} and {@code eventTimestamp=true}
* @param literalValue The literal value to insert into the column as-is without any quoting or escaping. Mutually
* exclusive with {@code pattern!=null} and {@code eventTimestamp=true}.
* @param eventTimestamp If {@code "true"}, indicates that this column is a date-time column in which the event
* timestamp should be inserted. Mutually exclusive with {@code pattern!=null} and
* {@code literalValue!=null}.
* @param unicode If {@code "true"}, indicates that the column is a unicode String.
* @param clob If {@code "true"}, indicates that the column is a character LOB (CLOB).
* @return the created column config.
*/
@PluginFactory
public static ColumnConfig createColumnConfig(
@PluginConfiguration final Configuration config,
@PluginAttribute("name") final String name,
@PluginAttribute("pattern") final String pattern,
@PluginAttribute("literal") final String literalValue,
@PluginAttribute("isEventTimestamp") final String eventTimestamp,
@PluginAttribute("isUnicode") final String unicode,
@PluginAttribute("isClob") final String clob) {
if (Strings.isEmpty(name)) {
LOGGER.error("The column config is not valid because it does not contain a column name.");
return null;
}
final boolean isPattern = Strings.isNotEmpty(pattern);
final boolean isLiteralValue = Strings.isNotEmpty(literalValue);
final boolean isEventTimestamp = Boolean.parseBoolean(eventTimestamp);
final boolean isUnicode = Booleans.parseBoolean(unicode, true);
final boolean isClob = Boolean.parseBoolean(clob);
if ((isPattern && isLiteralValue) || (isPattern && isEventTimestamp) || (isLiteralValue && isEventTimestamp)) {
LOGGER.error("The pattern, literal, and isEventTimestamp attributes are mutually exclusive.");
return null;
}
if (isEventTimestamp) {
return new ColumnConfig(name, null, null, true, false, false);
}
if (isLiteralValue) {
return new ColumnConfig(name, null, literalValue, false, false, false);
}
if (isPattern) {
return new ColumnConfig(
name, PatternLayout.createLayout(pattern, config, null, null, "false"), null, false, isUnicode,
isClob
);
}
LOGGER.error("To configure a column you must specify a pattern or literal or set isEventDate to true.");
return null;
}