Log4j2 how to read a property variable from a file in log4j2

Background: As usual, we have different life cycles, such as dev. stage, lt, prod they are all selected during deployment from the environment variable $ {lifecycle}. Thus, the JNDI parameter is stored in $ {lifecycle} .properties as the variable datasource.jndi.name = jdbc / xxx. Since other beans also use this properties file, it is verified that such a variable is loaded and the file is in the classpath, but somehow I cannot use this variable in log4j2.xml below the JDBC Appender.

<JDBC name="DBAppender" tableName="V1_QUERY_LOG" bufferSize="4" ignoreExceptions="false">
    <DataSource jndiName="${sys:datasource.jndi.name}" />
    <Column name="event_date" isUnicode="false" isEventTimestamp="true" />
    <Column name="log_level" isUnicode="false" pattern="%level" />
    <Column name="logger" isUnicode="false" pattern="%logger" />
    <Column name="message" isUnicode="false" pattern="%message" />
    <Column name="exception_msg" isUnicode="false" pattern="%ex{full}" />
</JDBC>

I also tried the option "$ {datasource.jndi.name}" or is there a way that I can match the solution in

<Properties>
 <Property name="datasource.jndi.name">get datasource.jndi.name from {lifecycle}.properties</property>
</Properties>
+4
2
+6

, Spring bean, Log4j. , .

, ${sys:something} Java. JVM -Dkey=value .

${bundle:MyProperties:MyKey}, Spring.

. :

+5

Source: https://habr.com/ru/post/1532180/


All Articles