首页 > 编程语言 >"No appenders found for logger" and "Please configure log4j properly"

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

时间:2023-08-04 12:32:40浏览次数:60  
标签:properties appenders No default Please log4j find configuration class

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



标签:properties,appenders,No,default,Please,log4j,find,configuration,class
From: https://blog.51cto.com/u_15147537/6959853

相关文章

  • iptables: No chain/target/match by that name
    部署完docker后执行脚本报错在启动run.sh脚本后出现iptables:Nochain/target/matchbythatname.报错解决办法:重启dockerPS:重启docker后,通过以下命令可以查看最新防火墙配置:iptables-L应该看到iptables配置中ChainDocker设置已更新(与1中历史结果进行对比)原因解释重新......
  • Blazor前后端框架Known-V1.2.10
    V1.2.10Known是基于C#和Blazor开发的前后端分离快速开发框架,开箱即用,跨平台,一处代码,多处运行。Gitee:https://gitee.com/known/KnownGithub:https://github.com/known/Known概述基于C#和Blazor实现的快速开发框架,前后端分离,开箱即用。跨平台,单页应用,混合桌面应用,Web和桌面......
  • [Ynoi2010] y-fast trie(multiset+思维)
    题目传送门solution妙妙题。分成\(a+b\geqC\)和\(a+b<C\)讨论。第一类是简单的,只需要选择最大和次大的数就行了。第二类加入是容易的,但是有删除。常规做法是线段树分治+\(multiset\),不能在线。考虑一个性质:如果对于\(x\),小于等于\(C-1-x\)的最大的\(y\)记作\(m......
  • python 闭包变量不允许write,要使用nonlocal
     以下是一段简单的闭包代码示例:deffoo():m=3n=5defbar():a=4returnm+n+areturnbar>>>bar=foo()>>>bar()12是可以的!但是:deffoo():m=3n=5defbar():a=4m+=1#不可以!!!return......
  • [Ynoi2016] 这是我自己的发明(根号分治+分块/莫队)
    题目传送门soltion简单题换根显然可以拆成\(O(1)\)个区间,这里先不管。直接做法是莫队,把双子树拆成\(dfs\)序上的双前缀,可以直接莫队,但是常数比较大。另一种做法是根分,对颜色出现次数分治,大于的求出\(dfs\)序的前缀和即可,小于的因为一共只有\(O(n\sqrtn)\)个点对,所以......
  • [Ynoi2012] NOIP2015 充满了希望(扫描线+线段树)
    题目传送门solution简单题。我们正着做扫描线。设\(t_i\)表示位置\(i\)最后一次进行二操作的时间,那么一操作就是交换\(t_x,t_y\),二操作就是区间复制。对于三操作,开一个树状数组,如果查询的位置的\(t_x=j\),就在\(j\)的位置上加一。查询就是查询后缀和。#include<bit......
  • Backdoor:Win32/Noancooe 使用IDA进行恶意软件分析
    Backdoor:Win32/Noancooe先看下微软官方怎么说这个恶意软件:DetectedbyMicrosoftDefenderAntivirusAliases:Trojan-Ransom.Win32.Foreign.muyq(Kaspersky)SummaryWindowsDefenderdetectsandremovesthisthreat.Thisthreatcangiveamalicioushackerunauthorize......
  • P7116 [NOIP2020] 微信步数
    原题简化题意:有一个k维场地,第i维宽为wi,即第i维的合法坐标为1,2,···,wi。小C有一个长为n的行动序列,第i元素为二元组(ci,di),表示这次行动小C的坐标由(x1,x2,...,xci,...,xk)变为(x1,x2,...,xci+di,...,xk)。小C会将行动......
  • InnoDB – the best storage engine for MySQL?
    https://dev.mysql.com/doc/refman/5.7/en/innodb-introduction.html InnoDBisageneral-purposestorageenginethatbalanceshighreliabilityandhighperformance.InnoDB是一个通用的存储引擎,平衡了高可靠性和高性能。InMySQL5.7,InnoDBisthedefaultMySQLsto......
  • PEP 703作者给出的一种no-GIL的实现——python3.9的nogil版本
    PEP703的内容是什么,意义又是什么呢?可以说python的官方接受的no-GIL提议的PEP就是PEP703给出的,如果GIL帧的从python中移除那么可以说对整个python生态圈将有着跨越性发展的意义。  ====================================================  PEP703地址:https://peps.p......