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


Java Layout.format方法代碼示例

本文整理匯總了Java中org.apache.log4j.Layout.format方法的典型用法代碼示例。如果您正苦於以下問題:Java Layout.format方法的具體用法?Java Layout.format怎麽用?Java Layout.format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.log4j.Layout的用法示例。


在下文中一共展示了Layout.format方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testNDCWithCDATA

import org.apache.log4j.Layout; //導入方法依賴的package包/類
/**
   * Tests CDATA element within NDC content.  See bug 37560.
   */
 public void testNDCWithCDATA() throws Exception {
     Logger logger = Logger.getLogger("com.example.bar");
     Level level = Level.INFO;
     String ndcMessage ="<envelope><faultstring><![CDATA[The EffectiveDate]]></faultstring><envelope>";
     NDC.push(ndcMessage);
     LoggingEvent event =
       new LoggingEvent(
         "com.example.bar", logger, level, "Hello, World", null);
     Layout layout = createLayout();
     String result = layout.format(event);
     NDC.clear();
     Element parsedResult = parse(result);
     NodeList ndcs = parsedResult.getElementsByTagName("log4j:NDC");
     assertEquals(1, ndcs.getLength());
     StringBuffer buf = new StringBuffer();
     for(Node child = ndcs.item(0).getFirstChild();
             child != null;
             child = child.getNextSibling()) {
         buf.append(child.getNodeValue());
     }
     assertEquals(ndcMessage, buf.toString());
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:26,代碼來源:XMLLayoutTest.java

示例2: testExceptionWithCDATA

import org.apache.log4j.Layout; //導入方法依賴的package包/類
/**
   * Tests CDATA element within exception.  See bug 37560.
   */
 public void testExceptionWithCDATA() throws Exception {
     Logger logger = Logger.getLogger("com.example.bar");
     Level level = Level.INFO;
     String exceptionMessage ="<envelope><faultstring><![CDATA[The EffectiveDate]]></faultstring><envelope>";
     LoggingEvent event =
       new LoggingEvent(
         "com.example.bar", logger, level, "Hello, World", new Exception(exceptionMessage));
     Layout layout = createLayout();
     String result = layout.format(event);
     Element parsedResult = parse(result);
     NodeList throwables = parsedResult.getElementsByTagName("log4j:throwable");
     assertEquals(1, throwables.getLength());
     StringBuffer buf = new StringBuffer();
     for(Node child = throwables.item(0).getFirstChild();
             child != null;
             child = child.getNextSibling()) {
         buf.append(child.getNodeValue());
     }
     assertTrue(buf.toString().indexOf(exceptionMessage) != -1);
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:24,代碼來源:XMLLayoutTest.java

示例3: testRollingFileAppenderExt

import org.apache.log4j.Layout; //導入方法依賴的package包/類
@Test
public void testRollingFileAppenderExt(@Injectable LoggingEvent event,
    @Injectable Layout layout) throws Exception {
  new Expectations() {
    {
      layout.format(event);
      result = "test";
    }
  };
  File cur = new File(System.getProperty("user.dir"));
  File temp = new File(cur, "temptestfile.log");
  if (temp.exists()) {
    temp.delete();
  }
  RollingFileAppenderExt ext = new RollingFileAppenderExt();
  ext.setLayout(layout);
  ext.setLogPermission("rw-------");
  ext.setFile(temp.getAbsolutePath());
  ext.setFile(temp.getAbsolutePath(), false, false, 300000);
  Assert.assertEquals(ext.getLogPermission(), "rw-------");
  Assert.assertTrue(temp.exists());

  temp.delete();
  ext.subAppend(event);
  Assert.assertTrue(temp.exists());

  ext.close();
  temp.delete();
  Assert.assertFalse(temp.exists());
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:31,代碼來源:TestRollingFileAppenderExt.java

示例4: getLogMessages

import org.apache.log4j.Layout; //導入方法依賴的package包/類
public String[] getLogMessages() {
    LoggingEvent[] events = this.getLogEvents();
    String[] ret = new String[events.length];
    Layout layout = this.getLayout();
    for (int i = 0; i < events.length; i++) {
        ret[i] = layout.format(events[i]);
    } // FOR
    return (ret);
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:10,代碼來源:RingBufferAppender.java


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