1 ImportJava.util.logging.Level;2 ImportJava.util.logging.Logger;3 4 Public classLoggingdemo {5 Public Static FinalLogger Logger = Logger.getlogger ("Loggingdemo.class");6 7 Public Static voidMain (String args[]) {8Level level = Level.parse ("FINEST");9 Logger.info (level.tostring ());Ten One //the following message will be output A logger.setlevel (level); -Logger.info ("This was an info"); -Logger.warning ("This is a warn"); theLogger.severe ("This is a severe"); - //logger.config ("config"); - //logger.fine ("fine"); - //Logger.finer ("finer"); + //logger.finest ("finest"); - +Logger.info ("Loggername:" +logger.getname ()); ALogger.info ("Loggerlevelname:" +logger.getlevel (). GetName ()); at - } -}
Operation Result:
May 23, 2018 5:13:24pm Org.study2.java8.logging.LoggingDemo Main info: Finest May23, 2018 5:13:24pm Org.study2.java8.logging.LoggingDemo main information: Thisis an info May23, 2018 5:13:24pm Org.study2.java8.logging.LoggingDemo Main warning: ThisIs a warn May23, 2018 5:13:24pm Org.study2.java8.logging.LoggingDemo main serious: Thisis a severe May23, 2018 5:13:24pm Org.study2.java8.logging.LoggingDemo main information: Loggername:loggingdemo.classMay23, 2018 5:13:24pm Org.study2.java8.logging.LoggingDemo main information: Loggerlevelname:finest
Java Logger log (Java8 feature)