• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Property类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: testH2Properties

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


示例17: main

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
public static void main(String [] args){
	try{
		System.out.println(logger1.isDebugEnabled());
		System.out.println(logger1.isErrorEnabled());
		System.out.println(logger1.isInfoEnabled());

		System.out.println(logger2.isDebugEnabled());
		System.out.println(logger2.isErrorEnabled());
		System.out.println(logger2.isInfoEnabled());

		System.out.println(logger3.isDebugEnabled());
		System.out.println(logger3.isErrorEnabled());
		System.out.println(logger3.isInfoEnabled());

		System.out.println(logger4.isDebugEnabled());
		System.out.println(logger4.isErrorEnabled());
		System.out.println(logger4.isInfoEnabled());

		org.apache.logging.log4j.spi.LoggerContext context=LogManager.getContext();
		Logger logger = (Logger) LogManager.getLogger();
		LoggerConfig config=logger.get();
		Map<Property, Boolean> properties=config.getProperties();
		System.out.println(config.getName());
		LoggerContext ctx=LoggerContext.getContext();
		Object appenders=ctx.getConfiguration().getAppenders();
		System.out.println(appenders.toString());
	}catch(Exception e){
		e.printStackTrace();
	}finally{
		System.exit(0);
	}


}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:35,代码来源:TestLog4j2.java


示例18: createAppender

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
@PluginFactory
public static KafkaAppender createAppender(
        @PluginElement("Layout") final Layout<? extends Serializable> layout,
        @PluginElement("Filter") final Filter filter,
        @Required(message = "No name provided for KafkaAppender") @PluginAttribute("name") final String name,
        @Required(message = "No topic provided for KafkaAppender") @PluginAttribute("topic") final String topic,
        @Required(message = "No zkServers provided for KafkaAppender") @PluginAttribute("zkServers") final String zkServers,
        @Required(message = "No mail provided for KafkaAppender") @PluginAttribute("mail") final String mail,
        @Required(message = "No rpc provided for KafkaAppender") @PluginAttribute("rpc") final String rpc,
        @Required(message = "No app provided for KafkaAppender") @PluginAttribute("app") final String app,
        @PluginElement("Properties") final Property[] properties,
        @PluginConfiguration final Configuration configuration) {
    final KafkaManager kafkaManager = new KafkaManager(configuration.getLoggerContext(), name, topic, zkServers, mail, rpc, app, SysUtil.host, properties);
    return new KafkaAppender(name, layout, filter, kafkaManager);
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:16,代码来源:KafkaAppender.java


示例19: createAppender

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
@PluginFactory
public static KafkaAppender createAppender(@PluginAttribute("name") final String name,
	                                       @PluginElement("Filter") final Filter filter,
		                                   @PluginAttribute("ignoreExceptions") final String ignore,
		                                   @PluginAttribute("topic") final String topic,
		                                   @PluginAttribute("enable") String enable,
		                                   @PluginAttribute("syncsend") String syncsend,
		                                   @PluginElement("Layout") Layout<? extends Serializable> layout,
		                                   @PluginElement("Properties") final Property[] properties) {
	boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
	boolean enableKafka = Booleans.parseBoolean(enable, true);
	boolean sync = Booleans.parseBoolean(syncsend, false);

	KafkaProducer<String, String> producer = null;
	Map<String, Object> props = new HashMap<String, Object>();
	for (Property property : properties) {
		props.put(property.getName(), property.getValue());
	}
	props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
    props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");

	if(enableKafka)
	   producer = new KafkaProducer<String, String>(props);

	if(layout == null) {
		layout = SerializedLayout.createLayout();
	}

	return new KafkaAppender(name, filter, layout, ignoreExceptions, producer , topic, sync);

}
 
开发者ID:omkreddy,项目名称:log4j2-kafka-appender,代码行数:32,代码来源:KafkaAppender.java


示例20: createLoggerConfig

import org.apache.logging.log4j.core.config.Property; //导入依赖的package包/类
/**
 * Creates an instance of {@link LoggerConfig} which may be
 * {@link AsyncLoggerConfig} if asynchronous loggers are used.
 * 
 * @param configuration the owner configuration
 * @param asyncLoggers
 * @param loggerName the name of the logger
 * @param level the {@link Level} of the logger
 * @param additivity if additivity is enabled for the logger
 * @return an instance of {@link LoggerConfig} or
 *         {@link AsyncLoggerConfig}
 */
protected static LoggerConfig createLoggerConfig(final Configuration configuration,
    boolean asyncLoggers, final String loggerName, final Level level, final boolean additivity) {
  final Filter filter = null;
  if (asyncLoggers) {
    // XXX Obscure static factory methods.
    return new AsyncLoggerConfig(loggerName, Collections.<AppenderRef>emptyList(), filter, level,
        additivity, new Property[0], configuration, false) {
      private static final long serialVersionUID = 1L;
    };
  } else {
    return LoggerConfig.createLogger(String.valueOf(additivity), level, loggerName, null,
        new AppenderRef[0], new Property[0], configuration, filter);
  }
}
 
开发者ID:nobeh,项目名称:log4j-configuration-builder,代码行数:27,代码来源:ConfigurationBuilder.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LogManager类代码示例发布时间:2022-05-23
下一篇:
Java DefaultPartitioner类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap