Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: EclipseLink support #3

Closed
C-Otto opened this issue Jun 23, 2016 · 2 comments
Closed

Feature request: EclipseLink support #3

C-Otto opened this issue Jun 23, 2016 · 2 comments

Comments

@C-Otto
Copy link
Contributor

C-Otto commented Jun 23, 2016

Currently, the library does not format log messages emitted by EclipseLink. It would be great if (debug) log messages like the one shown below would be printed in the JSON format. I'd appreciate native support, but some guidelines on how to modify the code so that the log messages are routed to SLF4J are also appreciated.

[EL Fine]: sql: 2016-06-23 12:00:12.706--ServerSession(400836922)--Connection(1567361246)--Thread(Thread[http-apr-8080-exec-2,5,main])--SELECT COUNT(ID) FROM XXX
@altenhof
Copy link
Member

Hi @C-Otto,

here's what I did recently:

  • Extend the persistence.xml to use a dedicated logger
  • In that logger write to org.slf4j

See example below - guess we should make it part of our Wiki...

Best

Michael

Example:

src/main/resources/META-INF/persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="jersey-client" transaction-type="RESOURCE_LOCAL">
        <class>com.sap.hcp.perfx.samples.CheckResult</class>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:derby:MyDB;create=true"/>
            <property name="javax.persistence.jdbc.user" value="test"/>
        <property name="javax.persistence.jdbc.user" value="test" />
            <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
            <!-- EclipseLink should create the database schema automatically -->
        <property name="eclipselink.ddl-generation" value="create-tables" />
        <property name="eclipselink.ddl-generation.output-mode" value="database" />
        <property name="eclipselink.logging.logger" value="com.sap.hcp.perfx.samples.ELSlf4jLogger"/>       
        <property name="eclipselink.logging.level" value="FINE"/>
        </properties>
    </persistence-unit>
</persistence>

Dedicated Logger:

public class ELSlf4jLogger extends AbstractSessionLog implements SessionLog {

    private static Logger LOGGER = LoggerFactory.getLogger(ELSlf4jLogger.class);

    @Override
    public void log(SessionLogEntry sessionLogEntry) {
        switch (sessionLogEntry.getLevel()) {
        case SessionLog.SEVERE:
            LOGGER.error(sessionLogEntry.getMessage());
            break;
        case SessionLog.WARNING:
            LOGGER.warn(sessionLogEntry.getMessage());
            break;
        default:
            if (sessionLogEntry.getException() != null) {
                LOGGER.error(sessionLogEntry.getMessage(), sessionLogEntry.getException());
            }
            else {
                LOGGER.info(sessionLogEntry.getMessage());
            }
        }
    }
}

@C-Otto
Copy link
Contributor Author

C-Otto commented Jun 23, 2016

Thank you!

@C-Otto C-Otto closed this as completed Aug 25, 2016
KarstenSchnitter added a commit that referenced this issue Jul 12, 2018
Fix late getRequest and getResponse calls in Tomcat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants