I am using a apache’s log4j for logging errors in my application. When I start the tomcat server, the log info information is written into the log file as expected (Also the log info is written into the log file when I stop the tomcat server). But when I start using the application, I log information I am expecting to be written through the app is not written into the log file. For e.g. I am giving inputs that will give exception, but the log.error(e,e) isn’t getting written in the log file.
this is how i am using the Logger
static Logger log = Logger.getLogger(MyClass.class);
log.info("my message" );
log.error(e,e);
Please help
EDIT: Adding log4j.properties file contents
log4j.rootLogger =INFO, FILE, stdout
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=${catalina.home}/logs/myapp.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{ABSOLUTE} %5p\t\t%c{1} :%L - %m%n
It seems that you have not configured your logger. Please find
log4j.xmlorlogging.propertiestypically located underTOMCAT_HOME/conf. Edit them to include your application’s package.This will help you to write your application level log messages to log file of your server (tomcat).
Better way is to manage your own logging configuration and files. Create
log4j.xmlfile and put it underWEB-INF/classesinto your application. You can find a lot of examples and tutorials that will help you to write yourlog4j.xml. For example this one: http://logging.apache.org/log4j/1.2/manual.html