本文整理匯總了Java中org.apache.logging.log4j.core.Appender.append方法的典型用法代碼示例。如果您正苦於以下問題:Java Appender.append方法的具體用法?Java Appender.append怎麽用?Java Appender.append使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.logging.log4j.core.Appender
的用法示例。
在下文中一共展示了Appender.append方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testAppendWithKeyLookup
import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
@Test
public void testAppendWithKeyLookup() throws Exception {
final Appender appender = ctx.getRequiredAppender("KafkaAppenderWithKeyLookup");
final LogEvent logEvent = createLogEvent();
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
appender.append(logEvent);
final List<ProducerRecord<byte[], byte[]>> history = kafka.history();
assertEquals(1, history.size());
final ProducerRecord<byte[], byte[]> item = history.get(0);
assertNotNull(item);
assertEquals(TOPIC_NAME, item.topic());
byte[] keyValue = format.format(date).getBytes(StandardCharsets.UTF_8);
assertArrayEquals(item.key(), keyValue);
assertEquals(LOG_MESSAGE, new String(item.value(), StandardCharsets.UTF_8));
}
示例2: testAppend
import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
@Test
public void testAppend() 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/"))
.build();
appender.append(createLogEvent());
wireMockRule.verify(postRequestedFor(urlEqualTo("/test/log4j/"))
.withHeader("Host", containing("localhost"))
.withHeader("Content-Type", containing("application/json"))
.withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
}
示例3: testAppendHttps
import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
@Test
public void testAppendHttps() 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("https://localhost:" + wireMockRule.httpsPort() + "/test/log4j/"))
.setSslConfiguration(SslConfiguration.createSSLConfiguration(null,
KeyStoreConfiguration.createKeyStoreConfiguration(TestConstants.KEYSTORE_FILE, TestConstants.KEYSTORE_PWD(), TestConstants.KEYSTORE_TYPE, null),
TrustStoreConfiguration.createKeyStoreConfiguration(TestConstants.TRUSTSTORE_FILE, TestConstants.TRUSTSTORE_PWD(), TestConstants.TRUSTSTORE_TYPE, null)))
.setVerifyHostname(false)
.build();
appender.append(createLogEvent());
wireMockRule.verify(postRequestedFor(urlEqualTo("/test/log4j/"))
.withHeader("Host", containing("localhost"))
.withHeader("Content-Type", containing("application/json"))
.withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
}
示例4: testAppendMethodPut
import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
@Test
public void testAppendMethodPut() throws Exception {
wireMockRule.stubFor(put(urlEqualTo("/test/log4j/1234"))
.willReturn(SUCCESS_RESPONSE));
final Appender appender = HttpAppender.newBuilder()
.withName("Http")
.withLayout(JsonLayout.createDefaultLayout())
.setConfiguration(ctx.getConfiguration())
.setMethod("PUT")
.setUrl(new URL("http://localhost:" + wireMockRule.port() + "/test/log4j/1234"))
.build();
appender.append(createLogEvent());
wireMockRule.verify(putRequestedFor(urlEqualTo("/test/log4j/1234"))
.withHeader("Host", containing("localhost"))
.withHeader("Content-Type", containing("application/json"))
.withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
}
示例5: testAppendCustomHeader
import org.apache.logging.log4j.core.Appender; //導入方法依賴的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 + "\"")));
}
示例6: append
import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
@Override
public void append(final LogEvent logEvent) {
final LogEvent newLogEvent = LoggingUtils.prepareLogEvent(logEvent);
final String refName = this.appenderRef.getRef();
if (StringUtils.isNotBlank(refName)) {
final Appender appender = this.config.getAppender(refName);
if (appender != null) {
appender.append(newLogEvent);
} else {
LOGGER.warn("No log appender could be found for [{}]", refName);
}
} else {
LOGGER.warn("No log appender reference could be located in logging configuration.");
}
}
示例7: testAppendWithLayout
import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
@Test
public void testAppendWithLayout() throws Exception {
final Appender appender = ctx.getRequiredAppender("KafkaAppenderWithLayout");
appender.append(createLogEvent());
final List<ProducerRecord<byte[], byte[]>> history = kafka.history();
assertEquals(1, history.size());
final ProducerRecord<byte[], byte[]> item = history.get(0);
assertNotNull(item);
assertEquals(TOPIC_NAME, item.topic());
assertNull(item.key());
assertEquals("[" + LOG_MESSAGE + "]", new String(item.value(), StandardCharsets.UTF_8));
}
示例8: testAppendWithSerializedLayout
import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
@Test
public void testAppendWithSerializedLayout() throws Exception {
final Appender appender = ctx.getRequiredAppender("KafkaAppenderWithSerializedLayout");
final LogEvent logEvent = createLogEvent();
appender.append(logEvent);
final List<ProducerRecord<byte[], byte[]>> history = kafka.history();
assertEquals(1, history.size());
final ProducerRecord<byte[], byte[]> item = history.get(0);
assertNotNull(item);
assertEquals(TOPIC_NAME, item.topic());
assertNull(item.key());
assertEquals(LOG_MESSAGE, deserializeLogEvent(item.value()).getMessage().getFormattedMessage());
}
示例9: testAsyncAppend
import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
@Test
public void testAsyncAppend() throws Exception {
final Appender appender = ctx.getRequiredAppender("AsyncKafkaAppender");
appender.append(createLogEvent());
final List<ProducerRecord<byte[], byte[]>> history = kafka.history();
assertEquals(1, history.size());
final ProducerRecord<byte[], byte[]> item = history.get(0);
assertNotNull(item);
assertEquals(TOPIC_NAME, item.topic());
assertNull(item.key());
assertEquals(LOG_MESSAGE, new String(item.value(), StandardCharsets.UTF_8));
}
示例10: testAppendWithKey
import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
@Test
public void testAppendWithKey() throws Exception {
final Appender appender = ctx.getRequiredAppender("KafkaAppenderWithKey");
final LogEvent logEvent = createLogEvent();
appender.append(logEvent);
final List<ProducerRecord<byte[], byte[]>> history = kafka.history();
assertEquals(1, history.size());
final ProducerRecord<byte[], byte[]> item = history.get(0);
assertNotNull(item);
assertEquals(TOPIC_NAME, item.topic());
String msgKey = item.key().toString();
byte[] keyValue = "key".getBytes(StandardCharsets.UTF_8);
assertArrayEquals(item.key(), keyValue);
assertEquals(LOG_MESSAGE, new String(item.value(), StandardCharsets.UTF_8));
}
示例11: testAppendErrorIgnore
import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
@Test
public void testAppendErrorIgnore() throws Exception {
wireMockRule.stubFor(post(urlEqualTo("/test/log4j/"))
.willReturn(FAILURE_RESPONSE));
StatusLogger.getLogger().registerListener(new StatusListener() {
@Override
public void log(final StatusData data) {
error = data;
}
@Override
public Level getStatusLevel() {
return Level.ERROR;
}
@Override
public void close() throws IOException { }
});
error = null;
final Appender appender = HttpAppender.newBuilder()
.withName("Http")
.withLayout(JsonLayout.createDefaultLayout())
.setConfiguration(ctx.getConfiguration())
.setUrl(new URL("http://localhost:" + wireMockRule.port() + "/test/log4j/"))
.build();
appender.append(createLogEvent());
wireMockRule.verify(postRequestedFor(urlEqualTo("/test/log4j/"))
.withHeader("Host", containing("localhost"))
.withHeader("Content-Type", containing("application/json"))
.withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
assertNotNull(error);
assertEquals(Level.ERROR, error.getLevel());
assertEquals("Unable to send HTTP in appender [Http]", error.getMessage().toString());
}
示例12: testAppendError
import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
@Test(expected = AppenderLoggingException.class)
public void testAppendError() throws Exception {
wireMockRule.stubFor(post(urlEqualTo("/test/log4j/"))
.willReturn(FAILURE_RESPONSE));
final Appender appender = HttpAppender.newBuilder()
.withName("Http")
.withLayout(JsonLayout.createDefaultLayout())
.setConfiguration(ctx.getConfiguration())
.withIgnoreExceptions(false)
.setUrl(new URL("http://localhost:" + wireMockRule.port() + "/test/log4j/"))
.build();
appender.append(createLogEvent());
}
示例13: testAppendConnectError
import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
@Test(expected = AppenderLoggingException.class)
public void testAppendConnectError() throws Exception {
final Appender appender = HttpAppender.newBuilder()
.withName("Http")
.withLayout(JsonLayout.createDefaultLayout())
.setConfiguration(ctx.getConfiguration())
.withIgnoreExceptions(false)
.setUrl(new URL("http://localhost:"+(wireMockRule.port()+1)+"/test/log4j/"))
.build();
appender.append(createLogEvent());
}
示例14: append
import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
public void append(LogEvent e) {
for (Appender appender: this.appenders)
appender.append(e);
}