当前位置: 首页>>代码示例>>Java>>正文


Java PropertiesUtil类代码示例

本文整理汇总了Java中org.apache.logging.log4j.util.PropertiesUtil的典型用法代码示例。如果您正苦于以下问题:Java PropertiesUtil类的具体用法?Java PropertiesUtil怎么用?Java PropertiesUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PropertiesUtil类属于org.apache.logging.log4j.util包,在下文中一共展示了PropertiesUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: StandaloneLoggerConfiguration

import org.apache.logging.log4j.util.PropertiesUtil; //导入依赖的package包/类
/**
 * Constructor to create the default configuration.
 */
public StandaloneLoggerConfiguration(ConfigurationSource source) {
    super(source);

    setName(CONFIG_NAME);
    final Appender appender = StandaloneLogEventAppender.createAppender("StandaloneLogAppender", 1000);
    appender.start();
    addAppender(appender);
    final LoggerConfig root = getRootLogger();
    root.addAppender(appender, null, null);

    final String levelName = PropertiesUtil.getProperties().getStringProperty(DEFAULT_LEVEL);
    final Level level = levelName != null && Level.valueOf(levelName) != null ?
            Level.valueOf(levelName) : Level.ALL;
    root.setLevel(level);
}
 
开发者ID:Steve973,项目名称:camel-standalone,代码行数:19,代码来源:StandaloneLoggerConfiguration.java

示例2: setToDefault

import org.apache.logging.log4j.util.PropertiesUtil; //导入依赖的package包/类
private void setToDefault() {
    setName(DefaultConfiguration.DEFAULT_NAME);
    final Layout<? extends Serializable> layout =
            PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n",
                    null, null, null, null);
    final Appender appender = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false",
        "true");
    appender.start();
    addAppender(appender);
    final LoggerConfig root = getRootLogger();
    root.addAppender(appender, null, null);

    final String levelName = PropertiesUtil.getProperties().getStringProperty(DefaultConfiguration.DEFAULT_LEVEL);
    final Level level = levelName != null && Level.valueOf(levelName) != null ?
        Level.valueOf(levelName) : Level.ERROR;
    root.setLevel(level);
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:18,代码来源:BaseConfiguration.java

示例3: DefaultConfiguration

import org.apache.logging.log4j.util.PropertiesUtil; //导入依赖的package包/类
/**
 * Constructor to create the default configuration.
 */
public DefaultConfiguration() {

    setName(DEFAULT_NAME);
    final Layout<? extends Serializable> layout =
            PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n", null, null, null, null);
    final Appender appender =
            ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
    appender.start();
    addAppender(appender);
    final LoggerConfig root = getRootLogger();
    root.addAppender(appender, null, null);

    final String levelName = PropertiesUtil.getProperties().getStringProperty(DEFAULT_LEVEL);
    final Level level = levelName != null && Level.valueOf(levelName) != null ?
        Level.valueOf(levelName) : Level.ERROR;
    root.setLevel(level);
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:21,代码来源:DefaultConfiguration.java

示例4: init

import org.apache.logging.log4j.util.PropertiesUtil; //导入依赖的package包/类
/**
 * <em>Consider private, used for testing.</em>
 */
static void init() {
    ThreadContextMapFactory.init();
    contextMap = null;
    final PropertiesUtil managerProps = PropertiesUtil.getProperties();
    disableAll = managerProps.getBooleanProperty(DISABLE_ALL);
    useStack = !(managerProps.getBooleanProperty(DISABLE_STACK) || disableAll);
    useMap = !(managerProps.getBooleanProperty(DISABLE_MAP) || disableAll);

    contextStack = new DefaultThreadContextStack(useStack);
    if (!useMap) {
        contextMap = new NoOpThreadContextMap();
    } else {
        contextMap = ThreadContextMapFactory.createThreadContextMap();
    }
    if (contextMap instanceof ReadOnlyThreadContextMap) {
        readOnlyContextMap = (ReadOnlyThreadContextMap) contextMap;
    } else {
        readOnlyContextMap = null;
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:24,代码来源:ThreadContext.java

示例5: CustomConfiguration

import org.apache.logging.log4j.util.PropertiesUtil; //导入依赖的package包/类
/**
 * Constructor to create the default configuration.
 */
public CustomConfiguration(final LoggerContext loggerContext, final ConfigurationSource source) {
    super(loggerContext, source);

    setName(CONFIG_NAME);
    final Layout<? extends Serializable> layout = PatternLayout.newBuilder()
            .withPattern(DEFAULT_PATTERN)
            .withConfiguration(this)
            .build();
    final Appender appender = ConsoleAppender.createDefaultAppenderForLayout(layout);
    appender.start();
    addAppender(appender);
    final LoggerConfig root = getRootLogger();
    root.addAppender(appender, null, null);

    final String levelName = PropertiesUtil.getProperties().getStringProperty(DEFAULT_LEVEL);
    final Level level = levelName != null && Level.valueOf(levelName) != null ?
            Level.valueOf(levelName) : Level.ERROR;
    root.setLevel(level);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:23,代码来源:CustomConfiguration.java

示例6: tearDown

import org.apache.logging.log4j.util.PropertiesUtil; //导入依赖的package包/类
public void tearDown() throws SQLException {
    final LoggerContext context = LoggerContext.getContext(false);
    try {
        String appenderName = "databaseAppender";
        final Appender appender = context.getConfiguration().getAppender(appenderName);
        assertNotNull("The appender '" + appenderName + "' should not be null.", appender);
        assertTrue("The appender should be a JpaAppender.", appender instanceof JpaAppender);
        ((JpaAppender) appender).getManager().close();
    } finally {
        System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
        PropertiesUtil.getProperties().reload();
        context.reconfigure();
        StatusLogger.getLogger().reset();

        try (Statement statement = this.connection.createStatement();) {
            statement.execute("SHUTDOWN");
        }

        this.connection.close();
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:22,代码来源:AbstractJpaAppenderTest.java

示例7: createClock

import org.apache.logging.log4j.util.PropertiesUtil; //导入依赖的package包/类
private static Clock createClock() {
    final String userRequest = PropertiesUtil.getProperties().getStringProperty(PROPERTY_NAME);
    if (userRequest == null) {
        LOGGER.trace("Using default SystemClock for timestamps.");
        return logSupportedPrecision(new SystemClock());
    }
    Supplier<Clock> specified = aliases().get(userRequest);
    if (specified != null) {
        LOGGER.trace("Using specified {} for timestamps.", userRequest);
        return logSupportedPrecision(specified.get());
    }
    try {
        final Clock result = Loader.newCheckedInstanceOf(userRequest, Clock.class);
        LOGGER.trace("Using {} for timestamps.", result.getClass().getName());
        return logSupportedPrecision(result);
    } catch (final Exception e) {
        final String fmt = "Could not create {}: {}, using default SystemClock for timestamps.";
        LOGGER.error(fmt, userRequest, e);
        return logSupportedPrecision(new SystemClock());
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:22,代码来源:ClockFactory.java

示例8: start

import org.apache.logging.log4j.util.PropertiesUtil; //导入依赖的package包/类
@Override
public void start(final BundleContext context) throws Exception {
    final Provider provider = new Log4jProvider();
    final Hashtable<String, String> props = new Hashtable<>();
    props.put("APIVersion", "2.60");
    provideRegistration = context.registerService(Provider.class.getName(), provider, props);
    // allow the user to override the default ContextSelector (e.g., by using BasicContextSelector for a global cfg)
    if (PropertiesUtil.getProperties().getStringProperty(Constants.LOG4J_CONTEXT_SELECTOR) == null) {
        System.setProperty(Constants.LOG4J_CONTEXT_SELECTOR, BundleContextSelector.class.getName());
    }
    if (this.contextRef.compareAndSet(null, context)) {
        context.addBundleListener(this);
        // done after the BundleListener as to not miss any new bundle installs in the interim
        scanInstalledBundlesForPlugins(context);
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:17,代码来源:Activator.java

示例9: setToDefault

import org.apache.logging.log4j.util.PropertiesUtil; //导入依赖的package包/类
protected void setToDefault() {
    // LOG4J2-1176 facilitate memory leak investigation
    setName(DefaultConfiguration.DEFAULT_NAME + "@" + Integer.toHexString(hashCode()));
    final Layout<? extends Serializable> layout = PatternLayout.newBuilder()
            .withPattern(DefaultConfiguration.DEFAULT_PATTERN)
            .withConfiguration(this)
            .build();
    final Appender appender = ConsoleAppender.createDefaultAppenderForLayout(layout);
    appender.start();
    addAppender(appender);
    final LoggerConfig rootLoggerConfig = getRootLogger();
    rootLoggerConfig.addAppender(appender, null, null);

    final Level defaultLevel = Level.ERROR;
    final String levelName = PropertiesUtil.getProperties().getStringProperty(DefaultConfiguration.DEFAULT_LEVEL,
            defaultLevel.name());
    final Level level = Level.valueOf(levelName);
    rootLoggerConfig.setLevel(level != null ? level : defaultLevel);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:20,代码来源:AbstractConfiguration.java

示例10: createAppender

import org.apache.logging.log4j.util.PropertiesUtil; //导入依赖的package包/类
private AppenderComponentBuilder createAppender(final String key, final Properties properties) {
    final String name = (String) properties.remove(CONFIG_NAME);
    if (Strings.isEmpty(name)) {
        throw new ConfigurationException("No name attribute provided for Appender " + key);
    }
    final String type = (String) properties.remove(CONFIG_TYPE);
    if (Strings.isEmpty(type)) {
        throw new ConfigurationException("No type attribute provided for Appender " + key);
    }
    final AppenderComponentBuilder appenderBuilder = builder.newAppender(name, type);
    addFiltersToComponent(appenderBuilder, properties);
    final Properties layoutProps = PropertiesUtil.extractSubset(properties, "layout");
    if (layoutProps.size() > 0) {
        appenderBuilder.add(createLayout(name, layoutProps));
    }

    return processRemainingProperties(appenderBuilder, properties);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:19,代码来源:PropertiesConfigurationBuilder.java

示例11: processRemainingProperties

import org.apache.logging.log4j.util.PropertiesUtil; //导入依赖的package包/类
private static <B extends ComponentBuilder<?>> B processRemainingProperties(final B builder,
                                                                            final Properties properties) {
    while (properties.size() > 0) {
        final String propertyName = properties.stringPropertyNames().iterator().next();
        final int index = propertyName.indexOf('.');
        if (index > 0) {
            final String prefix = propertyName.substring(0, index);
            final Properties componentProperties = PropertiesUtil.extractSubset(properties, prefix);
            builder.addComponent(createComponent(builder, prefix, componentProperties));
        } else {
            builder.addAttribute(propertyName, properties.getProperty(propertyName));
            properties.remove(propertyName);
        }
    }
    return builder;
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:17,代码来源:PropertiesConfigurationBuilder.java

示例12: getReliabilityStrategy

import org.apache.logging.log4j.util.PropertiesUtil; //导入依赖的package包/类
/**
 * Returns a new {@code ReliabilityStrategy} instance based on the value of system property
 * {@code log4j.ReliabilityStrategy}. If not value was specified this method returns a new
 * {@code AwaitUnconditionallyReliabilityStrategy}.
 * <p>
 * Valid values for this system property are {@code "AwaitUnconditionally"} (use
 * {@code AwaitUnconditionallyReliabilityStrategy}), {@code "Locking"} (use {@code LockingReliabilityStrategy}) and
 * {@code "AwaitCompletion"} (use the default {@code AwaitCompletionReliabilityStrategy}).
 * <p>
 * Users may also use this system property to specify the fully qualified class name of a class that implements the
 * {@code ReliabilityStrategy} and has a constructor that accepts a single {@code LoggerConfig} argument.
 * 
 * @param loggerConfig the LoggerConfig the resulting {@code ReliabilityStrategy} is associated with
 * @return a ReliabilityStrategy that helps the specified LoggerConfig to log events reliably during or after a
 *         configuration change
 */
public static ReliabilityStrategy getReliabilityStrategy(final LoggerConfig loggerConfig) {

    final String strategy = PropertiesUtil.getProperties().getStringProperty("log4j.ReliabilityStrategy",
            "AwaitCompletion");
    if ("AwaitCompletion".equals(strategy)) {
        return new AwaitCompletionReliabilityStrategy(loggerConfig);
    }
    if ("AwaitUnconditionally".equals(strategy)) {
        return new AwaitUnconditionallyReliabilityStrategy(loggerConfig);
    }
    if ("Locking".equals(strategy)) {
        return new LockingReliabilityStrategy(loggerConfig);
    }
    try {
        final Class<? extends ReliabilityStrategy> cls = LoaderUtil.loadClass(strategy).asSubclass(
            ReliabilityStrategy.class);
        return cls.getConstructor(LoggerConfig.class).newInstance(loggerConfig);
    } catch (final Exception dynamicFailed) {
        StatusLogger.getLogger().warn(
                "Could not create ReliabilityStrategy for '{}', using default AwaitCompletionReliabilityStrategy: {}", strategy, dynamicFailed);
        return new AwaitCompletionReliabilityStrategy(loggerConfig);
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:40,代码来源:ReliabilityStrategyFactory.java

示例13: start

import org.apache.logging.log4j.util.PropertiesUtil; //导入依赖的package包/类
@Override
public void start() {
    LOGGER.debug("Starting LoggerContext[name={}, {}]...", getName(), this);
    if (PropertiesUtil.getProperties().getBooleanProperty("log4j.LoggerContext.stacktrace.on.start", false)) {
        LOGGER.debug("Stack trace to locate invoker",
                new Exception("Not a real error, showing stack trace to locate invoker"));
    }
    if (configLock.tryLock()) {
        try {
            if (this.isInitialized() || this.isStopped()) {
                this.setStarting();
                reconfigure();
                if (this.configuration.isShutdownHookEnabled()) {
                    setUpShutdownHook();
                }
                this.setStarted();
            }
        } finally {
            configLock.unlock();
        }
    }
    LOGGER.debug("LoggerContext[name={}, {}] started OK.", getName(), this);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:24,代码来源:LoggerContext.java

示例14: createWaitStrategy

import org.apache.logging.log4j.util.PropertiesUtil; //导入依赖的package包/类
static WaitStrategy createWaitStrategy(final String propertyName, final long timeoutMillis) {
    final String strategy = PropertiesUtil.getProperties().getStringProperty(propertyName, "TIMEOUT");
    LOGGER.trace("property {}={}", propertyName, strategy);
    final String strategyUp = strategy.toUpperCase(Locale.ROOT); // TODO Refactor into Strings.toRootUpperCase(String)
    switch (strategyUp) { // TODO Define a DisruptorWaitStrategy enum?
    case "SLEEP":
        return new SleepingWaitStrategy();
    case "YIELD":
        return new YieldingWaitStrategy();
    case "BLOCK":
        return new BlockingWaitStrategy();
    case "BUSYSPIN":
        return new BusySpinWaitStrategy();
    case "TIMEOUT":
        return new TimeoutBlockingWaitStrategy(timeoutMillis, TimeUnit.MILLISECONDS);
    default:
        return new TimeoutBlockingWaitStrategy(timeoutMillis, TimeUnit.MILLISECONDS);
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:20,代码来源:DisruptorUtil.java

示例15: calculateRingBufferSize

import org.apache.logging.log4j.util.PropertiesUtil; //导入依赖的package包/类
static int calculateRingBufferSize(final String propertyName) {
    int ringBufferSize = Constants.ENABLE_THREADLOCALS ? RINGBUFFER_NO_GC_DEFAULT_SIZE : RINGBUFFER_DEFAULT_SIZE;
    final String userPreferredRBSize = PropertiesUtil.getProperties().getStringProperty(propertyName,
            String.valueOf(ringBufferSize));
    try {
        int size = Integer.parseInt(userPreferredRBSize);
        if (size < RINGBUFFER_MIN_SIZE) {
            size = RINGBUFFER_MIN_SIZE;
            LOGGER.warn("Invalid RingBufferSize {}, using minimum size {}.", userPreferredRBSize,
                    RINGBUFFER_MIN_SIZE);
        }
        ringBufferSize = size;
    } catch (final Exception ex) {
        LOGGER.warn("Invalid RingBufferSize {}, using default size {}.", userPreferredRBSize, ringBufferSize);
    }
    return Integers.ceilingNextPowerOfTwo(ringBufferSize);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:18,代码来源:DisruptorUtil.java


注:本文中的org.apache.logging.log4j.util.PropertiesUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。