[hibernate-dev] Obtaining loggers

Steve Ebersole steve at hibernate.org
Tue May 21 17:24:05 EDT 2013


Forgot...  So really this just allows more conciseness in obtaining the 
logger.  So from:

private static final CoreMessageLogger LOG = Logger.getMessageLogger( 
CoreMessageLogger.class, CollectionLoadContext.class.getName() );

to:

private static final CoreMessageLogger LOG = CoreLogging.messageLogger( 
CollectionLoadContext.class );


On 05/21/2013 04:21 PM, Steve Ebersole wrote:
> I was getting tired of statements in the source code to get logger 
> instances that spread across sometimes 4 lines because of JBoss 
> Logging's verbose means of acquiring a message logger.  So I created a 
> more concise form for this for hibernate-core, hibernate-entitymanager 
> and hibernate-envers.  I mainly limited it to these projects because 
> they have lots of these calls, whereas the others do not.  Feel free 
> to copy the approach to the other projects if someone wants.
>
> Essentially each of those projects define a class with 4 static 
> methods.  Taking the hibernate-core one as an example:
>
>
> import org.jboss.logging.Logger;
>
> /**
>  * Quite sad, really, when you need helpers for generating loggers...
>  *
>  * @author Steve Ebersole
>  */
> public class CoreLogging {
>     /**
>      * Disallow instantiation
>      */
>     private CoreLogging() {
>     }
>
>     public static CoreMessageLogger messageLogger(Class 
> classNeedingLogging) {
>         return messageLogger( classNeedingLogging.getName() );
>     }
>
>     public static CoreMessageLogger messageLogger(String loggerName) {
>         return Logger.getMessageLogger( CoreMessageLogger.class, 
> loggerName );
>     }
>
>     public static Logger logger(Class classNeedingLogging) {
>         return Logger.getLogger( classNeedingLogging );
>     }
>
>     public static Logger logger(String loggerName) {
>         return Logger.getLogger( loggerName );
>     }
> }
>
> I just plan on replacing these calls as opportunities arise, rather 
> than all in one fell swoop.



More information about the hibernate-dev mailing list