dantuch
dantuch

Reputation: 9283

log4j linux issue - log file is empty

Initial config file:

log4j.rootLogger=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=<%p> %d{dd-MM-yyyy HH:mm:ss} %m%n
log4j.appender.stdout.Threshold=DEBUG

later its confligured to output logs to runtime-specified location:

private static Logger configureLogger(ConflictsCheckerArgs dataModel) {
    Logger logger = Logger.getLogger(ApplicationController.class);

    FileAppender newAppender = new FileAppender();
    newAppender.setFile(new File(dataModel.getOutputPath(), "logs.log").getPath());
    newAppender.setName("logsToFile");
    newAppender.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
    newAppender.setThreshold(Level.INFO);
    newAppender.setAppend(true);
    newAppender.activateOptions();

    Logger.getRootLogger().addAppender(newAppender);

    return logger;
}

Problem is, that this file is created, but it's empty. I assume, that in jar's/target location program does not have write-access and maybe log4j try to do something there and that stops it from working at all. Do you have any ideas how to fix this problem - how to have logs in that log file in place of empty file?

Worth to add is that every other "normal" files, that are meant to be put into output directory, are there and they are perfectly fine.

Upvotes: 0

Views: 1057

Answers (2)

Bwire
Bwire

Reputation: 1201

I think it is to do with :

log4j.rootLogger=WARN, stdout

In your application are you logging errors and warnings yet no output?

try changing it to :

log4j.rootLogger=INFO, stdout

Upvotes: 0

bastos.sergio
bastos.sergio

Reputation: 6764

Try activating the debug functionality to see what the log4j library is doing internally...

Example:

java -Dlog4j.debug ...

This will print to System.out helpful information about which file it used to initialize itself, which loggers / appenders got configured etc.

Upvotes: 1

Related Questions