could anybody explain to me, how to set up java Logger for various classes from a concrete package ?
for example: if I get this one and set it up
Logger logger = Logger.getLogger("com.google.api.client.*");
logger.setLevel(Level.CONFIG);
logger.addHandler(new Handler() {
@Override
public void close() throws SecurityException {
}
@Override
public void flush() {
}
@Override
public void publish(LogRecord record) {
// default ConsoleHandler will take care of >= INFO
if (record.getLevel().intValue() < Level.INFO.intValue()) {
System.out.println(record.getMessage());
}
}
});
there are conditions like this
Logger.getLogger(HttpTransport.class.getName()).isLoggable(Level.CONFIG);
in the library where HttpTransport
is part of com.google.api.client.*
But the problem is, that
Logger.getLogger(HttpTransport.class.getName()).isLoggable(Level.CONFIG);
is false
... like if a different logger was obtained
How else should I set it for all classes from the same package? if there are conditions for loggers for concrete classes like HttpTransport.
The process of creating a new Logger in Java is quite simple. You have to use Logger. getLogger() method. The getLogger() method identifies the name of the Logger and takes string as a parameter.
A Filter is an interface in java. util. logging package. It is used to control the messages to be logged by the handler.
Logging in Java requires using one or more logging frameworks. These frameworks provide the objects, methods, and configuration necessary to create and send log messages. Java provides a built-in framework in the java. util. logging package.
You do not want the .* in your package string. Change
Logger logger = Logger.getLogger("com.google.api.client.*");
to
Logger logger = Logger.getLogger("com.google.api.client");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With