I am trying to configure log4j for the first time but its not creating myTest.log file. Below is my log4j.properties file and location of this file is WEB-INF/classes folder.
log4j.rootLogger=INFO, stdout, com.myTest
#tomcat logger
#log4j.logger.org.apache.catalina=DEBUG
log4j.logger.com.myTest=INFO
log4j.logger.org.apache.commons.configuration.PropertiesConfiguration=DEBUG
#appenders
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%5p] %d{yyyy-MM-dd HH:mm:ss} %m%n
log4j.appender.com.myTest=org.apache.log4j.FileAppender
log4j.appender.com.myTest.File=myTest.log
log4j.appender.com.myTest.MaxFileSize=15MB
log4j.appender.com.myTest.MaxBackupIndex=10
log4j.appender.com.myTest.layout=org.apache.log4j.PatternLayout
log4j.appender.com.myTest.layout.ConversionPattern=[%5p] %d{yyyy-MM-dd HH:mm:ss} %m%n
log4j.appender.org.apache.ibatis=org.apache.log4j.FileAppender
log4j.appender.org.apache.ibatis.File=myTest.log
log4j.appender.org.apache.ibatis.MaxFileSize=15MB
log4j.appender.org.apache.ibatis.MaxBackupIndex=10
log4j.appender.org.apache.ibatis.layout=org.apache.log4j.PatternLayout
log4j.appender.org.apache.ibatis.layout.ConversionPattern=[%5p] %d{yyyy-MM-dd HH:mm:ss} %m%n
My controller class is like
@Controller
public class LoginController
{
static final Logger logger = Logger.getLogger(LoginController.class);
@RequestMapping("/login")
public ModelAndView login(){
logger.debug("Test logs");
logger.error("test error");
return new ModelAndView("login");
}
}
But I can’t see any myTest.log file in my Apache/log folder. Is this a place it should be?
Jar file I am using is log4j-1.2.16.jar. Is anything else required.
I am using Ubuntu and its first time I am using this.
Put log4j.properties file in build/classes/ folder.
Put file path to ${catalina.home}/logs/myTest.log.
Path of logs can be checked by writing below code in your LoginController class
}