"No appenders found for logger" and "Please configure log4j properly"

简介: Why do I see a warning about "No appenders found for logger" and "Please configure log4j properly"?This occurs when the default configuration files log4j.


Why do I see a warning about "No appenders found for logger" and "Please configure log4j properly"?
This occurs when the default configuration files log4j.properties and log4j.xml can not be found and the application performs no explicit configuration.
log4j uses Thread.getContextClassLoader().getResource() to locate the default configuration files and does not directly check the file system. Knowing the appropriate location to place log4j.properties or log4j.xml requires understanding the search strategy of the class loader in use. log4j does not provide a default configuration since output to the console or to the file system may be prohibited in some environments.
Also see FAQ: Why can't log4j find my properties in a J2EE or WAR application?.

Thread.getContextClassLoader().getResource():项目生成class文件的根目录,例如maven项目就是指target/classes/

Why can't log4j find my properties file in a J2EE or WAR application?
The short answer: the log4j classes and the properties file are not within the scope of the same classloader.
The long answer (and what to do about it): J2EE or Servlet containers utilize Java's class loading system. Sun changed the way classloading works with the release of Java 2. In Java 2, classloaders are arranged in a hierarchial parent-child relationship. When a child classloader needs to find a class or a resource, it first delegates the request to the parent.
Log4j only uses the default Class.forName() mechanism for loading classes. Resources are handled similarly. See the documentation for java.lang.ClassLoader for more details.
So, if you're having problems, try loading the class or resource yourself. If you can't find it, neither will log4j. ;)

http://logging.apache.org/log4j/1.2/faq.html#a3.5




相关文章
|
4月前
|
运维 Linux Windows
[运维技术]PowerShell中实现一个最基本的日志器logger
[运维技术]PowerShell中实现一个最基本的日志器logger
66 1
|
12天前
|
Java 应用服务中间件 HSF
Java应用结构规范问题之AllLoggers接口获取异常日志的Logger实例的问题如何解决
Java应用结构规范问题之AllLoggers接口获取异常日志的Logger实例的问题如何解决
|
23天前
|
消息中间件 监控 搜索推荐
OpenFeign日志组件Logger原理与应用
该文章详细解释了如何在OpenFeign中配置并使用请求和响应的GZIP压缩功能。
|
27天前
|
Java
OpenFeign 各种用法、 logger 日志记录
OpenFeign 各种用法、 logger 日志记录
34 0
|
2月前
|
关系型数据库 MySQL 数据库
MySQL 启动日志报错: File /mysql-bin.index not found (Errcode: 13 - Permission denied)
MySQL 启动日志报错: File /mysql-bin.index not found (Errcode: 13 - Permission denied)
141 2
|
3月前
|
监控 Linux 数据处理
深入了解Linux的logger命令:日志记录与监控
`logger`命令在Linux中用于向系统日志发送消息,便于记录系统事件和应用程序状态。它与`syslogd`配合,允许用户指定优先级、标识符和内容。简单易用,灵活适应不同日志需求。示例:`logger -p user.warning -t MYAPP "A warning occurred."`。注意选择合适优先级,使用有意义的标识符,并结合其他工具如`logrotate`进行日志管理。
|
4月前
|
监控 安全 API
orhanobut/logger - 强大的Android日志打印库
orhanobut/logger - 强大的Android日志打印库
154 1
|
4月前
|
Java 数据库
log4j:WARN Please initialize the log4j system prop
log4j:WARN Please initialize the log4j system prop
34 1
|
4月前
|
Java
log4j:WARN Please initialize the log4j system properly.
log4j:WARN Please initialize the log4j system properly.
126 0
|
10月前
|
Java
解决:Config service failed to start in 120 seconds! Please check ./service/apollo-service.log...
解决:Config service failed to start in 120 seconds! Please check ./service/apollo-service.log...
127 0
下一篇
DDNS