简体   繁体   中英

Log4j maven dependency won't log to console

this is my first try with Log4j, when I run the code I got the following error:

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...

Here is my code, syntax and logic seems right, should I configure/create any files?

package main;

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

public class Main {

    private static final Logger logger = LogManager.getLogger(Main.class);
    
    public static void main(String[] args) {

        try {
            
            logger.info("START.");
            Service.readConfig();
            
        } catch (Exception e) {
            
        }
        
    }

}

Since you don't have any configuration files, log4j is going with the default configuration, which is assigning the root logger to the ERROR logging level . Configuring a level on a logger will cause logging events of that level and those that are more specific to pass through the filter. INFO , which is the level you are logging when you call logger.info() is less specific and thus it's not getting logged. You need to configure the logger to log at least INFO , or log ERROR or FATAL using the corresponding methods. You can read how to configure the logger level in log4j's documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM