Search code examples
javaspring-bootlog4j2tomcat8

How to get server path in spring boot rest api


I have one server on which two tomcat server has been configured. I have deployed a spring boot API war on both tomcat. But both server API writing logs in same file mentioned in the logger configuration file.

logging.config=//home//user//config//testlog4j2.properties

I want to separate log file for both server using same war. Is there any option to get server path like ../tomcat/temp in application.properties


Solution

  • You can use an environment variable.

    Let say you define the environment variable TOMCAT_LOG_DIR=/path/to/tomcat/location/log for both servers.

    In application.properties just put:

    logging.config=${TOMCAT_LOG_DIR}/testlog4j2.properties
    

    Now you can deploy it on both servers.

    Note

    log4j is initialized on application startup.