WebSphere (8.5.5) does not logging OpenJPA

后端 未结 2 1328
一个人的身影
一个人的身影 2021-01-25 05:48

I\'m interested in logging SQL statements. I\'ve tried two approaches, with log4j2 and writing to file, both in vain.

I\'ve added following lines to persistence.xm

相关标签:
2条回答
  • 2021-01-25 06:34

    First, an aside: you have this in your persistence.xml file:

    <property name="openjpa.Log" value="SQL=TRACE" />
    <property name="openjpa.Log" value="File=openjpa_ra.log" />
    

    Only ONE of these will take effect. That is, just like any Java properties, they are not cumulative, OpenJPA will not combine these two Log settings, but will rather only use one (likely the last one processed). The above should be combined like this:

    <property name="openjpa.Log" value="SQL=TRACE, File=openjpa_ra.log" />
    

    Next, let me answer your question at hand: If you are using container managed persistence (e.g. @PersistenceContext), then the trace settings in your persistence.xml file are ignored. This is because tracing is handled by the container/WAS when container managed is used. To explain this, please look at this document:

    http://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/tejb_loggingwjpa.html

    In particular, see this warning:

    Avoid trouble: The openjpa.Log property is ignored if it is defined in a container-managed persistence unit that uses the persistence providers that are provided with the application server. In this case, you must use the standard trace specification for the application server.

    If you go into the admin console, you can set the location of your trace output. But I don't believe there is a way to change from using WAS trace to log4j. When the jpa provider is running in WAS, jeeruntime component takes over the logging functions between WAS's Trace and OpenJPA's Log interface, hence the "Avoid trouble" statement in infoCenter and the reference of "trace specification for the application server". In WAS, you will have to use the trace specification, e.g. openjpa=all:JPA=all or openjpa.jdbc.SQL=all, the latter will give you just SQL trace, the former all JPA trace. Bottom line is you will not be able to redirect only OpenJPA/JPA trace to a single file when container managed is used.

    If you are not using container managed, then this should print SQL tract to file openjpa_ra.log:

    <property name="openjpa.Log" value="SQL=TRACE, File=openjpa_ra.log" />
    

    I would try this, and this only.....I think the Log setting you added to your 'update' might be too convoluted. If you are not using container managed persistence, then WAS logging is not involved, and the Log settings will be honored. Furthermore, you should be able to use Log4j. The use of Log4j is documented in OpenJPA docs here:

    http://openjpa.apache.org/builds/2.2.2/apache-openjpa/docs/manual#ref_guide_logging_log4j

    I hope this helps, please let me know if you need more details.

    Thanks,

    Heath

    0 讨论(0)
  • 2021-01-25 06:49

    Anton , chances are the log4j configuration is overridden in one of a previously loaded component in the application server.

    Your best bet to figure out what is happening could be to change the trace levels on the server side specifically for open JPA with the right trace level strings.

    You can navigate to change logging detail (follow the crumb on the image) and use a trace string for open JPA (*=info: openjpa.Query=all: openjpa.jdbc_JDBC=all: openjpa.jdbc_SQL=all). Changes in configuration will need a reboot of the server.

    0 讨论(0)
提交回复
热议问题