My company has an environment management tool that enables you to look up properties from the environment programmatically in Java. I want to leverage this tool to configure logback. For example, suppose I have a logback.xml as follows (the file appender section in particular):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- console appender -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd/HH:mm:ss.SSS} [%thread] %-5level %logger{20}: %msg%n</pattern>
</encoder>
</appender>
<!-- file appender -->
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${LOG_FILE:-/default/log/file/path</file>
<encoder>
<pattern>%d{yyyy-MM-dd/HH:mm:ss.SSS} [%thread] %-5level %logger{20}: %msg%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
</configuration>
So, in this case, I want to look up the LOG_FILE property from the environment (or OS, if you will), and pass it to logback before logback loads the logback.xml so that it will know the value of LOG_FILE. So, how can I achieve that? BTW, I know how to define a file appender programmatically, but that's not what I want here.
Thank you very much.