在Intellij中配置log4j.properties

时间:2013-12-23 19:26:56

标签: groovy intellij-idea log4j

我在配置log4j属性时遇到问题 我以前用代码来配置记录器 但是,现在我得到没有appender可以从groovyx.net.http.RESTClient找到WARN,我无法更改代码。 WARN如下:

log4j:WARN No appenders could be found for logger (groovyx.net.http.RESTClient).
log4j:WARN Please initialize the log4j system properly.

所以我尝试默认使用log4j.properties文件来设置appender。但是,我不知道应该把log4j.properties文件放在哪里。我将-Dlog4j.debug添加为JVM选项并运行测试。我收到以下信息:

log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@a6eb38a.
log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@a6eb38a class loader.  
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@a6eb38a.
log4j: Trying to find [log4j.properties] using sun.misc.Launcher$AppClassLoader@a6eb38a class loader.
log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [null].  

我正在使用IntelliJ并运行Spock测试。 任何答案都将是欣赏。谢谢。

2 个答案:

答案 0 :(得分:2)

您的log4j配置文件应放在源根目录中。

在IDEA中,它可能是资源文件夹。

请注意:Where should I put the log4j.properties file?

对于Groovy来说,它都是一样的。

答案 1 :(得分:0)

在intellij中,您可以按如下方式为配置文件指定路径:

  1. 打开编辑配置对话框
  2. 单击日志选项卡
  3. 单击加号以添加属性/ xml文件的路径。您可以为此配置添加别名。
  4. 应用。
  5. 要检查您的log4j配置文件是否已加载,您可以将运行/编辑配置下的VM选项添加为-Dlog4j.debug。使用此参数log4j将登录与加载文件过程相关的控制台步骤。