suraj1291993
suraj1291993

Reputation: 473

Log4j2 Configuration Logs to File

I am new to Log4j2. I am trying to configure a logging system using slf4j and log4j2.

I have few doubts.

While configuring log4j2, I noticed configuration logs form log4j2 is printed in console. I want to print those logs in file instead of console.

Is there any way to use log4j2's appender .

PS : I noted that log4j2 uses StatusLogger to print its configuration logs. Is there any way to make it use a file.

Upvotes: 1

Views: 632

Answers (1)

Remko Popma
Remko Popma

Reputation: 36844

The simplest way to do this is to redirect the process output to a file:

java -cp lib/*.jar com.mypackage.MyClass > output.txt

There are some properties you may be able to use to tell Log4j to write status logs to a file (probably org.apache.logging.logj.simplelog.logFile), but at best this will work after Log4j 2 is fully initialized. I assume you are interested in the internal status log statements that are emitted during Log4j 2 startup and initialization. For that, I'd recommend redirecting to a file.

Upvotes: 1

Related Questions