Discussion:
[jboss-user] [JBoss Tools] - Use Log4j logging instead of apache commons logging
Michael Sacauskis
2013-07-18 21:38:23 UTC
Permalink
Michael Sacauskis [https://community.jboss.org/people/msacauskis] created the discussion

"Use Log4j logging instead of apache commons logging"

To view the discussion, visit: https://community.jboss.org/message/828716#828716

--------------------------------------------------------------
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
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/828716#828716]

Start a new discussion in JBoss Tools at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128]
Denis Golovin
2013-07-22 18:28:25 UTC
Permalink
Denis Golovin [https://community.jboss.org/people/dgolovin] created the discussion

"Re: Use Log4j logging instead of apache commons logging"

To view the discussion, visit: https://community.jboss.org/message/829161#829161

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

{code}
${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);
....
{code}
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/829161#829161]

Start a new discussion in JBoss Tools at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128]
Denis Golovin
2013-07-22 22:37:16 UTC
Permalink
Denis Golovin [https://community.jboss.org/people/dgolovin] created the discussion

"Re: Use Log4j logging instead of apache commons logging"

To view the discussion, visit: https://community.jboss.org/message/829186#829186

--------------------------------------------------------------
The commons-logging.jar file includes the JCL API, the default LogFactory implementation and thin-wrapper Log implementations for http://logging.apache.org/log4j/docs/index.html Log4J, http://avalon.apache.org/logkit/index.html 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 youse 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 Coge Generatiion Configuration dialog and point it to ${externalfolder} which contans dao/daohome.ftl file in it
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/829186#829186]

Start a new discussion in JBoss Tools at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128]
Loading...