OnJava8-Examples/logging/LoggingLevelManipulation.java

185 lines
5.7 KiB
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// logging/LoggingLevelManipulation.java
2015-12-15 11:47:04 -08:00
// (c)2016 MindView LLC: see Copyright.txt
2015-11-15 15:51:35 -08:00
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
2015-12-16 13:50:01 -08:00
// {ErrorOutputExpected}
2015-06-15 17:47:35 -07:00
import java.util.logging.Level;
import java.util.logging.Logger;
public class LoggingLevelManipulation {
private static Logger
2015-11-03 12:00:44 -08:00
lgr = Logger.getLogger("com"),
2015-06-15 17:47:35 -07:00
lgr2 = Logger.getLogger("com.mindviewinc"),
util= Logger.getLogger("onjava"),
2015-06-15 17:47:35 -07:00
test= Logger.getLogger("com.mindviewinc.test"),
rand = Logger.getLogger("random");
static void printLogMessages(Logger logger) {
logger.finest(logger.getName() + " Finest");
logger.finer(logger.getName() + " Finer");
logger.fine(logger.getName() + " Fine");
logger.config(logger.getName() + " Config");
logger.info(logger.getName() + " Info");
logger.warning(logger.getName()+" Warning");
logger.severe(logger.getName() + " Severe");
}
static void logMessages() {
printLogMessages(lgr);
printLogMessages(lgr2);
printLogMessages(util);
printLogMessages(test);
printLogMessages(rand);
}
static void printLevels() {
System.out.println(" -- printing levels -- "
+ lgr.getName()
+ " : " + lgr.getLevel()
+ " " + lgr2.getName()
+ " : " + lgr2.getLevel()
+ " " + util.getName()
+ " : " + util.getLevel()
+ " " + test.getName()
+ " : " + test.getLevel()
+ " " + rand.getName()
+ " : " + rand.getLevel());
}
public static void main(String[] args) {
printLevels();
lgr.setLevel(Level.SEVERE);
printLevels();
System.out.println("net level: SEVERE");
logMessages();
util.setLevel(Level.FINEST);
test.setLevel(Level.FINEST);
rand.setLevel(Level.FINEST);
printLevels();
System.out.println(
"individual loggers set to FINEST");
logMessages();
lgr.setLevel(Level.FINEST);
printLevels();
System.out.println("net level: FINEST");
logMessages();
}
2015-09-07 11:44:36 -06:00
}
/* Output:
2016-07-22 14:45:35 -06:00
-- printing levels -- com : null com.mindviewinc : null
2015-12-16 13:50:01 -08:00
onjava : null com.mindviewinc.test : null random : null
-- printing levels -- com : SEVERE com.mindviewinc : null
onjava : null com.mindviewinc.test : null random : null
2015-06-15 17:47:35 -07:00
net level: SEVERE
2015-12-16 13:50:01 -08:00
-- printing levels -- com : SEVERE com.mindviewinc : null
onjava : FINEST com.mindviewinc.test : FINEST random :
FINEST
2015-06-15 17:47:35 -07:00
individual loggers set to FINEST
2015-12-16 13:50:01 -08:00
-- printing levels -- com : FINEST com.mindviewinc : null
onjava : FINEST com.mindviewinc.test : FINEST random :
FINEST
2015-06-15 17:47:35 -07:00
net level: FINEST
___[ Error Output ]___
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
2015-12-16 13:50:01 -08:00
SEVERE: com Severe
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
SEVERE: com.mindviewinc Severe
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
INFO: onjava Info
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
WARNING: onjava Warning
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
SEVERE: onjava Severe
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
SEVERE: com.mindviewinc.test Severe
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
INFO: random Info
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
WARNING: random Warning
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
SEVERE: random Severe
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
2015-12-16 13:50:01 -08:00
SEVERE: com Severe
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
SEVERE: com.mindviewinc Severe
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
INFO: onjava Info
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
WARNING: onjava Warning
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
SEVERE: onjava Severe
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
INFO: com.mindviewinc.test Info
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
WARNING: com.mindviewinc.test Warning
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
SEVERE: com.mindviewinc.test Severe
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
INFO: random Info
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
WARNING: random Warning
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
SEVERE: random Severe
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
2015-12-16 13:50:01 -08:00
INFO: com Info
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
2015-12-16 13:50:01 -08:00
WARNING: com Warning
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
2015-12-16 13:50:01 -08:00
SEVERE: com Severe
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
INFO: com.mindviewinc Info
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
WARNING: com.mindviewinc Warning
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
SEVERE: com.mindviewinc Severe
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
INFO: onjava Info
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
WARNING: onjava Warning
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
SEVERE: onjava Severe
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
INFO: com.mindviewinc.test Info
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
WARNING: com.mindviewinc.test Warning
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
SEVERE: com.mindviewinc.test Severe
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
INFO: random Info
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
WARNING: random Warning
2016-07-27 11:12:11 -06:00
Jul 27, 2016 10:50:42 AM LoggingLevelManipulation
2015-06-15 17:47:35 -07:00
printLogMessages
SEVERE: random Severe
2015-09-07 11:44:36 -06:00
*/