LoginSignup
7
7

More than 5 years have passed since last update.

EclipseLinkのログをSlf4Jにブリッジする

Last updated at Posted at 2014-06-17

EclipseLinkではjava.util.loggingを使っているため、そのままではSLF4Jとは別にロギングしていまいます。ロギングをSLF4Jに一本化するために、独自のSessionLogを実装します。
SessionLoggerの実装はここを参考にしました。EclipseLink側のログレベルの方が細かいので、お好みでマッピングしてください。
あとはSessionCustmizerで作成したSessionLoggerを設定し、persistence.xmlに追記したらOK!

persistence.xml
<properties>
  <property name="eclipselink.session.customizer" value="misc.jpa.JpaSessionCustomizer"/>
</properties>
JpaSessionCustomizer.java
package misc.jpa;

import org.eclipse.persistence.config.SessionCustomizer;
import org.eclipse.persistence.sessions.Session;

public class JpaSessionCustomizer implements SessionCustomizer {

    @Override
    public void customize(Session sn) throws Exception {
        sn.setSessionLog(new Slf4jSessionLogger());
    }

}
7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7