I have a web application based on Struts 2 MVC. I had to configure proper logging in the application which i already did and its working fine.
What i now want is, i need all the runtime exceptions and error due to system failure (such as lost database connection, any third party service is down etc etc), to be logged in my application log file.
I read about Thread.UncaughtExceptionHandler and also gone through this answer but still unable to get a start for this requirement.
Can someone suggest me how to initiate with this? What classes to make? What to configure? etc etc. Also to tell, there is no multithreading involved in my application.
Thank you!
Below is my log4j.properties
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${catalina.home}/logs/backlogApp.log
log4j.appender.file.MaxFileSize=1000KB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-4p %m%n
log4j.appender.DatePattern='.'yyyy-MM-dd
# Root logger option
log4j.rootLogger=WARN, file
log4j.logger.com.nagarro=WARN
# OFF Hibernate and Spring
log4j.logger.org.hibernate=OFF
log4j.logger.org.springframework=OFF
# OFF all JDBC parameters
log4j.logger.org.hibernate.type=OFF
Also, the global exception handler in struts.xml
<global-results>
<result name="error">/jsp/errorpage.jsp</result>
<result name="sessionexpired">/jsp/login.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception"
result="error" />
<exception-mapping exception="javax.persistence.PersistenceException"
result="error" />
</global-exception-mappings>