java Log4J:警告无法为 Logger 错误找到 Appender
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36951204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Log4J: Warn No Appenders could be found for Logger error
提问by Sandy QA Proffessional
Below is my log4j.properties file content, file is placed with the src folder in eclipse.
下面是我的log4j.properties文件内容,文件放在eclipse的src文件夹下。
#Application Logs
log4j.rootlogger=INFO, logg
log4j.appender.logg=org.apache.log4j.RollingFileAppender
log4j.appender.logg.File=D:\SandhyaFiles\SeleniumWorkspace\InterviewProject\Logs\Testlogs.log
log4j.appender.logg.layout=org.apache.log4j.PatternLayout
log4j.appender.logg.layout.ConversionPattern=%d -%c -%p - %m%n
log4j.appender.logg.maxFileSize=5MB
log4j.appender.logg.maxBackupIndex=3
Inside Library package i have initialised and used logj as below:
在 Library 包中,我已经初始化并使用了 logj,如下所示:
public class Library
{
public static final Logger Log = Logger.getLogger(Library.class);
public void initialized(){
Log.info("Inside initialise")
}}
calling initialize from testcase throws log4j warning:
从测试用例调用 initialize 会引发 log4j 警告:
log4j:WARN No appenders could be found for logger (library.Library). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfigfor more info.
log4j:WARN 找不到记录器 (library.Library) 的附加程序。log4j:WARN 请正确初始化 log4j 系统。log4j:WARN 有关更多信息,请参阅http://logging.apache.org/log4j/1.2/faq.html#noconfig。
Please Help me fix this.
请帮我解决这个问题。
采纳答案by Sandy QA Proffessional
After so many trials, weirdly re arranging the properties file to this everything is going no warning and could get the logs.
经过如此多的试验,奇怪地将属性文件重新安排为此一切都没有警告并且可以获取日志。
# Root logger option
log4j.rootLogger=INFO, logg
log4j.appender.logg=org.apache.log4j.RollingFileAppender
log4j.appender.logg.File=.\Logs\Testlogs.log
log4j.appender.logg.MaxFileSize=5MB
log4j.appender.logg.MaxBackupIndex=3
log4j.appender.logg.layout=org.apache.log4j.PatternLayout
log4j.appender.logg.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
I wonder why this is so? if somebody can explain it will be great help. Thanks
我想知道为什么会这样?如果有人可以解释,那将是非常有帮助的。谢谢
回答by uniknow
It seems like log4j is not able to find the log4j properties file.
似乎 log4j 无法找到 log4j 属性文件。
One could specify the location of the log4j.properties file explicitly via the log4j.configuration
system property.
可以通过log4j.configuration
系统属性明确指定 log4j.properties 文件的位置。
-Dlog4j.configuration=file:mylogging.properties
In case the system property log4j.configuration
is not defined, then the resource is set to its default value log4j.properties
and looked for in the classpath of the project (at root).
如果log4j.configuration
未定义系统属性,则将资源设置为其默认值log4j.properties
并在项目的类路径中(在根目录下)查找。