Log4j 属性给出错误

Log4j properties giving error

我收到错误消息

log4j:WARN No appenders could be found for logger (com.faktorZehn.socialNetwork.socialNetwork.PersonGenerator).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

我的属性看起来像

 This sets the global logging level and specifies the appenders
log4j.rootLogger=INFO, theConsoleAppender

# settings for the console appender
log4j.appender.theConsoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.theConsoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.theConsoleAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

有没有我哪里做错了?

您的资源文件夹不在您的类路径中。右键单击文件夹 -> Build Path -> Use as source folder.

然后重新运行您的应用程序,您的 log4j.properties 应该被 log4j 框架使用。

确保 log4j.properties 在类路径中。 使 resources 文件夹实际上成为一个资源文件夹。它看起来像一个 Maven 项目,所以你可以将它移动到 src/main/resources

或者您可以使用 JVM 参数设置它。

-Dlog4j.configuration=resources/log4j.properties