2015-09-07 11:44:36 -06:00
|
|
|
// logging/ConfigureLogging.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-06-15 17:47:35 -07:00
|
|
|
// {JVMArgs: -Djava.util.logging.config.file=log.prop}
|
2015-12-16 13:50:01 -08:00
|
|
|
// {ErrorOutputExpected}
|
2015-06-15 17:47:35 -07:00
|
|
|
import java.util.logging.*;
|
|
|
|
|
|
|
|
public class ConfigureLogging {
|
|
|
|
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"),
|
2015-11-11 20:20:04 -08:00
|
|
|
util= Logger.getLogger("onjava"),
|
2015-06-15 17:47:35 -07:00
|
|
|
test= Logger.getLogger("com.mindviewinc.test"),
|
|
|
|
rand = Logger.getLogger("random");
|
|
|
|
public ConfigureLogging() {
|
|
|
|
/*
|
|
|
|
Set Additional formatters, Filters and
|
|
|
|
Handlers for the loggers here. You cannot
|
|
|
|
specify the Handlers for loggers except
|
|
|
|
the root logger from the configuration
|
|
|
|
file.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
|
|
sendLogMessages(lgr);
|
|
|
|
sendLogMessages(lgr2);
|
|
|
|
sendLogMessages(util);
|
|
|
|
sendLogMessages(test);
|
|
|
|
sendLogMessages(rand);
|
|
|
|
}
|
|
|
|
private static void
|
|
|
|
sendLogMessages(Logger logger) {
|
|
|
|
System.out.println(" Logger Name : "
|
|
|
|
+ logger.getName() + " Level: "
|
|
|
|
+ logger.getLevel());
|
|
|
|
logger.finest("Finest");
|
|
|
|
logger.finer("Finer");
|
|
|
|
logger.fine("Fine");
|
|
|
|
logger.config("Config");
|
|
|
|
logger.info("Info");
|
|
|
|
logger.warning("Warning");
|
|
|
|
logger.severe("Severe");
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
}
|
|
|
|
/* Output:
|
2016-07-22 14:45:35 -06:00
|
|
|
Logger Name : com Level: null
|
|
|
|
Logger Name : com.mindviewinc Level: FINEST
|
|
|
|
Logger Name : onjava Level: INFO
|
|
|
|
Logger Name : com.mindviewinc.test Level: FINER
|
|
|
|
Logger Name : random Level: SEVERE
|
2015-06-15 17:47:35 -07:00
|
|
|
___[ Error Output ]___
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2016-07-22 14:45:35 -06:00
|
|
|
FINEST: Finest
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2016-07-22 14:45:35 -06:00
|
|
|
FINER: Finer
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2016-07-22 14:45:35 -06:00
|
|
|
FINE: Fine
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2016-07-22 14:45:35 -06:00
|
|
|
CONFIG: Config
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2015-12-16 13:50:01 -08:00
|
|
|
INFO: Info
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2015-12-16 13:50:01 -08:00
|
|
|
WARNING: Warning
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2015-06-15 17:47:35 -07:00
|
|
|
SEVERE: Severe
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2016-07-22 14:45:35 -06:00
|
|
|
FINEST: Finest
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2016-07-22 14:45:35 -06:00
|
|
|
FINER: Finer
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2016-07-22 14:45:35 -06:00
|
|
|
FINE: Fine
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2016-07-22 14:45:35 -06:00
|
|
|
CONFIG: Config
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2015-06-15 17:47:35 -07:00
|
|
|
INFO: Info
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2015-06-15 17:47:35 -07:00
|
|
|
WARNING: Warning
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2015-06-15 17:47:35 -07:00
|
|
|
SEVERE: Severe
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2015-06-15 17:47:35 -07:00
|
|
|
INFO: Info
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2015-06-15 17:47:35 -07:00
|
|
|
WARNING: Warning
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2015-06-15 17:47:35 -07:00
|
|
|
SEVERE: Severe
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2016-07-22 14:45:35 -06:00
|
|
|
FINER: Finer
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2016-07-22 14:45:35 -06:00
|
|
|
FINE: Fine
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2016-07-22 14:45:35 -06:00
|
|
|
CONFIG: Config
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2015-06-15 17:47:35 -07:00
|
|
|
INFO: Info
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2015-06-15 17:47:35 -07:00
|
|
|
WARNING: Warning
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2015-06-15 17:47:35 -07:00
|
|
|
SEVERE: Severe
|
2016-07-27 11:12:11 -06:00
|
|
|
Jul 27, 2016 10:50:38 AM ConfigureLogging sendLogMessages
|
2015-06-15 17:47:35 -07:00
|
|
|
SEVERE: Severe
|
2015-09-07 11:44:36 -06:00
|
|
|
*/
|