yaniv
yaniv

Reputation: 170

Some issues with java.util.logging.Logger

I have the following example code :

import java.util.logging.Logger;

public class LoggingExample {

  private static final Logger LOGGER = Logger.getLogger(
    Thread.currentThread().getStackTrace()[0].getClassName() );

    public static void main(String[] args) {
      LOGGER.setLevel(Level.ALL);
      LOGGER.info("Logging an INFO-level message");
      LOGGER.fine("Logging an INFO-level message2");

    }
}

With the output to console of:

05/06/2014 12:07:09 ztesting.Loger.LoggingExample main
INFO: Logging an INFO-level message

And I have several question:

  1. The entire output is in red, can I set the output to be in different colors according to the level?
  2. Can I not display the first line "05/06/2014 12:07:09 ztesting.Loger.LoggingExample main"
  3. Can I block the output to console completely, meaning I would only set output to a log file.
  4. Not as important, but why does the fine row does not display ?

P.S. I m using netbeans 6.9

ALSO tried using the following links and it got me no where

Is there any way to remove the information line from java.util.logging.Logger output?

How do I get java logging output to appear on a single line?

Thanks for any help ..

Upvotes: 0

Views: 796

Answers (1)

Peter Svensson
Peter Svensson

Reputation: 6173

Most of your questions are answered in different tutorials available for java.util.logging. One example here

You should also read the javadoc.

"Can I not display the first line "05/06/2014 12:07:09 ztesting.Loger.LoggingExample main"

Yes, using Formatters

"Can I block the output to console completely, meaning I would only set output to a log file."

Yes, set the log level, filter or handler in a configuration file

"The entire output is in red, can I set the output to be in different colors according to the level?" 

This is specific to Netbeans which I don't personally use so I can't answer that.

Personally I prefer SLF4J with Logback over JUL...

Upvotes: 1

Related Questions