2 Replies Latest reply on Jul 22, 2013 6:38 PM by Denis Golovin

    Use Log4j logging instead of apache commons logging

    Michael Sacauskis Newbie

      Hi

       

      I'm using hibernate tools in eclipise juno.  When I generate DAO code it generates imports and logging code for apache commons logging.  My project uses log4j, is there a way to change what logger is used in generated code?

       

      Thanks

       

      Mike

        • 1. Re: Use Log4j logging instead of apache commons logging
          Denis Golovin Master

          It seems there is no easy way, because it is hardcoded in daohome.ftl template inside hibernate-tools-4.0.0.jar as

           

           

          ${pojo.getPackageDeclaration()}

          // Generated ${date} by Hibernate Tools ${version}

           

           

          <#assign classbody>

          <#assign declarationName = pojo.importType(pojo.getDeclarationName())>/**

          * Home object for domain model class ${declarationName}.

          * @see ${pojo.getQualifiedDeclarationName()}

          * @author Hibernate Tools

          */

          <#if ejb3>

          @${pojo.importType("javax.ejb.Stateless")}

          </#if>

          public class ${declarationName}Home {

           

           

              private static final ${pojo.importType("org.apache.commons.logging.Log")} log = ${pojo.importType("org.apache.commons.logging.LogFactory")}.getLog(${pojo.getDeclarationName()}Home.class);

          ....

          • 2. Re: Use Log4j logging instead of apache commons logging
            Denis Golovin Master

            Considering what is stated in apache common logging documentation:

            The commons-logging.jar file includes the JCL API, the default LogFactory implementation and thin-wrapper Log implementations for Log4J, Avalon LogKit, the Avalon Framework's logging infrastructure, JDK 1.4, as well as an implementation of JDK 1.4 logging APIs (JSR-47) for pre-1.4 systems.

            In most cases, including commons-logging.jar and your preferred logging implementation in the classpath should be all that is required to use JCL.

             

            you probably do not need to change anything, because generated classes should use log4j through common logging interface. If you need do use log4j classes directly, then there is a workaround for that, which includes:

            1. Copying dao/daohome.ftl template from hibernate-tools.jar to ${externalfolder}
            2. Change it to your needs
            3. Configure template location property for exporter in Hibernate Code Generatiion Configuration dialog and point it to ${externalfolder} which contains dao/daohome.ftl file in it