1

I'm trying the following code example (based on code from here). My aim is to set the level of the logging from run time.

package logchecker;
import java.util.logging.*;

public class Logchecker {

    private static final Logger logger = Logger.getLogger(Logchecker.class.getName());

   public static void main(String[] args) {
      System.out.println("This logger's level is " + logger.getLevel());   // null
      logger.setLevel(Level.ALL);
      System.out.println("This logger's level is " + logger.getLevel());   // null
      logger.info("TEST");
      logger.finest("FINEST TEST");
   }
}

The output is:

This logger's level is null

This logger's level is ALL

Sep 17, 2013 1:46:31 PM logchecker.Logchecker main

INFO: TEST

It obviously doesn't output the log.finest. What am I missing? I'm running with NetBeans 7.3.

2
  • 1
    Maybe this question on SO can help you. Commented Sep 17, 2013 at 12:16
  • 1
    This is probably a duplicate of stackoverflow.com/questions/6315699/… Commented Sep 17, 2013 at 12:17

1 Answer 1

1

I needed to set my Handlers level as well. Added the following code to my main:

Logger root = Logger.getLogger("");
Handler[] handlers = root.getHandlers();
for(Handler h: handlers){
    h.setLevel(Level.INFO);
}

Of course you can set the level to whatever you need.

thanks again to the comments for directing me to the solution

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.