本文整理匯總了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;
}