3

I found this code in the net and studying it to better understand how the logging works but it has an error in one particlar line and I can't seem to fix it.

static public void setup() throws IOException {

  System.out.println("MyLogger");
  Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);

    // suppress the logging output to the console
    Logger rootLogger = Logger.*getLogger*("");   <---- ERROR (getLogger cannot be resolved or is not a field)
    Handler[] handlers = rootLogger.getHandlers();
    if (handlers[0] instanceof ConsoleHandler) {
      rootLogger.removeHandler(handlers[0]);
    }

    logger.setLevel(Level.INFO);
    fileTxt = new FileHandler("Logging.txt");
    fileHTML = new FileHandler("Logging.html");

    // create a TXT formatter
    formatterTxt = new SimpleFormatter();
    fileTxt.setFormatter(formatterTxt);
    logger.addHandler(fileTxt);

    // create an HTML formatter
    formatterHTML = new MyHtmlFormatter();
    fileHTML.setFormatter(formatterHTML);
    logger.addHandler(fileHTML);
  }

}

Anyone have any idea why? ty in advance.

0

1 Answer 1

2

That is java.util.logging.Logger, I strongly suspect you have imported some other Logger

 // Something like this
 java.util.logging.Logger rootLogger = java.util.logging.Logger.getLogger("");
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.