gandra404
gandra404

Reputation: 6091

Spring boot with gradle and log4j2 not logs to file

I have start working with spring boot and gradle and I am trying to use log4j2 for logging. I am first compiling and building:

gradlew clean build

and after than execute jar:

java -jar build/libs/java-apns-notifier-0.1.0.jar

After executing jar I can see log in the console but not in the file mentioned in log4j2.xml(D:/temp/logs/apns.log). In that file I can see only logs from springframework but not from my code.
Question is how to make this simple scenario to work?
I want to see that my logs also appears in the log file.

Here is the source code: Java Apple Push Notification Service Notifier

IMPORTANT!
I have recently noticed that logs appears. But only after I kill the process. So to clarify here is what is going on:

  1. Run jar with:

java -jar build/libs/java-apns-notifier-0.1.0.jar

-> Nothing appears in the log file

  1. Kill process in the comand line.
    -> Log appears in the log file

Upvotes: 0

Views: 1299

Answers (1)

Paulo Santos
Paulo Santos

Reputation: 671

The log is taking some time to appear in your log file because you are using

immediateFlush="false"

If you switch it to true, you will see the logs appearing immediately, but it might impact the performance of the application.

By default, bufferedIO is true and bufferSize is 8192 bytes. This means that the logs will only be written to disk after the buffer has 8192 chars.

Refer to https://logging.apache.org/log4j/2.x/manual/appenders.html for more details.

Upvotes: 1

Related Questions