Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2757

JDBCAppender tableName from Main Arguments Lookup

    XMLWordPrintableJSON

Details

    • Question
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 2.13.0
    • None
    • Appenders, JDBC
    • None

    Description

      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. 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.

          <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>
      

      This is what I use in Main.java to set the arguments:

      MainMapLookup.setMainArguments(new String[] { "--prefix", tablesPrefix });

      Unfortunately, this does not seem to work. The JDBCAppender keeps reading the tableName parameter verbatim as ${main:1}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?

      Attachments

        Activity

          People

            Unassigned Unassigned
            ppetrov_mp Petar Petrov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: