I'm trying to configure log4j to log messages to a file. Right now, the file does get created with the name I provide, but the logs are not written to the file. My code:
public class Main extends Application
{
private static Logger logger = Logger.getLogger( Main.class.getName() );
@Override
public void start(Stage primaryStage) throws Exception
{
logger.warning("test");
logger.severe("oh noes");
}
public static void main(String[] args) {
launch(args);
}
}
Contents of my log4j.properties
file:
# Root logger option
log4j.rootLogger=INFO, file, stdout
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=log.log
log4j.appender.file.MaxFileSize=1024MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
When I run this, I get this output in the console:
Jun 23, 2014 3:19:16 AM com.foo.Main start
WARNING: test
Jun 23, 2014 3:19:16 AM com.foo.Main start
SEVERE: oh noes
The file log.log
does get created in my main directory. But its empty.
Any ideas what I'm doing wrong? I'm using log4j version 1.2.17.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…