Source Code : Java log: various log methods
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Java log: various log methods

/*
Logging In Java with the JDK 1.4 Logging API and Apache log4j
by Samudra Gupta
Apress Copyright 2003
ISBN:1590590996
*/
import java.util.logging.*;
import java.io.IOException;
public class LogMethods {
private static Logger logger = Logger.getLogger("sam.logging");
public LogMethods()
{
//first obtain the logmanager instance
LogManager manager = LogManager.getLogManager();
//remove all the associated handlers with this manager
manager.reset();
//create a new handler for the logger to write messages
// to the console
ConsoleHandler ch = new ConsoleHandler();
ch.setLevel(Level.FINEST);
//setting the logger level and handler
logger.setLevel(Level.FINEST);
logger.addHandler(ch);
}
/**
* This method demonstrates the basic logging methods
*/
public void printBasicMethods()
{
logger.log(Level.INFO, "THIS IS INFO LEVEL MESSAGE");
//creating a log record on our own
LogRecord record = new LogRecord(Level.SEVERE, "OUR OWN LOGRECORD OBJECT");
//logging the log record object
logger.log(record);
}
/**
* This method demonstrates the precise logging methods
*/
public void printPreciseMethods()
{
logger.logp(Level.INFO, "LogMethods", "printPreciseMethods","PRECISE METHODS..");
}
/**
* This method demonstrates the level based logging methods
*/
public void printLevelMethods()
{
logger.fine("THIS IS A FINE LEVEL MESSAGE");
logger.finer("THIS IS A FINER LEVEL MESSAGE");
logger.finest("THIS IS A FINEST LEVEL MESSAGE");
logger.config("THIS IS CONFIG LEVEL MESSAGE");
}
/**
*This method demonstrates the method level logging methods
*/
public void printMethod()
{
logger.entering("LogMethods", "printMethod");
logger.exiting("LogMethods", "printMethod");
}
public static void main(String[] args)
{
LogMethods lm = new LogMethods();
lm.printBasicMethods();
lm.printPreciseMethods();
lm.printLevelMethods();
lm.printMethod();
}
}
Thank with us