Enabling Logging on Existing Code
The most basic example shows as follows:
ContactListHandler.java |
01 package cyber.web.form.test.xcontact;
02
03 import cyber.web.form.*;
04 import cyber.web.form.tools.VelocityServletHelper;
05
06 import org.jdom.*;
07 import org.apache.log4j.Logger;
08 import org.apache.velocity.*;
09 import org.apache.velocity.context.Context;
10
11 /**
12 * @author cying
13 *
14 * To change the template for this generated type comment go to
15 * Window>Preferences>Java>Code Generation>Code and Comments
16 */
17 public class ContactListHandler implements XFormHandler
18 {
19 static Logger logger = Logger.getLogger(ContactListHandler.class);
|
The marked 07 line shows how to import the Logger class.
The marked 19 line shows how to define static per-class logger. This is the
most common use of the Logger.
¡@
After you defined the Logger, you will want to use it in your code:
ContactListHandler.java |
01 public boolean onXFormEvent(XFormEvent evt)
02 {
03 switch (evt.getEvent())
04 {
05 case XFormEvent.EVENT_PROCESS_FORWARD :
06 {
07 if (evt.isForwardAction("delete"))
08 {
09 logger.debug("Delete action");
10 evt.getForm().getElement().detach();
11 return true;
12 } |