'java.util.logger undefined for the type System.Logger
I am new to java and trying to use the logger in java.util. I declare the logger like this snippet:
Logger logger = Logger.getLogger(MyClass.class.getName());
referring to this website: https://www.loggly.com/ultimate-guide/java-logging-basics/
What I did was:
private static final Logger logger = Logger.getLogger(EthicalEngine.class.getName());
However, it shows the error message
The method getLogger(String) is undefined for the type System.Logger
Here is part of my main class ( EthicalEngine ):
public class EthicalEngine {
private static final Logger logger = Logger.getLogger(EthicalEngine.class.getName());
public static void main(String[] args) throws Exception {
EthicalEngine ethicalEngine = new EthicalEngine();
ethicalEngine.commandLineProcess();
}
Did I do anything wrong, or there is something that I missed? Any help is highly appreciated.
Solution 1:[1]
You are confusing java.util.logging.Logger, which is a logging framework added in Java 1.4, and java.lang.System.Logger, which is a logging facade added in Java 9.
java.util.logging.Loggeris created by theLogger.getLogger(String name)method.java.lang.System.Loggeris created by theSystem.getLogger?(String name)method.
Since you are calling Logger.getLogger(), it means that you imported the wrong Logger type.
Solution: Fix your import statement.
Solution 2:[2]
Replace
import java.lang.System.Logger;
with
import java.util.logging.Logger;
to remove the error.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andreas |
| Solution 2 | Xavier Guihot |
