[ 
https://issues.apache.org/jira/browse/LOG4J2-2757?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17014486#comment-17014486
 ] 

Gary D. Gregory commented on LOG4J2-2757:
-----------------------------------------

You should try to use a $$ instead of $ in your config.

> 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
>            Priority: Major
>
> 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: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?



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

Reply via email to