1

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.

greenhorntechie
  • 386
  • 2
  • 6
  • 13

1 Answers1

1

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.

sumit
  • 3,210
  • 1
  • 19
  • 37
  • 1
    Thanks Sumit for the response. Earlier I tried with -Dlog4j.configuration=file:///etc/myapp/log4j.xml and also -Dlog4j.configuration=/etc/myapp/log4j.xml. Both of them didn't work. However, when I tried with -Dlog4j.configuration=file:/etc/myapp/log4j.xml as per your suggestion, it worked. Many thanks for your comment. – greenhorntechie Apr 22 '20 at 08:52