Logger not logging.

T

tekwiz

I have a strange issue. The java.util.logging.Logger is not logging
anything below INFO level even when I explicitly set it to log
everything (Level.all) Here's what I did first:

Logger l = Logger.getLogger("TestLog");
l.setLevel(Level.ALL);
l.info("test");
l.fine("test");
l.finer("test");
l.finest("test");

This didn't work, so I tried explicity setting the level on the
handlers, overriding the filters, and flushing the buffers on the
handlers:

Logger l = Logger.getLogger("TestLog");

l.setFilter(new Filter() {
public boolean isLoggable(LogRecord record) {
return true;
}
});

for(Handler h : l.getHandlers()) {
h.setFilter(new Filter() {
public boolean isLoggable(LogRecord record) {
return true;
}
});
h.setLevel(Level.ALL);
}

l.setLevel(Level.ALL);
l.info("test");
l.fine("test");
l.finer("test");
l.finest("test");

Still no go... Please tell me I'm missing something simple...
 
A

Arne Vajhøj

tekwiz said:
I have a strange issue. The java.util.logging.Logger is not logging
anything below INFO level even when I explicitly set it to log
everything (Level.all) Here's what I did first:

Logger l = Logger.getLogger("TestLog");
l.setLevel(Level.ALL);
l.info("test");
l.fine("test");
l.finer("test");
l.finest("test");

Try:

Logger l = Logger.getLogger("TestLog");
l.setLevel(Level.ALL);
l.getParent().getHandlers()[0].setLevel(Level.ALL);
l.info("test");
l.fine("test");
l.finer("test");
l.finest("test");

(and you really should use a config file with
explicit handlers)

Arne
 
M

Mark Space

tekwiz said:
I have a strange issue. The java.util.logging.Logger is not logging
anything below INFO level even when I explicitly set it to log
everything (Level.all) Here's what I did first:

Logger l = Logger.getLogger("TestLog");
l.setLevel(Level.ALL);

Your "TestLog" likely has no handlers, unless you added some elsewhere.
The log messages you see are coming from the parent of this logger,
which is probably the root logger.

Loggers are designed to be controlled via config files, really.
Handling them in code can be a bit tricky.

Try making an instance of a console handler, setting the level to ALL,
and installing it in your logger. that will give you duplicate message,
since you'll be getting message from both your logger and the root
logger. You can fix this by setting (guessing at method name here)
useParentLogger(false) on your logger.
 
M

Mark Space

Arne said:
Try:

Logger l = Logger.getLogger("TestLog");
l.setLevel(Level.ALL);
l.getParent().getHandlers()[0].setLevel(Level.ALL);

The problem with this is that the parent of your logger isn't always to
be the root logger. And if it isn't the root logger, this probably
won't do much.

Plus, setting the root logger will affect all other loggers in your
program, which might be really annoying, to say the least. For local
debugging, it's best to make your own logger and handler(s) and just use
those. It's guaranteed to work, and you won't mess with the settings of
the root logger, which really should be allowed to be configurable by
the commandline switches and the appropriate config files.
 
A

Andrea Francia

May be you need to edit logging.properties file (which in my computer is
located at C:\Program Files\Java\jdk1.6.0_02\jre\lib\logging.properties).

This is the default configuration:
# Limit the message that are printed on the console to INFO and above.
java.util.logging.ConsoleHandler.level = INFO
You should change it to
# Limit the message that are printed on the console to INFO and above.
java.util.logging.ConsoleHandler.level = ALL

bye
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top