我有一个工作的jsf应用程序,log4j配置为将不同的消息记录到不同的日志文件。但有时会将错误记录到控制台而不是特定的日志文件。这主要是在我使用的第三方jar中发生nullpointer错误时。 有没有办法配置log4j,以便所有未专门发送到日志文件的错误不会发送到控制台而是发送到常规日志文件?
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "dtd/log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="LogAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:\\logs\\web.log"/>
<param name="MaxFileSize" value="10000KB"/>
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%x %-5p [%d{yyyyMMdd HH:mm:ss}] - %c:%L - %m%n"/>
</layout>
</appender>
<appender name="WarnAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:\\logs\\warn.log"/>
<param name="Threshold" value="warn"/>
<param name="MaxFileSize" value="10000KB"/>
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%x %-5p [%d{yyyyMMdd HH:mm:ss}] - %c:%L - %m%n"/>
</layout>
</appender>
<appender name="WSAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:\\logs\\milesws.log"/>
<param name="MaxFileSize" value="10000KB"/>
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%x %-5p [%d{yyyyMMdd HH:mm:ss}] - %c:%L - %m%n"/>
</layout>
</appender>
<appender name="AccessAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:\\logs\\access.log"/>
<param name="MaxFileSize" value="10000KB"/>
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%x %-5p [%d{yyyyMMdd HH:mm:ss}] - %c:%L - %m%n"/>
</layout>
</appender>
<logger name="be.sofico.api.ws">
<level value="debug" />
<appender-ref ref="WSAppender" />
</logger>
<logger name="be.sofico.web">
<level value="debug" />
<appender-ref ref="LogAppender" />
</logger>
<logger name="org.ajax4jsf.event">
<level value="all" />
<appender-ref ref="LogAppender" />
</logger>
<logger name="org.apache">
<level value="info" />
<appender-ref ref="LogAppender" />
</logger>
<logger name="javax.enterprise.resource.webcontainer.jsf.lifecycle">
<appender-ref ref="LogAppender" />
</logger>
<logger name="javax.faces">
<level value="debug" />
<appender-ref ref="LogAppender" />
</logger>
<logger name="com.sun.faces">
<level value="all"/>
<appender-ref ref="LogAppender" />
</logger>
<logger name="org.apache.catalina">
<level value="warn"/>
<appender-ref ref="LogAppender" />
</logger>
<logger name="AccessLog">
<level value="info"/>
<appender-ref ref="AccessAppender" />
</logger>
<root>
<level value="debug"/>
<appender-ref ref="WarnAppender" />
</root>
</log4j:configuration>
记录到控制台而不是任何日志文件中的错误
managedbean E <Null Message>
com.sun.faces.spi.InjectionProviderException
at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:111)
at com.sun.faces.vendor.WebContainerInjectionProvider.invokePreDestroy(WebContainerInjectionProvider.java:79)
at com.sun.faces.mgbean.BeanBuilder.destroy(BeanBuilder.java:119)
at com.sun.faces.mgbean.BeanManager.destroy(BeanManager.java:248)
at com.sun.faces.application.WebappLifecycleListener.handleAttributeEvent(WebappLifecycleListener.java:265)
at com.sun.faces.application.WebappLifecycleListener.sessionDestroyed(WebappLifecycleListener.java:133)
at com.sun.faces.config.ConfigureListener.sessionDestroyed(ConfigureListener.java:306)
at com.ibm.ws.session.http.HttpSessionObserver.sessionDestroyed(HttpSessionObserver.java:179)
at com.ibm.ws.session.SessionEventDispatcher.sessionDestroyed(SessionEventDispatcher.java:160)
at com.ibm.ws.session.StoreCallback.sessionInvalidated(StoreCallback.java:126)
at com.ibm.ws.session.store.memory.MemorySession.invalidate(MemorySession.java:225)
at com.ibm.ws.session.store.memory.MemoryStore.checkSessionStillValid(MemoryStore.java:429)
at com.ibm.ws.session.store.memory.MemoryStore.runInvalidation(MemoryStore.java:373)
at com.ibm.ws.session.WsSessionInvalidator.alarm(WsSessionInvalidator.java:64)
at com.ibm.ejs.util.am._Alarm.run(_Alarm.java:133)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1659)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor1125.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:109)
... 15 more
Caused by: java.lang.NullPointerException
at be.sofico.web.frmwrk.FacesBean.getBean(FacesBean.java:59)
at be.sofico.web.frmwrk.FacesBean.getWS(FacesBean.java:70)
at be.sofico.web.frmwrk.mgbean.menu.MenuModelBase.destroy(MenuModelBase.java:46)
... 19 more