當前位置: 首頁>>代碼示例>>Java>>正文


Java Appender.append方法代碼示例

本文整理匯總了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));
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:17,代碼來源:KafkaAppenderTest.java

示例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 + "\"")));
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:19,代碼來源:HttpAppenderTest.java

示例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 + "\"")));
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:23,代碼來源:HttpAppenderTest.java

示例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 + "\"")));
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:20,代碼來源:HttpAppenderTest.java

示例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 + "\"")));
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:25,代碼來源:HttpAppenderTest.java

示例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.");
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:16,代碼來源:CasAppender.java

示例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));
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:13,代碼來源:KafkaAppenderTest.java

示例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());
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:14,代碼來源:KafkaAppenderTest.java

示例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));
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:13,代碼來源:KafkaAppenderTest.java

示例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));
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:16,代碼來源:KafkaAppenderTest.java

示例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());
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:40,代碼來源:HttpAppenderTest.java

示例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());
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:15,代碼來源:HttpAppenderTest.java

示例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());
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:12,代碼來源:HttpAppenderTest.java

示例14: append

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
public void append(LogEvent e) {
    for (Appender appender: this.appenders)
        appender.append(e);
}
 
開發者ID:neurord,項目名稱:stochdiff,代碼行數:5,代碼來源:CustomFileAppender.java


注:本文中的org.apache.logging.log4j.core.Appender.append方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。