0

From log4j property file ,I have a need to insert data in multiple tables.

So I need to write multiple query for a jdbc appender for logging to database.

Paul
  • 26,170
  • 12
  • 85
  • 119
Pawan
  • 1
  • 2

2 Answers2

0

Seems that the stock JDBCAppender in log4j-package, or other DB-appenders I found do not allow multiple inserts per log-event.

Attaching 2 JDBCAppenders to log4j could solve your problem. Having 2 appenders would on the other hand cause some transaction overhead, and the rows inserted into database wont have any relation with each other.

Another solution I can think of is writing your own appender, like in the accepted answer of question How to create a own Appender in log4j?

Community
  • 1
  • 1
reap
  • 202
  • 1
  • 4
  • two appender will allow to write only two query ,please suggest about custom appender ,how to achieve this. – Pawan Aug 27 '13 at 11:50
  • The accepted answer in question http://stackoverflow.com/questions/6072389/how-to-create-a-own-appender-in-log4j shows where to start. The actual implementation depends on your logging table structure, but you could use log4j JDBCAppender as example ([JDBCAppender src](http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/jdbc/JDBCAppender.java)) – reap Sep 27 '13 at 05:33
0

Maybe using FlumeAppender would be a good solution to the scenario that you described.

Apache Flume is a distributed, reliable, and available system for efficiently collecting, aggregating, and moving large amounts of log data from many different sources to a centralized data store. The FlumeAppender takes LogEvents and sends them to a Flume agent as serialized Avro events for consumption.

More details in: https://logging.apache.org/log4j/2.x/manual/appenders.html#FlumeAppender

Daniel Reis
  • 850
  • 9
  • 10