应用程序log4j.properties未加载(Application log4j.properties not loaded)
我在amazon linux(版本201303)上安装了一个干净的tomcat 7,其中一个应用程序部署为ROOT。 log4j-1.2.17.jar驻留在WEB-INF / lib中。 WEB-INF / classes中有一个log4j.properties文件,其中包含以下内容:
log4j.rootLogger=DEBUG,A1, A2 log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.Threshold=DEBUG log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd}-%t-%x-%-5p-%-10c:%m%n log4j.appender.A2.File=${catalina.home}/logs/app.log log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender log4j.appender.A2.DatePattern='.' yyyy-MM-dd log4j.appender.A2.MaxFileSize=10MB log4j.appender.A2.MaxBackupIndex=99 log4j.appender.A2.Append=true log4j.appender.A2.layout=org.apache.log4j.PatternLayout log4j.appender.A2.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS}-%t-%x-%-5p-%-10c:%m%n
在应用程序中,log4j实例化为
static Logger logger = Logger.getLogger(ClassName.class.getName());
app.log永远不会被创建。 如果我手动创建它,它永远不会被写入。 唯一的日志记录是在logs / catalina.out中。 我错过了什么? 我已多次通过http://tomcat.apache.org/tomcat-7.0-doc/logging.html阅读。 以下摘录似乎证实了我的方法:
如果您只想在自己的Web应用程序中使用log4j,则不需要这些步骤。 - 在这种情况下,只需将log4j.jar和log4j.properties放入Web应用程序的WEB-INF / lib和WEB-INF / classes中。
catalina_home / lib中有一个log4j.jar和log4j.xml,以及catalina_home / conf中的log4j.properties。 那些与我的WAR中包含的罐子有冲突吗? 我没有在catalina.out中看到任何错误。
UPDATE
所以看来WEB-INF / classes中的log4j.properties正在加载。 我删除了ConsoleAppender(log4j.appender.A1)并停止出现在catalina.out中的日志消息。 我把它重新放入,日志消息再次出现在catalina.out中。 奇怪的是转换模式似乎与日志不匹配。 不应该
%d{yyyy-MM-dd}-%t-%x-%-5p-%-10c:%m%n
生成像2013-07-10 INFO ClassName Log message
? 相反,我看到14:39:29,180 INFO [ClassName] Log message
。更新2
我找到了答案。 $ {catalina.home} / lib中有一个log4j.xml,它在容器级别配置log4j。 我想如果我真的在Tomcat中做了什么,我会早点把它想出来。 一旦我开始配置lib / log4j.xml,我得到了预期的结果。 我仍然有点困惑为什么我的应用程序继承了该配置而不是使用自己的log4j.properties。 哦,我实现了预期的结果,所以有时间继续前进。
I have a clean tomcat 7 installation on amazon linux (version 201303) with one application deployed as ROOT. log4j-1.2.17.jar resides in WEB-INF/lib. There is a log4j.properties file in WEB-INF/classes containing the following:
log4j.rootLogger=DEBUG,A1, A2 log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.Threshold=DEBUG log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd}-%t-%x-%-5p-%-10c:%m%n log4j.appender.A2.File=${catalina.home}/logs/app.log log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender log4j.appender.A2.DatePattern='.' yyyy-MM-dd log4j.appender.A2.MaxFileSize=10MB log4j.appender.A2.MaxBackupIndex=99 log4j.appender.A2.Append=true log4j.appender.A2.layout=org.apache.log4j.PatternLayout log4j.appender.A2.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS}-%t-%x-%-5p-%-10c:%m%n
In the app, log4j is instantiated with
static Logger logger = Logger.getLogger(ClassName.class.getName());
app.log never gets created. If I create it manually, it is never written to. The only logging going on is in logs/catalina.out. What am I missing? I've read through http://tomcat.apache.org/tomcat-7.0-doc/logging.html several times. The following excerpt seems to confirm my approach:
These steps are not needed if you just want to use log4j in your own web application. — In that case, just put log4j.jar and log4j.properties into WEB-INF/lib and WEB-INF/classes of your web application.
There is a log4j.jar and log4j.xml in catalina_home/lib, along with a log4j.properties in catalina_home/conf. Could those be conflicting with the jars included in my WAR? I don't see any errors in catalina.out.
UPDATE
So it appears that the log4j.properties in WEB-INF/classes is loading. I removed the ConsoleAppender (log4j.appender.A1) and log messages stopped appearing in catalina.out. I put it back in and the log messages reappeared in catalina.out. What's weird is the conversion pattern doesn't seem to match the log. Shouldn't
%d{yyyy-MM-dd}-%t-%x-%-5p-%-10c:%m%n
generate something like2013-07-10 INFO ClassName Log message
? Instead I'm seeing14:39:29,180 INFO [ClassName] Log message
.UPDATE 2
I found my answer. There was a log4j.xml in ${catalina.home}/lib that was configuring log4j at the container level. I guess if I actually new what I was doing in Tomcat I would have figured it out sooner. Once I started configuring lib/log4j.xml I got the expected result. I'm still a little confused why my app inherited that configuration instead of using its own log4j.properties. Oh well, I achieved the intended result so time to move on.
原文:https://stackoverflow.com/questions/17561257
最满意答案
有些术语是多余的,因为无论如何Java都会采取这种行为。
A·k mod 2^w
在Java中,整数乘法溢出并因此执行mod
2^w
(带符号)。 它有一个符号的事实并不重要,如果你正在移动至少一个位。
(w - r)
的移位与Java中-r
的移位相同(w由类型表示)private static final int K_PRIME = (int) 2999999929L; public static int hash(int a, int r) { // return (a * K_PRIME % (2^32)) >>> (32 - r); return (a * K_PRIME) >>> -r; }
为64位
private static final long K_PRIME = new BigInteger("9876534021204356789").longValue(); public static long hash(long a, int r) { // return (a * K_PRIME % (2^64)) >>> (64 - r); return (a * K_PRIME) >>> -r; }
我已经写了这个例子来说明你可以在BigInteger中做同样的事情,你为什么不做。 ;)
public static final BigInteger BI_K_PRIME = new BigInteger("9876534021204356789"); private static long K_PRIME = BI_K_PRIME.longValue(); public static long hash(long a, int r) { // return (a * K_PRIME % (2^64)) >>> (64 - r); return (a * K_PRIME) >>> -r; } public static long biHash(long a, int r) { return BigInteger.valueOf(a).multiply(BI_K_PRIME).mod(BigInteger.valueOf(2).pow(64)).shiftRight(64 - r).longValue(); } public static void main(String... args) { Random rand = new Random(); for (int i = 0; i < 10000; i++) { long a = rand.nextLong(); for (int r = 1; r < 64; r++) { long h1 = hash(a, r); long h2 = biHash(a, r); if (h1 != h2) throw new AssertionError("Expected " + h2 + " but got " + h1); } } int runs = 1000000; long start1 = System.nanoTime(); for (int i = 0; i < runs; i++) hash(i, i & 63); long time1 = System.nanoTime() - start1; long start2 = System.nanoTime(); for (int i = 0; i < runs; i++) biHash(i, i & 63); long time2 = System.nanoTime() - start2; System.out.printf("hash with long took an average of %,d ns, " + "hash with BigInteger took an average of %,d ns%n", time1 / runs, time2 / runs); }
版画
hash with long took an average of 3 ns, \ hash with BigInteger took an average of 905 ns
Some of the terms are redundant because Java assumes this behaviour anyway.
A·k mod 2^w
In Java, integer multiplication overflows and thus does a mod
2^w
(with a sign). The fact that it has a sign doesn't matter if you are then shifting by at least one bit.Shift of
(w - r)
is the same as a shift of-r
in Java (the w is implied by the type)private static final int K_PRIME = (int) 2999999929L; public static int hash(int a, int r) { // return (a * K_PRIME % (2^32)) >>> (32 - r); return (a * K_PRIME) >>> -r; }
for 64-bit
private static final long K_PRIME = new BigInteger("9876534021204356789").longValue(); public static long hash(long a, int r) { // return (a * K_PRIME % (2^64)) >>> (64 - r); return (a * K_PRIME) >>> -r; }
I have written this example to show you can do the same thing in BigInteger and why you wouldn't. ;)
public static final BigInteger BI_K_PRIME = new BigInteger("9876534021204356789"); private static long K_PRIME = BI_K_PRIME.longValue(); public static long hash(long a, int r) { // return (a * K_PRIME % (2^64)) >>> (64 - r); return (a * K_PRIME) >>> -r; } public static long biHash(long a, int r) { return BigInteger.valueOf(a).multiply(BI_K_PRIME).mod(BigInteger.valueOf(2).pow(64)).shiftRight(64 - r).longValue(); } public static void main(String... args) { Random rand = new Random(); for (int i = 0; i < 10000; i++) { long a = rand.nextLong(); for (int r = 1; r < 64; r++) { long h1 = hash(a, r); long h2 = biHash(a, r); if (h1 != h2) throw new AssertionError("Expected " + h2 + " but got " + h1); } } int runs = 1000000; long start1 = System.nanoTime(); for (int i = 0; i < runs; i++) hash(i, i & 63); long time1 = System.nanoTime() - start1; long start2 = System.nanoTime(); for (int i = 0; i < runs; i++) biHash(i, i & 63); long time2 = System.nanoTime() - start2; System.out.printf("hash with long took an average of %,d ns, " + "hash with BigInteger took an average of %,d ns%n", time1 / runs, time2 / runs); }
prints
hash with long took an average of 3 ns, \ hash with BigInteger took an average of 905 ns
相关问答
更多-
关于这个问题的新细节引出了我的答案。 我本来会关闭这个问题,但是我发现了一些有用的东西,所以为了记录起见,我将把它们留在这里。 天下奇闻 根据我的情况,当设置marginTop不适用于任何值。 我不得不使用带负值的layout_marginBottom 。 我的解决方案 我发现在这个布局之外有许多父容器,这个布局被加载到那里。 我不得不对其中的一些测试clipChildren="false" ,但我终于发现了导致问题的原因。 所以这是剪辑儿童和布局边距的组合导致我的问题。 希望有人会从我失去的时间中获益 N ...
-
打开模式与C fopen() std库函数完全相同。 BSD fopen页定义如下: The argument mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.): ``r'' Open text file for reading. The stream is positioned at the ...
-
这不是原始的绊倒你的原始字符串; 你误解了os.path.join 。 当组件不以一个开头时, os.path.join 应该添加一个斜杠。 如果斜杠已经存在,它将被视为绝对路径的开头,它会丢弃前面的组件并再次从头开始(除了在Windows上,驱动器号)。 来自文档: 如果组件是绝对路径,则抛弃所有先前组件并从绝对路径组件继续连接。 在Windows上,遇到绝对路径组件(例如,r'\ foo')时,不会重置驱动器号。 如果组件包含驱动器号,则会丢弃所有先前的组件并重置驱动器号。 请注意,由于每个驱动器都有一 ...
-
一方面,XPath表达式 for t in q.xpath('/../..//w:instrText...'...) 没有意义。 初始/表示“从根节点开始”(即最外层元素的父节点)。 以下步骤, .. ,表示“上下文节点的父节点”。 但是根节点没有父节点。 所以这个表达式什么都不会选。 (实际上,在XPath 1.0中, /..用作指定空节点集的便捷方式。) 相反,你可能想要 for t in q.xpath('../..//w:instrText...'...) 它取自上下文节点的父节点( t的值 ...
-
我认为一个明智的方法是这样进行: 使用String.split(",")将字符串拆分为字符串数组(称之为labelsIn String.split(",") 。 创建一个ArrayList
(称之为labelsOut )来保存结果。 循环遍历labelsIn数组和每个元素: 如果它与模式 [AZ][0-9]+ 匹配,则将其附加到labelsOut列表。 否则,如果它匹配模式([AZ])([0-9]+)-\1([0-9]+) (调用Matcher对象match ),则提取low和high的数字 ... -
有些术语是多余的,因为无论如何Java都会采取这种行为。 A·k mod 2^w 在Java中,整数乘法溢出并因此执行mod 2^w (带符号)。 它有一个符号的事实并不重要,如果你正在移动至少一个位。 (w - r)的移位与Java中-r的移位相同(w由类型表示) private static final int K_PRIME = (int) 2999999929L; public static int hash(int a, int r) { // return (a * K_PRIME % ...
-
无法让日志显示真正的IP w / mod_remoteip和Sucuri(Can't get Logs to Show Real IP w/ mod_remoteip and Sucuri)[2022-10-22]
看起来你的“RemoteIPHeader”配置不正确。 删除您在那里的内容,并尝试将其设置为: RemoteIPHeader X-Forwarded-For 它应该工作。 希望能帮助到你。 谢谢, It seems like your "RemoteIPHeader" is not configured properly. Remove what you have there and try to set it only as: RemoteIPHeader X-Forwarded-For And it ... -
想出来(有点)。 从http://snaps.php.net/获得最新的开发版本(5.3-201105190430)并编译并安装它。 这解决了这个问题(显然他们知道这个问题并让它排队等候)。 谢谢! Figured it out (sort of). Got the latest dev build (5.3-201105190430) from http://snaps.php.net/ and compiled & installed it. That fixed the problem (so app ...
-
线a←min {wi,W-w}实际上给出'a'的值,该值是w [i]和Ww的最小值。 if w[i] < W-w then a ← w[i] otherwise a ← W-w 对于您可以执行的实现 [w[i], W-w].min The line a ← min{wi, W − w} actually gives a value to 'a' which is minimum value of w[i] and W-w. if w[i] < W-w then a ← w[i] otherwise a ...
-
:help :command 显示:command的文档。 :help i_ctrl-a 显示插入模式下
的文档。 如何使用文档是新的vimmer应该学习的最重要的事情 。 认真。 如果您遇到棘手的映射问题,请说 b ,您可以这样做 :verbose map b 知道它的作用以及它的定义。 :help :command shows the documentation for :command. :help i_ctrl-a shows the documenta ...