import java.util.logging.*; public class SimpleLogging { static final Logger log = Logger.getLogger("Simple Log"); void processData(){ log.info("About to start processing data"); /* Do some processing here */ log.info("Finished procesing data"); } public static void main(String args[]){ SimpleLogging myLog = new SimpleLogging(); myLog.processData(); } }
Output
Jul 24, 2014 2:14:51 PM logger.SimpleLogging processData INFO: About to start processing data Jul 24, 2014 2:14:52 PM logger.SimpleLogging processData INFO: Finished procesing data
static
final Logger log = Logger.getLogger("Simple Log");
Above
statement creates a logger with the name 'Simple Log'. If a logger
with the name 'Simple Log' exist already, then the existed logger is
returned.
log.info("About
to start processing data");
Above
statement logs the information message. By default, the information
messages are logged to console. So that only you are seeing the
logged messages in console.
No comments:
Post a Comment