You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Petar Petrov (Jira)" <ji...@apache.org> on 2020/01/13 09:12:00 UTC

[jira] [Created] (LOG4J2-2757) JDBCAppender tableName from Main Arguments Lookup

Petar Petrov created LOG4J2-2757:
------------------------------------

             Summary: JDBCAppender tableName from Main Arguments Lookup
                 Key: LOG4J2-2757
                 URL: https://issues.apache.org/jira/browse/LOG4J2-2757
             Project: Log4j 2
          Issue Type: Question
          Components: Appenders, JDBC
    Affects Versions: 2.13.0
            Reporter: Petar Petrov


Hi, 

I've posted this on StackOverflow, however, I could not really get any solution there.

There is a JDBCAppender in my application to which I'd like to set the *tableName* parameter from a [main argument lookup|http://logging.apache.org/log4j/2.x/manual/lookups.html#AppMainArgsLookup]. Reason for this is that my database table may optionally have a prefix, so I'm reading this from a configuration file in my application and I'd like to apply it to the appender at runtime.
{code:java}
    <JDBC name="TaskLogJDBC" tableName="${main:1}LogEvents">
        <ConnectionFactory class="my.package.name.ConnectionFactory" method="getConnection"/>
        <Column name="created_on" isEventTimestamp="true"/>
        <Column name="lvl" pattern="%level"/>
        <Column name="logger" pattern="%logger"/>
        <Column name="message" pattern="%message"/>
        <Column name="throwable" pattern="%ex{full}"/>
    </JDBC>
{code}
This is what I use in *Main.java* to set the arguments:
{code:java}
MainMapLookup.setMainArguments(new String[] { "--prefix", tablesPrefix });{code}
Unfortunately, this does not seem to work. The JDBCAppender keeps reading the *tableName* parameter verbatim as _${main:0}LogEvents_ instead of _prefix_LogEvents_. I traced it and I think the JDBCAppender configuration read happens before the *MainMapLookup.setMainArguments()* gets called.

Environment variable lookup is an option, but I'd like to avoid it at this point. Are there any other options or am I doing something wrong?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)