0
我們在我們的項目中使用了log4j JDBCAppender。但是,它無法將異常堆棧跟蹤記錄到數據庫。我通過網絡搜索,並且得到了%throwable,但這不適用於JDBCAppender。有人可以幫我解決這個問題嗎?使用Log4j記錄異常堆棧跟蹤JDBCAppender
這是我的自定義追加程序代碼,我作爲同一JDBCAppender與小的修改
public void append(LoggingEvent event) {
ArrayList buffer = new ArrayList();
buffer.add(event);
flushBuffer(buffer);
}
public void flushBuffer(ArrayList buffer) {
for (Iterator i = buffer.iterator(); i.hasNext();) {
try {
LoggingEvent logEvent = (LoggingEvent) i.next();
String messageRecievied = getLogStatement(logEvent);
execute(messageRecievied);
} catch (SQLException e) {
this.errorHandler.error("Failed to excute sql", e, 2);
}
}
}
我不知道爲什麼它不包括蹤跡
這是我的log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender class="com.MyAppender" name="customAppen">
<layout class="org.apache.log4j.EnhancedPatternLayout">
<param value="%d[%t] %-5p(%F:<%M>:%L)- %m%n" name="ConversionPattern"/>
</layout>
</appender>
<appender class="org.apache.log4j.AsyncAppender" name="asynchapp">
<param name="Blocking" value="false"/>
<appender-ref ref="customAppen"/>
</appender>
<root>
<level value = "INFO"/>
<appender-ref ref="asynchapp"/>
</root>