Well, pattern converters like that are for serializing a LogEvent to a
string. You could split up your message keys like this:

<ColumnMapping name="name" pattern="%K{name}"/>
<ColumnMapping name="id" pattern="%K{id}"/>
<ColumnMapping name="email" pattern="%K{email}"/>

Another option might be to use MessageLayout <
https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/MessageLayout.java>
combined with a custom appender.


On 11 October 2017 at 00:19, gaurav9...@gmail.com <gaurav9...@gmail.com>
wrote:

>
>
> On 2017-10-11 00:49, Matt Sicker <boa...@gmail.com> wrote:
> > Are you using ColumnMapping? See <
> > https://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender
> >.
> >
> > See <
> > https://github.com/apache/logging-log4j2/blob/master/
> log4j-nosql/src/test/resources/CassandraAppenderTest.xml>
> > for example usage (even though that uses the CassandraAppender, the same
> > ColumnMapping element works in JdbcAppender).
> >
> > On 10 October 2017 at 09:03, gaurav9...@gmail.com <gaurav9...@gmail.com>
> > wrote:
> >
> > > Hi Log4j2 users,
> > >
> > > I've created custom-message implementing log4j2's 'message' interface
> like
> > > following tutorial
> > > https://logging.apache.org/log4j/2.x/manual/messages.html
> > >
> > > I've defined JDBCAppender in lo4j2.xml which writes values from above
> > > message to database table.
> > > I've tried using conversion-pattern %m in the Column configuration but
> it
> > > stores the whole message.
> > > Which conversion-pattern to use here to get specific variable values
> and
> > > writing them in the table's column?
> > >
> > > Link to Stackoverflow question: https://stackoverflow.com/
> > > questions/46668645/store-custom-message-variable-
> > > values-to-the-database-tables-column-using-log4j2
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> > > For additional commands, e-mail: log4j-user-h...@logging.apache.org
> > >
> > >
> >
> >
> > --
> > Matt Sicker <boa...@gmail.com>
> >
>
> No.
> Here, they are taking the whole message
>
> <ColumnMapping name="message" pattern="%message"/>
>
> I dont want that.
>
> e.g.
> What I want is following:
>
> when we execute
> logger.info(new MyMessage("temp","1234","a...@gmail.com"));
>
> then it should write into a table
>
> name  id        email
> temp   1234   a...@gmail.com
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


-- 
Matt Sicker <boa...@gmail.com>

Reply via email to