Java 类org.apache.logging.log4j.core.helpers.Integers 实例源码

项目:log4j2    文件:Agent.java   
/**
 * Create an Agent.
 * @param host The host name.
 * @param port The port number.
 * @return The Agent.
 */
@PluginFactory
public static Agent createAgent(@PluginAttribute("host") String host,
        @PluginAttribute("port") final String port) {
    if (host == null) {
        host = DEFAULT_HOST;
    }

    int portNum;
    try {
        portNum = Integers.parseInt(port, DEFAULT_PORT);
    } catch (final Exception ex) {
        LOGGER.error("Error parsing port number " + port, ex);
        return null;
    }
    return new Agent(host, portNum);
}
项目:log4j2    文件:AbstractAppender.java   
public static int parseInt(String s, int defaultValue) {
    try {
        return Integers.parseInt(s, defaultValue);
    } catch (NumberFormatException e) {
        LOGGER.error("Could not parse \"{}\" as an integer,  using default value {}: {}", s, defaultValue, e);
        return defaultValue;
    }
}
项目:log4j2    文件:TimeBasedTriggeringPolicy.java   
/**
 * Create a TimeBasedTriggeringPolicy.
 * @param interval The interval between rollovers.
 * @param modulate If true the time will be rounded to occur on a boundary aligned with the increment.
 * @return a TimeBasedTriggeringPolicy.
 */
@PluginFactory
public static TimeBasedTriggeringPolicy createPolicy(
        @PluginAttribute("interval") final String interval,
        @PluginAttribute("modulate") final String modulate) {
    final int increment = Integers.parseInt(interval, 1);
    final boolean mod = Boolean.parseBoolean(modulate);
    return new TimeBasedTriggeringPolicy(increment, mod);
}
项目:log4j2    文件:DefaultRolloverStrategy.java   
/**
 * Create the DefaultRolloverStrategy.
 * @param max The maximum number of files to keep.
 * @param min The minimum number of files to keep.
 * @param fileIndex If set to "max" (the default), files with a higher index will be newer than files with a
 * smaller index. If set to "min", file renaming and the counter will follow the Fixed Window strategy.
 * @param compressionLevelStr The compression level, 0 (less) through 9 (more); applies only to ZIP files.
 * @param config The Configuration.
 * @return A DefaultRolloverStrategy.
 */
@PluginFactory
public static DefaultRolloverStrategy createStrategy(
        @PluginAttribute("max") final String max,
        @PluginAttribute("min") final String min,
        @PluginAttribute("fileIndex") final String fileIndex,
        @PluginAttribute("compressionLevel") final String compressionLevelStr,
        @PluginConfiguration final Configuration config) {
    final boolean useMax = fileIndex == null ? true : fileIndex.equalsIgnoreCase("max");
    int minIndex;
    if (min != null) {
        minIndex = Integer.parseInt(min);
        if (minIndex < 1) {
            LOGGER.error("Minimum window size too small. Limited to " + MIN_WINDOW_SIZE);
            minIndex = MIN_WINDOW_SIZE;
        }
    } else {
        minIndex = MIN_WINDOW_SIZE;
    }
    int maxIndex;
    if (max != null) {
        maxIndex = Integer.parseInt(max);
        if (maxIndex < minIndex) {
            maxIndex = minIndex < DEFAULT_WINDOW_SIZE ? DEFAULT_WINDOW_SIZE : minIndex;
            LOGGER.error("Maximum window size must be greater than the minimum windows size. Set to " + maxIndex);
        }
    } else {
        maxIndex = DEFAULT_WINDOW_SIZE;
    }
    final int compressionLevel = Integers.parseInt(compressionLevelStr, Deflater.DEFAULT_COMPRESSION);
    return new DefaultRolloverStrategy(minIndex, maxIndex, useMax, compressionLevel, config.getStrSubstitutor());
}
项目:log4j2    文件:RFC5424Layout.java   
/**
 * 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);
}