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


Java Property类代码示例

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


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

示例1: getOrCreateLoggerConfig

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
public static LoggerConfig getOrCreateLoggerConfig(String name) {
  LoggerContext context = (LoggerContext) LogManager.getContext(false);
  Configuration config = context.getConfiguration();
  LoggerConfig logConfig = config.getLoggerConfig(name);
  boolean update = false;
  if (!logConfig.getName().equals(name)) {
    List<AppenderRef> appenderRefs = logConfig.getAppenderRefs();
    Map<Property, Boolean> properties = logConfig.getProperties();
    Set<Property> props = properties == null ? null : properties.keySet();
    logConfig = LoggerConfig.createLogger(String.valueOf(logConfig.isAdditive()),
        logConfig.getLevel(), name, String.valueOf(logConfig.isIncludeLocation()),
        appenderRefs == null ? null : appenderRefs.toArray(new AppenderRef[appenderRefs.size()]),
        props == null ? null : props.toArray(new Property[props.size()]), config, null);
    config.addLogger(name, logConfig);
    update = true;
  }
  if (update) {
    context.updateLoggers();
  }
  return logConfig;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:22,代码来源:Configurator.java

示例2: KafkaManager

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
public KafkaManager(final LoggerContext loggerContext, final String name, final String topic, final String zkServers, final String mail, final  String rpc,
                    final String app, final String host, final Property[] properties) {
    super(loggerContext, name);
    this.topic = topic;
    this.zkServers = zkServers;
    this.mail = mail;
    this.rpc = rpc;
    this.app = app;
    this.orginApp = app;
    this.host = host;
    this.checkAndSetConfig(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName());
    this.checkAndSetConfig(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
    // 设置分区类, 使用自定义的KeyModPartitioner,同样的key进入相同的partition
    this.checkAndSetConfig(ProducerConfig.PARTITIONER_CLASS_CONFIG, KeyModPartitioner.class.getName());
    // xml配置里面的参数
    for (final Property property : properties) {
        this.config.put(property.getName(), property.getValue());
    }
    // 由于容器部署需要从外部获取host
    this.config.put(ProducerConfig.CLIENT_ID_CONFIG, this.app + Constants.MIDDLE_LINE + this.host + Constants.MIDDLE_LINE + "log4j2");
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:22,代码来源:KafkaManager.java

示例3: createMap

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
private static Map<String, String> createMap(final List<Property> properties) {
    final Map<String, String> contextMap = ThreadContext.getImmutableContext();
    if (contextMap == null && (properties == null || properties.size() == 0)) {
        return null;
    }
    if (properties == null || properties.size() == 0) {
        return contextMap; // contextMap is not null
    }
    final Map<String, String> map = new HashMap<String, String>(contextMap);

    for (final Property prop : properties) {
        if (!map.containsKey(prop.getName())) {
            map.put(prop.getName(), prop.getValue());
        }
    }
    return Collections.unmodifiableMap(map);
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:18,代码来源:Log4jLogEvent.java

示例4: toString

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
@Override
public String toString() {
    final StringBuilder sb = new StringBuilder();
    sb.append(" {");
    boolean first = true;
    for (final Map.Entry<Property, Boolean> entry : properties.entrySet()) {
        if (!first) {
            sb.append(", ");
        }
        final Property prop = entry.getKey();
        sb.append(prop.getName()).append("=").append(prop.getValue());
        first = false;
    }
    sb.append("}");
    return sb.toString();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:17,代码来源:PropertiesRewritePolicy.java

示例5: createLogger

import org.apache.logging.log4j.core.config.Property; //导入依赖的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));
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:26,代码来源:AsyncLoggerConfig.java

示例6: mergePropertiesIntoContextMap

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
/**
 * Merges the contents of the specified map into the contextMap, after
 * replacing any variables in the property values with the
 * StrSubstitutor-supplied actual values.
 *
 * @param properties configured properties
 * @param strSubstitutor used to lookup values of variables in properties
 */
public void mergePropertiesIntoContextMap(
        final Map<Property, Boolean> properties,
        final StrSubstitutor strSubstitutor) {
    if (properties == null) {
        return; // nothing to do
    }

    final Map<String, String> map = (contextMap == null) ? new HashMap<String, String>()
            : new HashMap<String, String>(contextMap);

    for (final Map.Entry<Property, Boolean> entry : properties.entrySet()) {
        final Property prop = entry.getKey();
        if (map.containsKey(prop.getName())) {
            continue; // contextMap overrides config properties
        }
        final String value = entry.getValue() ? strSubstitutor.replace(prop
                .getValue()) : prop.getValue();
        map.put(prop.getName(), value);
    }
    contextMap = map;
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:30,代码来源:RingBufferLogEvent.java

示例7: testH2Properties

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
@Test
public void testH2Properties() throws SQLException {
    final Property[] properties = new Property[] {
            // @formatter:off
            Property.createProperty("username", JdbcH2TestHelper.USER_NAME),
            Property.createProperty("password", JdbcH2TestHelper.PASSWORD),
            // @formatter:on
    };
    // @formatter:off
    final PoolingDriverConnectionSource source = PoolingDriverConnectionSource.newPoolingDriverConnectionSourceBuilder()
        .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
        .setProperties(properties)
        .build();
    // @formatter:on
    try (Connection conn = source.getConnection()) {
        Assert.assertFalse(conn.isClosed());
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:19,代码来源:PoolingDriverConnectionSourceTest.java

示例8: testH2PropertiesAndPoolName

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
@Test
public void testH2PropertiesAndPoolName() throws SQLException {
    final Property[] properties = new Property[] {
            // @formatter:off
            Property.createProperty("username", JdbcH2TestHelper.USER_NAME),
            Property.createProperty("password", JdbcH2TestHelper.PASSWORD),
            // @formatter:on
    };
    // @formatter:off
    final PoolingDriverConnectionSource source = PoolingDriverConnectionSource.newPoolingDriverConnectionSourceBuilder()
        .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
        .setProperties(properties)
        .setPoolName("MyPoolName")
        .build();
    // @formatter:on
    try (Connection conn = source.getConnection()) {
        Assert.assertFalse(conn.isClosed());
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:20,代码来源:PoolingDriverConnectionSourceTest.java

示例9: KafkaManager

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
public KafkaManager(final LoggerContext loggerContext, final String name, final String topic, final boolean syncSend,
                    final Property[] properties, final String key) {
    super(loggerContext, name);
    this.topic = Objects.requireNonNull(topic, "topic");
    this.syncSend = syncSend;
    config.setProperty("key.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
    config.setProperty("value.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
    config.setProperty("batch.size", "0");
    for (final Property property : properties) {
        config.setProperty(property.getName(), property.getValue());
    }

    this.key = key;

    this.timeoutMillis = Integer.parseInt(config.getProperty("timeout.ms", DEFAULT_TIMEOUT_MILLIS));
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:17,代码来源:KafkaManager.java

示例10: createAppender

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
@Deprecated
public static KafkaAppender createAppender(
        final Layout<? extends Serializable> layout,
        final Filter filter,
        final String name,
        final boolean ignoreExceptions,
        final String topic,
        final Property[] properties,
        final Configuration configuration,
        final String key) {

    if (layout == null) {
        AbstractLifeCycle.LOGGER.error("No layout provided for KafkaAppender");
        return null;
    }
    final KafkaManager kafkaManager =
            new KafkaManager(configuration.getLoggerContext(), name, topic, true, properties, key);
    return new KafkaAppender(name, layout, filter, ignoreExceptions, kafkaManager);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:20,代码来源:KafkaAppender.java

示例11: injectContextData

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
/**
 * If there are no configuration properties, this injector will return the thread context's internal data
 * structure. Otherwise the configuration properties are combined with the thread context key-value pairs into the
 * specified reusable StringMap.
 *
 * @param props list of configuration properties, may be {@code null}
 * @param ignore a {@code StringMap} instance from the log event
 * @return a {@code StringMap} combining configuration properties with thread context data
 */
@Override
public StringMap injectContextData(final List<Property> props, final StringMap ignore) {
    // If there are no configuration properties we want to just return the ThreadContext's StringMap:
    // it is a copy-on-write data structure so we are sure ThreadContext changes will not affect our copy.
    final StringMap immutableCopy = ThreadContext.getThreadContextMap().getReadOnlyContextData();
    if (props == null || props.isEmpty()) {
        return immutableCopy; // this will replace the LogEvent's context data with the returned instance
    }
    // However, if the list of Properties is non-empty we need to combine the properties and the ThreadContext
    // data. Note that we cannot reuse the specified StringMap: some Loggers may have properties defined
    // and others not, so the LogEvent's context data may have been replaced with an immutable copy from
    // the ThreadContext - this will throw an UnsupportedOperationException if we try to modify it.
    final StringMap result = ContextDataFactory.createContextData(props.size() + immutableCopy.size());
    copyProperties(props, result);
    result.putAll(immutableCopy);
    return result;
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:27,代码来源:ThreadContextDataInjector.java

示例12: toString

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
@Override
public String toString() {
    final StringBuilder sb = new StringBuilder();
    sb.append(" {");
    boolean first = true;
    for (final Map.Entry<Property, Boolean> entry : properties.entrySet()) {
        if (!first) {
            sb.append(", ");
        }
        final Property prop = entry.getKey();
        sb.append(prop.getName()).append('=').append(prop.getValue());
        first = false;
    }
    sb.append('}');
    return sb.toString();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:17,代码来源:PropertiesRewritePolicy.java

示例13: HttpURLConnectionManager

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
public HttpURLConnectionManager(final Configuration configuration, final LoggerContext loggerContext, final String name,
                                final URL url, final String method, final int connectTimeoutMillis,
                                final int readTimeoutMillis,
                                final Property[] headers,
                                final SslConfiguration sslConfiguration,
                                final boolean verifyHostname) {
    super(configuration, loggerContext, name);
    this.url = url;
    if (!(url.getProtocol().equalsIgnoreCase("http") || url.getProtocol().equalsIgnoreCase("https"))) {
        throw new ConfigurationException("URL must have scheme http or https");
    }
    this.isHttps = this.url.getProtocol().equalsIgnoreCase("https");
    this.method = Objects.requireNonNull(method, "method");
    this.connectTimeoutMillis = connectTimeoutMillis;
    this.readTimeoutMillis = readTimeoutMillis;
    this.headers = headers != null ? headers : new Property[0];
    this.sslConfiguration = sslConfiguration;
    if (this.sslConfiguration != null && !isHttps) {
        throw new ConfigurationException("SSL configuration can only be specified with URL scheme https");
    }
    this.verifyHostname = verifyHostname;
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:23,代码来源:HttpURLConnectionManager.java

示例14: createLogger

import org.apache.logging.log4j.core.config.Property; //导入依赖的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("Filter") 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,
            AsyncLoggerConfig.includeLocation(includeLocation));
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:26,代码来源:AsyncLoggerConfig.java

示例15: testAppendCustomHeader

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
@Test
public void testAppendCustomHeader() throws Exception {
    wireMockRule.stubFor(post(urlEqualTo("/test/log4j/"))
        .willReturn(SUCCESS_RESPONSE));

    final Appender appender = HttpAppender.newBuilder()
        .withName("Http")
        .withLayout(JsonLayout.createDefaultLayout())
        .setConfiguration(ctx.getConfiguration())
        .setUrl(new URL("http://localhost:" + wireMockRule.port() + "/test/log4j/"))
        .setHeaders(new Property[] {
            Property.createProperty("X-Test", "header value"),
            Property.createProperty("X-Runtime", "${java:runtime}")
        })
        .build();
    appender.append(createLogEvent());

    wireMockRule.verify(postRequestedFor(urlEqualTo("/test/log4j/"))
        .withHeader("Host", containing("localhost"))
        .withHeader("X-Test", equalTo("header value"))
        .withHeader("X-Runtime", equalTo(JAVA_LOOKUP.getRuntime()))
        .withHeader("Content-Type", containing("application/json"))
        .withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:25,代码来源:HttpAppenderTest.java


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