Null pointer error when writing MapMessage key's value to database
Hi log4j2 users, I have created a MapMessage with a key-value pair e.g. userName="log4j" I have configured JDBCAppender with 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]
Re: Fetch message values in JDBCAppender
On 2017-10-07 04:27, Matt Sicker wrote: > Can you post your config and log4j version? > > On 6 October 2017 at 00:25, gaurav deshpande wrote: > > > Please help > > -- Forwarded message -- > > From: "gaurav deshpande" > > Date: 06-Oct-2017 02:19 > > Subject: Fetch message values in JDBCAppender > > To: > > Cc: > > > > Hi log4j2 users, > > > > I have created custom-message implementing 'message' interface. > > > > I have also created JDBCAppender which writes values from above message to > > database table. > > > > But how do I get the value from custom message and store it into databse? > > > > I've tried pattern attribute in column tag but thats not working. > > > > Input: custom message > > Output: store it into database table > > > > Please help, > > > > Thanks, > > Gaurav > > > > > > -- > Matt Sicker > log4j version:2.9.0 > - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: Null pointer error when writing MapMessage key's value to database
On 2017-10-06 20:32, Gary Gregory 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. > > Gary > > On Fri, Oct 6, 2017 at 8:48 AM, [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 > > > > > > > > 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 myMap = new HashMap<>(); myMap.put("username", "123456"); logger.error(new MapMessage(myMap)); } } 2) log4j2.xml - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
How to store custom-message variable values to the database table's column using log4j2
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: [email protected] For additional commands, e-mail: [email protected]
Re: How to store custom-message variable values to the database table's column using log4j2
On 2017-10-11 00:49, Matt Sicker 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, [email protected] > 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: [email protected] > > For additional commands, e-mail: [email protected] > > > > > > > -- > Matt Sicker > No. Here, they are taking the whole message I dont want that. e.g. What I want is following: when we execute logger.info(new MyMessage("temp","1234","[email protected]")); then it should write into a table name idemail temp 1234 [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: Null pointer error when writing MapMessage key's value to database
On 2017-10-11 04:29, Gary Gregory wrote: > On Tue, Oct 10, 2017 at 12:42 AM, [email protected] > wrote: > > > > > > > On 2017-10-06 20:32, Gary Gregory 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 > > > > > > > > > > > > > > > > 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 myMap = new HashMap<>(); > > myMap.put("username", "123456"); > > logger.error(new MapMessage(myMap)); > > } > > } > > > > 2) log4j2.xml > > > > > > > > > > > method="getDatabaseConnection"/> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > - > > To unsubscribe, e-mail: [email protected] > > For additional commands, e-mail: [email protected] > > > > > The pattern="%K{username}" is not working - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
How do I create jdbc appender using programmatic configuration?
Hi log4j2 users, I want to create jdbc appender using programmatic configuration. Please provide the programmatic configuration if you already have or guide me to create it. P.S. I am able to create JDBCAppender using xml configuration Thanks - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: How do I create jdbc appender using programmatic configuration?
On 2017-11-30 23:07, Matt Sicker wrote: > You should be able to create one the same way you create any other appender > using programmatic configuration. > > On 30 November 2017 at 06:36, [email protected] > wrote: > > > Hi log4j2 users, > > > > I want to create jdbc appender using programmatic configuration. > > > > Please provide the programmatic configuration if you already have or guide > > me to create it. > > > > P.S. I am able to create JDBCAppender using xml configuration > > > > Thanks > > > > - > > To unsubscribe, e-mail: [email protected] > > For additional commands, e-mail: [email protected] > > > > > > > -- > Matt Sicker > Hi Matt, I am able to add "tableName" attribute for JDBC AppenderComponentBuilder But not the remaining stuff like ConnectionFactory class,method and Columns. Please help - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: How do I create jdbc appender using programmatic configuration?
On 2017-12-01 14:34, "[email protected]" wrote: > > > On 2017-11-30 23:07, Matt Sicker wrote: > > You should be able to create one the same way you create any other appender > > using programmatic configuration. > > > > On 30 November 2017 at 06:36, [email protected] > > wrote: > > > > > Hi log4j2 users, > > > > > > I want to create jdbc appender using programmatic configuration. > > > > > > Please provide the programmatic configuration if you already have or guide > > > me to create it. > > > > > > P.S. I am able to create JDBCAppender using xml configuration > > > > > > Thanks > > > > > > - > > > To unsubscribe, e-mail: [email protected] > > > For additional commands, e-mail: [email protected] > > > > > > > > > > > > -- > > Matt Sicker > > Hi Matt, > > I am able to add "tableName" attribute for JDBC AppenderComponentBuilder > But not the remaining stuff like > ConnectionFactory class,method and Columns. > > Please help > > > - > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > What I've tried until now: ConfigurationBuilder builder = ConfigurationBuilderFactory.newConfigurationBuilder(); builder.setConfigurationName("myConfig"); builder.setStatusLevel(Level.ERROR); ColumnConfig[] columnConfigs = new ColumnConfig[] { ColumnConfig.newBuilder() // .setConfiguration(builder.) .setName("myUsername") .setPattern("") .setLiteral("%X{username}") .setEventTimestamp(false) .setUnicode(false) .setClob(false) .build(), ColumnConfig.newBuilder() // .setConfiguration(this) .setName("myAction") .setPattern("%X{action}") .setLiteral(null) .setEventTimestamp(false) .setUnicode(false) .setClob(false) .build(), ColumnConfig.newBuilder() // .setConfiguration(this) .setName("myTimeStamp") .setPattern(null) .setLiteral(null) .setEventTimestamp(true) .setUnicode(false) .setClob(false) .build() }; ConnectionSource factoryMethodConnectionSource = FactoryMethodConnectionSource.createConnectionSource( "com.database.ConnectionFactory", "getDatabaseConnection"); AppenderComponentBuilder appenderBuilder = builder .newAppender("databaseAppender", "JDBC") .addAttribute("tableName", âmyTableâ); builder.add(appenderBuilder); builder.add( builder .newLogger("DbLogger", Level.DEBUG) .add(builder.newAppenderRef("databaseAppender")) .addAttribute("additivity", false)); LoggerContext ctx = Configurator.initialize(builder.build()); - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
How to get the JDBC connection close() control from log4j2
Hi, My project uses custom-connection pool and wants to control connection close. But log4j2's JDBC appender uses its own Closer.close() method call in the JdbcDatabaseManager.java Is there any way to get the control for close() method to my project code instead of log4j2? Will it be okay to create own custom-plugin instead of using JDBCAppender? Please help. Thanks, Gaurav - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
