2 Replies Latest reply on May 1, 2014 10:54 PM by Ramesh Reddy

    Custom JPA Logging Appender

    Ramesh Reddy Master



      For Teiid project http://teiid.org, we have a need to write certain log messages to database. Unfortunately the Log4J JDBCAppender does not works us, and Log4J 2.x support not in the JBoss AS yet. What I am after is a JPA based Log Appender. My question is, what is best way to implement this for JBoss EAP 6.1.Alpha


      1) Write a Stateless Bean that does the JPA tasks, which can be bean can be invoked from custom Log Appender?

      2) Log Appender class to do the JPA tasks directly, and avoid the bean. However, I am not sure I could @Inject EntityManager into Log Appender to do the dbms operations in this scenario.


      Can someone please give guidance, what may be better way to do this?





        • 1. Re: Custom JPA Logging Appender
          James Perkins Master

          You wouldn't really be able to have a handler (appender) that could use JPA. Logging is generally one of the first things configured. This would be well before JPA is setup.


          It should be rather easy though to create a java.util.logging.Handler or org.jboss.logmanager.ExtHandler that uses JDBC though. You'd just need to configure a JDBC connection then handle the insert in the publish or doPublish method.


          Then you would just add this as a module to EAP 6 and configure a custom-handler in the logging subsystem.



          James R. Perkins

          • 2. Re: Custom JPA Logging Appender
            Ramesh Reddy Master



            Thank you. Yes, we have one we developed using straight JDBC, My choice of JPA was to get away from


            * custom DDL/DML statements

            * ability plug-in target databases ad-hoc, and start logging

            * not worry about any minor SQL syntax differences

            * connection/transaction management


            Luckily in our usecase it used for "autdit" related messages, so I am expecting messages to only flow after system is completely started, so I would be able to lookup the bean locally in the container and issue the JPA call. Logging to database itself is so heavy weight, I am concerned that, I may be over thinking in adding additional complexity with all the layers. Eventually the idea is to plug-in sources like Hive or time series databases to capture this log data for effective querying.