本文整理汇总了Java中ch.qos.logback.classic.LoggerContext.putProperty方法的典型用法代码示例。如果您正苦于以下问题:Java LoggerContext.putProperty方法的具体用法?Java LoggerContext.putProperty怎么用?Java LoggerContext.putProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.classic.LoggerContext
的用法示例。
在下文中一共展示了LoggerContext.putProperty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beforeLogSystemInit
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
@Before
public void beforeLogSystemInit() throws IOException, InterruptedException {
kafka = TestKafka.createTestKafka(1);
loggerContext = new LoggerContext();
loggerContext.putProperty("brokers.list", kafka.getBrokerList());
loggerContext.getStatusManager().add(new StatusListener() {
@Override
public void addStatusEvent(Status status) {
if (status.getEffectiveLevel() > Status.INFO) {
System.err.println(status.toString());
if (status.getThrowable() != null) {
collector.addError(status.getThrowable());
} else {
collector.addError(new RuntimeException("StatusManager reported warning: "+status.toString()));
}
} else {
System.out.println(status.toString());
}
}
});
loggerContext.putProperty("HOSTNAME","localhost");
unit = new KafkaAppender<ILoggingEvent>();
final PatternLayout patternLayout = new PatternLayout();
patternLayout.setPattern("%msg");
patternLayout.setContext(loggerContext);
patternLayout.start();
unit.setEncoder(new LayoutKafkaMessageEncoder(patternLayout, Charset.forName("UTF-8")));
unit.setTopic("logs");
unit.setName("TestKafkaAppender");
unit.setContext(loggerContext);
unit.addProducerConfigValue(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBrokerList());
unit.setKeyingStrategy(new RoundRobinKeyingStrategy());
}
示例2: getLoggerContext
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
static LoggerContext getLoggerContext(
final String[] keys,
final String[] values) {
// specifically cast to logback version so we can add advanced stuff (i.e. properties)
final LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.reset();
for (int i = 0; i < keys.length; i++) {
final String key = keys[i];
final String value = values[i];
if (!Strings.isNullOrEmpty(key) && !Strings.isNullOrEmpty(value)) {
loggerContext.putProperty(key, value);
}
}
return loggerContext;
}