本文整理匯總了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);
}