I want to generate * .log or * .txt files with different dates (eg file-log-22-10-2015.log) inside the WEB-INF folder of my JavaWeb project. I created the log4j.proprieties file as follows :
log4j.properties
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
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=%d{dd-MM-yyyy HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=/WEB-INF/logs
log4j.appender.file.DatePattern='.'dd-MM-yyyy
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd-MM-yyyy HH:mm:ss} %-5p %c{1}:%L - %m%n
But it does not generate and gives the following error in the console:
log4j: WARN No appenders could be found for logger (br.com.meusistema.ClasseTeste). log4j: WARN Please initialize the log4j system properly. log4j: WARN See link for more info.
The properties file is in the WEB-INF folder and I'm calling the logger inside the normal class as below.
Test.java class:
package br.com.meusistema;
import org.apache.log4j.Logger;
public class ClasseTeste{
private static final Logger log = Logger.getLogger(ClasseTeste.class);
public void metodoTeste(){
BasicConfigurator.configure();
log.info("iniciando Teste");
}
}
The structure is thus using log4j1
And even after all this does not generate the file. I removed this method from the documentation, and I'm using Vraptor.