2
I want to generate *.log or *.txt files with different dates (e.g., file-log-22-10-2015.log) within 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
However 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 http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
The properties file is in the WEB-INF folder and I am calling the logger inside the normal class as below.
Classeteste.java:
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 am using Vraptor.
If you are using log4j1 it needs to be inside , if you are using log4j2 the file needs to be in your project’s SRC, and it is missing
log4j.appender.file.Append=true
I don’t remember if he recognizes the relative path from where you want to record I believe it would be something likelog4j.appender.file.File=seucaminho inteiro para o web inf /WEB-INF/logs
– Wellington Avelino
@Wellingtonavelino ta according to the above structure
– Tiago Ferezin
Changes the
File=
I didn’t find it in the documentation saying that he can do as you put it, I always speak the way I want. @Tiagoferezin– Wellington Avelino
ok tried another way and it worked soon dps of the tests I will post the solution I found @Wellingtonavelino
– Tiago Ferezin
How did you pass the way?
– Wellington Avelino