private static Logger logger = Logger.getLogger( MyClass.class );Are you tired of writing the same line of code over and over again?
No more!
Using the Eclipse templates you can generate this code easily.
Create the template by clicking Window -> Preferences -> Java -> Editor -> Templates -> New
Enter the template name
logger
Enter the pattern
private static Logger logger = Logger.getLogger( ${enclosing_type}.class ); ${:import(org.apache.log4j.Logger)}This pattern also takes care of the import statement.
Now see it in action:
Thanks for this one...... I really appreciate these small improvements.
ReplyDeletesmall tip but very useful thanks very muhc
ReplyDeleteThanks a lot ............
ReplyDeleteGreat post!
ReplyDeleteGreat post! Very nice addition :-)
ReplyDeleteIf someone prefers Commons Logging the template could look like this:
private static final Log log = LogFactory.getLog( ${enclosing_type}.class );
${:import(org.apache.commons.logging.Log,org.apache.commons.logging.LogFactory)}
If you want this to happen automatically when you create a new class http://javatechtalkies.blogspot.com/2010/05/eclipse-create-class-with-logger-member.html
ReplyDeleteThanks. Slf4j is:
ReplyDeleteprivate static Logger logger = LoggerFactory.getLogger(${enclosing_type}.class);
${:import(org.slf4j.Logger, org.slf4j.LoggerFactory)}