当前位置: 首页>>代码示例>>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;未经允许,请勿转载。