I am developing a web servlet and getting confused with log4j.properities, and I decided to call the log initialization in the constructor.
public static Logger logger = Logger.getLogger(MyProject.class.getName()); public MyProject() { super();
In general, the web servlet log file belongs to the tomcat log directory.
log4j.rootLogger=debug, R log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=${catalina.base}/logs/myproject.log log4j.appender.R.MaxFileSize=100KB log4j.appender.R.MaxBackupIndex=1 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
But, when encoding jUnit for a webservlet, the log file refers to the wrong address, because $ {catalina.base} is empty text. The error log is here.
[junit] log4j:ERROR setFile(null,true) call failed. [junit] java.io.FileNotFoundException: /logs/myproject.log (No such file or directory)
So, please teach me how to manage log files wisely. I hope to stop the output log file during testing using jUnit.
source share