Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up java Logger for a specific package

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.

like image 709
lisak Avatar asked Mar 13 '11 18:03

lisak


People also ask

How do you add a logger to a Java program?

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.

Which of the following Java package is used for logging?

A Filter is an interface in java. util. logging package. It is used to control the messages to be logged by the handler.

What is Java logging package?

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.


1 Answers

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");
like image 122
Dharwin Avatar answered Oct 08 '22 13:10

Dharwin