Dashboard > LAMS 2 > ... > Best Practices > Logging with Log4J
  LAMS 2 Log In | Sign Up   View a printable version of the current page.  
  Logging with Log4J
Added by Fiona Malikoff , last edited by Fiona Malikoff on Jul 21, 2005  (view change)
Labels: 
(None)

Logging

All logging is done using Log4j (http://logging.apache.org/log4j/).

At the top of your class, define a static logger:

Then when putting in a log statement, you just do:

Please think about the log levels and use appropriately. Your code should have more than just log.debug statements! There is also info, warn, error, etc!

Also remember to use isDebugEnabled() appropriately. If your debug statement would take some effort to generate then stop the call occuring using isDebugEnabled(). But if the log message is very simple (say a concatenation of two strings), then it isn't worthwhile using isDebugEnabled(). This will help performance.

For example, assume you have an object blah that has a toString method that prints the values of 15 fields and contains some other complex objects, when method validateBlah(Blah blah) is called. If the log statement wanta to dump out the object then do:

If all you are just logging the entry into the method don't bother with the log.isDebugEnabled() statement:

Powered by a free Atlassian Confluence Open Source Project License granted to Learning Activity Management System (LAMS). Evaluate Confluence today.
Powered by Atlassian Confluence 2.7.3, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators