2017-01-02 91 views
-1

我有以下简单的代码,我试图在IntelliJ IDEA的终极2016.3运行:如何获得log4j的消息控制台,以示对IntelliJ IDEA的

import org.apache.log4j.BasicConfigurator; 
import org.apache.log4j.Logger; 

public class Sample { 
    static Logger log = Logger.getLogger(Sample.class); 

    public static void main(String[] args) { 
     BasicConfigurator.configure(); 
     log.info("This is a message"); 
    } 
} 

,但我不能够看到我的消息在控制台中,我得到以下错误:

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. 

我添加了所有的jar文件到目标目录。我想使用BasicConfigurator.configure()可以让你不使用配置文件。

+0

看到这里的例子 - http://www.programcreek.com/java-api-examples/org.apache.log4j.BasicConfigurator – Rao

+0

这些例子是针对旧的EOL Log4j 1. –

回答

0

你的进口是旧的Log4j 1库。 对于Log4j2,您需要org.apache.logging.log4j

Log4j2比旧的Log4j 1具有更好的文档。编程配置涵盖了here

+0

感谢您的信息! –

0

您的资源路径中需要配置文件。默认文件名是log4j2.yaml。这是我的方式。你需要改变你import path