Java Logging

Submitted by code_admin on Mon, 07/23/2018 - 09:24

My standard way of using Java Logging.

Level.SEVERE = All fatal exceptions - always seen
Level.WARNING = Default shown warnings
Level.INFO = General app info messages
** DEFAULT LEVEL IS INFO **
Level.CONFIG = Non error messages
Level.FINE = ??
Level.FINER = ??
Level.FINEST,"FINEST = Single bug fix

Class head

  1.     private static final Logger log = Logger.getLogger(ClassName.class.getName());

First line of class constructor

  1.         //LOGUtilities.SetLocalLogging(log, Level.ALL);

This line is commented out so when I am debuging I can put it back in if required

Main Methods

At the start of the program enter the following. The level in the info statement sets the global level.

  1.         LOGUtilities.init(Level.INFO); //Setup default log formatter
  2.         log.log(Level.INFO,"Starting Test");
  3.  
  4.          //APP CODE
  5.  
  6.         log.log(Level.INFO,"Ending Test");

Exception methods

  1.         } catch (Exception e) {
  2.             log.log(Level.SEVERE,e.toString(),e);
  3.         }

No stack trace output needed as it will go into the log

Tags

RJM Article Type
Quick Reference