6

I am running my app with executable jar.

I have log4j.properties inside /resources folder

In prod I would like to override it and have it within external dir

How I could do that using Spring-Boot?

rayman
  • 20,786
  • 45
  • 148
  • 246
  • 1
    Adding _-Dlog4j.configuration=file:/path/to/log4j.properties_ to the command line should also work in Spring Boot. – Tome Jan 22 '15 at 09:25

4 Answers4

11
-Dlogging.config=/path/to/log4j.properties

http://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html

Johan Frick
  • 1,084
  • 1
  • 10
  • 18
11

If you don't like to add command line arguments, you can make additional application.properties on the directory where you start the application. like:

# log4j configuration for product
logging.config=log4j-prod.properties

Then, this application.properties will override the /resources/application.properties and, the log4j-prod.properties will be used on the product environment. Please read more details on:

http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files

Whiteship
  • 1,799
  • 3
  • 16
  • 15
3

try this: java -Dlog4j.configuration=file:/log4j.properties -jar XX.jar

the -D configuration before the -jar configuration. work for me.

chateldon
  • 41
  • 4
1

-Dlog4j.configuration=file:/path/to/log4j.properties to the command line works in Spring Boot 1.5.6. Don't forget file: .

James Jones
  • 3,850
  • 5
  • 25
  • 44
Liao Rui
  • 11
  • 1