Java error log

Java error log is a error that arises due to internal error. A error logger is simple an object that is used to show an error log message for a specifice system and component used in an application.

Java error log

Java error log

     

Java error log is a error that arises due to internal error. A error logger is simple an object that is used to show an error log message for a specifice system and component used in an application.

In this Tutorial we want to describe you a code that show a java error log, for this we have  a Class name'javaerrorlog' .Inside the class name we have a private static  variable logger that returns you a logger name according to  name of the parameter passed in it by calling a method name get Logger(). Inside the main static method ( ) . The class file handler is inherited from java.util.logging.The function of file handler is to either write in the specified file used in your programming. The file handler write to a specified file i.e. log.txt and store in a object of class File Handler name 'handler'.

 

 

Now understand list of method used in code-

add Handler This is used to add a handler in order to receive  logging message.
set Level This method returns you or set the level for a  globally registered method. In brief you can say this  is used to set the log level message specify the message logged by the specified user.
info

This method return you an info  message to you. The code consists of try-catch block to check the exception arises in code. for every subsequent try block there is a catch block that consists of a method name.

log  This method return you log a log record.

code to understand java log error


import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

public class javaerrorlog {
private static Logger l = Logger.getLogger("");
 
  public static void main(String args[]) throws Exception
  FileHandler handler = new FileHandler("log.txt");
 l.addHandler(handler);
 
  l.setLevel(Level.ALL);
 
  l.info("Error logs");
  try {
  
  catch (Error ex) {
  l.log(Level.INFO, "", ex);
  }
  l.fine("");
  }
}

Output
compile-single:
run-single:
22 Oct, 2008 6:05:40 PM java.util.logging.LogManager$RootLogger log
INFO: Error logs
BUILD SUCCESSFUL (total time: second)

Download code