0

Suppose I have two Spring-Boot applications called config and eureka.

config is made up of:

config 
  /src/main
    /java
      /com.example
        Demo.java
    /resources
      application.properties

eureka is made up of:

eureka 
  /src/main
    /java
      /com.example
        Demo.java
    /resources
      application.properties

I have a log4j.properties files

log4j.rootLogger=INFO, stdout, file

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d{yyyy:MM:dd HH:mm:ss.SSS}] - %p [%t] --- %c : %m%n

log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=log.out
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%d{yyyy:MM:dd HH:mm:ss.SSS}]  - %p [%t] --- %c : %m%n

One way to log both config and eureka is by keeping a copy of this properties file in resources folder of both applications and giving a common path for the log file in both. I have tried this and this works correctly.

I want to do something different. I want to maintain a single log4j.properties file instead of two for both applications. My question is what is the proper way to do this? How?

Sudha
  • 159
  • 3
  • 5
  • 17
  • On Linux, I guess you could use a symbolic link. – Arnaud Jan 21 '16 at 08:52
  • Thank you. What about in Windows? – Sudha Jan 21 '16 at 08:52
  • 1
    This could be achieved with a _resources_ project, from which the other ones would depend. See the accepted answer here : http://stackoverflow.com/questions/17492622/specify-common-resources-in-a-multi-module-maven-project – Arnaud Jan 21 '16 at 09:04
  • That answer is helpful but it would work if both of them were under a single project. In my case they both are independent projects. One way for me to do it would be to create a parent and do as how they have told in the other answer. I want to keep them separate and refer to a single configuration file. I don't know if this is possible. I'm quite new to this. So sorry if I keep asking silly questions. – Sudha Jan 21 '16 at 09:20

1 Answers1

1

You can keep log4j.properties in common location (in Windows c:\boots), refer it in application.properties.

logging.config = C:\boots\log4j.properties
kann
  • 687
  • 10
  • 22
  • Thank you, this worked. Will this work if I were to put it in bootstrap.properties file instead of application.properties? – Sudha Jan 25 '16 at 05:51