本文整理汇总了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());
}
示例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);
}
示例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());
}
示例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);
}