JLF Logging Framework Quick Start Guide
Purpose
The JLF Logging Framework is a reusable and extensible class library to help you log events in your Java code.
Today this framework only logs output to the standard error stream, a file, or a
set of email addresses (via SMTP), but you can easily extend the framework to
add your own logging mechanisms to, for example, a centralized database or the
JDK 1.4 logging framework. As with all good object designs, as such mechanisms are added, none of
the logging framework client source code.
Quick Start Notes
- Configure JLF as described here.
- Create your own application log. Say your application is named MyApp. Copy the file
AppLog.java
into your project, rename it to your project name (say MyAppLog.java), do a find/replace all on AppLog to
MyAppLog,
and change the package name from org.jlf.log to your package name.
- Instead of writing statements like System.err.println("Exception encountered:
" + e);, write a statement like MyAppLog.error("Exception encountered:
" + e);
- Instead of adding statements like System.out.println("In method calculateOrder()
for customer " + customer); for debugging, then removing or commenting them out later, add and leave
significant events using a statement like MyAppLog.info("In
method calculateOrder() for customer " + customer);
- Anytime you execute a SQL statement in your code (this is a major event that needs to be logged!), first log
it with a statement like SQLLog.info("Executing SQL statement " + statement);.
AppLog and SQLLog are logs defined in the com.bestbuy.log package, you will have to import them any time you use
them.
- If catching an exception or error, you can log the fact that it happened (complete with a stack trace!!!) and
re-throw it all in one statement with the help of the AppError class. Example: throw
new AppError("Caught critical exception " + e, e,
MyAppLog.getInstance(), Log.CRITICAL_ERROR_LEVEL)
- If you want to time events in your code and report the time to a log
under certain circumstances (you can even alert people if the timer takes
too long!) check out the AppInstrument
class.
See Framework Details for more information on how the framework works, how you
can configure the logs, and how you can extend the framework.