Java examples for Java Virtual Machine:Logger
Logging a Method Call
import java.util.logging.Level; import java.util.logging.Logger; public class Main { public boolean myMethod(int p1, Object p2) { // Log entry//from ww w . j av a 2 s . c o m Logger logger = Logger.getLogger("com.mycompany.MyClass"); if (logger.isLoggable(Level.FINER)) { logger.entering(this.getClass().getName(), "myMethod", new Object[] { new Integer(p1), p2 }); } // Method body // Log exit boolean result = true; if (logger.isLoggable(Level.FINER)) { logger .exiting(this.getClass().getName(), "myMethod", new Boolean(result)); // Use the following if the method does not return a value logger.exiting(this.getClass().getName(), "myMethod"); } return result; } }