greenhorntechie
greenhorntechie

Reputation: 386

Changing log level for an executable JAR

I have built a maven Java project and deployed my JAR as an executable one on linux. I placed my log4j.xml under /src/main/resources directory during the build and hence it is now part of the final deployed JAR. I have configured log4j.xml with RollingFileAppender. So far, everything is working fine and I am able to see the logs generated.

However, wondering how to change the log level or any of the configuration within log4j.xml which is now part of the deployed JAR?

The other approaches I tried is having the log4j.xml outside in a separate directory and passed it as a configuration option to the JAR file using the below command

java -Xms512m -Xmx1024m -Dlog4j.configuration=/etc/myapp/log4j.xml -jar mylar.jar /etc/input.properties

java -Xms512m -Xmx1024m -Dlog4j.configurationFile=/etc/myapp/log4j.xml -jar mylar.jar /etc/input.properties

However, it is not working. No logs are being generated. So wondering whether I am doing this correctly or there is a better approach to implement.

Upvotes: 1

Views: 4787

Answers (1)

sumit
sumit

Reputation: 3740

from the quick look at your arguments, can you try passing the log4j path like below. (you are missing file: in the beginning of the path )

java -Dlog4j.configuration=file:/etc/cfg/log4j.properties -jar ./MyProject.jar ...

here is a similar answer present.

Upvotes: 2

Related Questions