Using ADF Logging
When I review code for ADF projects, I often see poor or inconsistent logging. Sometimes I even don't see any logging at all! I find this strange and inexplicable, because ADF makes it really easy to add good logging to your application without slowing it down. When all your logging is done with the ADF logger, you can set and change the log level at runtime on all environments through Enterprise Manager or by editing the log configuration file.
Adding a Logger
Every piece of non-trivial Java code in your application should register its own logger like this:
public MyBean {
private final ADFLogger logger =
ADFLogger.createADFLogger(MyBean.class);
You need to refer to the class that contains the logger in the create method so that you can tell the loggers apart and configure them individually.
Once you have a logger object, you can use the methods on it to log messages with various log levels.
Choosing a Log Level
In order to ensure that your project uses log levels consistently, your developer handbook/guidelines/wiki needs to set down some rules. I propose the following in my ADF tutorial book:
- SEVERE for critical errors that your operations staff needs to know about
- WARNING should indicate misconfigurations, missing data or failures from other components or external systems
- CONFIG is for information read from property files and configuration databases as well as initialization of classes
- FINE is information about method calls and should only be used once or twice in a method (when entering and/or when leaving, showing parameters and return values)
- FINER is detailed logging of steps within a method
- FINEST is for logging inside loops.
Business Level Logging
I've found that it is a good idea to produce specific logging for business users, and I recommend reserving the INFO level for this. Most logging is very technical and intended for either other developers or operations staff, but the INFO logging should use business terms. For example: "Order 456472 was placed on hold because item Medium Red Widget is not in stock." This allows you to extract these logs and show them to the business to explain why the system works the way it does.
|