Search code examples
javalogginglog4jlog4j2

Method getLogger() no longer a member of Logger in log4j2?


I have the log4j-api-2.0.0.jar and log4j-core-2.0.2.jar import into my build path. But somehow the following code were fail:

import org.apache.logging.log4j.core.Logger;

public class TheClass {

    private static Logger log = Logger.getLogger(TheClass.class);

...

And the error message shows that:

The method getLogger(Class<TheClass>) is undefined for the type Logger

I am just so curious is getLogger() no longer a valid method in Logger?


Solution

  • You'll notice Logger no longer declares such a method.

    log4j version 2 has made some drastic changes. Here's the change log. getLogger seems to have been moved to a LogManager class.

    Here's how they suggest making the migration.