On Tue, Oct 10, 2017 at 12:42 AM, [email protected] <[email protected]
> wrote:

>
>
> On 2017-10-06 20:32, Gary Gregory <[email protected]> wrote:
> > Hi,
> >
> > I think you will get better help if you provide a reproducible JUnit test
> > case or program, on GitHub for example.
> >
> > Whenever you mention an Error or Exception, you should copy it in your
> > message.
>

Again?

Gary


> >
> > Gary
> >
> > On Fri, Oct 6, 2017 at 8:48 AM, [email protected] <
> [email protected]>
> > wrote:
> >
> > > Hi log4j2 users,
> > >
> > > I have created a MapMessage with a key-value pair
> > >
> > > e.g. userName="log4j"
> > >
> > > I have configured JDBCAppender with
> > >
> > > <Column name="userName" pattern="%K{userName}"/>
> > >
> > > But, it gives null pointer error when tried to insert into database
> table
> > > using %K/%map/%MAP
> > > and works when you put normal message/literal string.
> > >
> > > Note:
> > > 'userName' is same for Column-name, pattern and MapMessage-key as well.
> > > Using log4j version 2.9.0
> > >
> > > Please help,
> > >
> > > Thanks,
> > > Gaurav
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [email protected]
> > > For additional commands, e-mail: [email protected]
> > >
> > >
> > 1)    Test.java
>
> package com.test;
>
> import org.apache.logging.log4j.*;
> import org.apache.logging.log4j.message.MapMessage;
> import java.util.*;
>
> public class Test {
>
>   public static void main(String[] args) {
>     dbLog();
>   }
>
>   public static void dbLog() {
>     Logger logger = LogManager.getLogger("dbLogger");
>
>     Map<String, String> myMap = new HashMap<>();
>     myMap.put("username", "123456");
>     logger.error(new MapMessage(myMap));
>   }
> }
>
> 2)      log4j2.xml
>
> <Configuration status="info" name="myConfig">
>     <Appenders>
>         <JDBC name="databaseAppender" tableName="temp">
>             <ConnectionFactory class="com.database.ConnectionFactory"
> method="getDatabaseConnection"/>
>             <Column name="username" pattern="%K{username}"/>
>         </JDBC>
>     </Appenders>
>     <Loggers>
>         <Logger name="dbLogger" level="error" additivity="false">
>             <AppenderRef ref="databaseAppender"/>
>         </Logger>
>
>         <Root level="ERROR">
>             <AppenderRef ref="Console1"/>
>         </Root>
>     </Loggers>
> </Configuration>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to