[英]Log4j doesn't log INFO Level
I have the following log4j.properties file, for an application deployed in WebSphere Portal: 对于WebSphere Portal中部署的应用程序,我有以下log4j.properties文件:
log4j.rootLogger=DEBUG, InfoAppender, DebugAppender
log4j.appender.InfoAppender=org.apache.log4j.RollingFileAppender
log4j.appender.InfoAppender.Threshold=INFO
log4j.appender.InfoAppender.File=C:/info.log
log4j.appender.InfoAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.InfoAppender.layout.ConversionPattern=%d %p [%c] - %m%n
log4j.appender.DebugAppender=org.apache.log4j.RollingFileAppender
log4j.appender.DebugAppender.Threshold=DEBUG
log4j.appender.DebugAppender.File=C:/debug.log
log4j.appender.DebugAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.DebugAppender.layout.ConversionPattern=%d %p [%c] - %m%n
When I code, I define the logger at class level: 当我编码时,我在类级别定义记录器:
private static Logger logger = Logger.getLogger(IWannaLogThis.class);
And I log INFO messages with this: 我用这个记录INFO消息:
logger.info(theObjectToLog);
When I deploy my application, the debug.log
file gets everything I log with logger.debug()
but ignores everything I write with logger.info()
. 当我部署我的应用程序时,
debug.log
文件中获得的一切,我登录logger.debug()
但忽略一切我写logger.info()
On the other side, the info.log
file keeps empty. 另一方面,
info.log
文件保持为空。
The weirdest thing is that in debug.log
and info.log
appears some INFO and DEBUG messages made by some JARS (like Hibernate Validator) I had in the classpath, but just ignores everything I try to log in my code. 最奇怪的是,在
debug.log
和info.log
出现了一些由类路径中的JARS(如Hibernate Validator)发出的INFO和DEBUG消息,但忽略了我尝试登录代码的所有内容。
Any ideas? 有任何想法吗?
This is most likely a classloading-related problem. 这很可能是与类加载相关的问题。 WebSphere Portal uses Log4J internally, so I'm guessing that you end up using WebSphere Portal's provided Log4J JAR file as well as its own Log4J properties.
WebSphere Portal在内部使用Log4J,所以我猜你最终会使用WebSphere Portal提供的Log4J JAR文件以及它自己的Log4J属性。
You can verify that by adding the following to the JVM arguments of the server instance: 您可以通过将以下内容添加到服务器实例的JVM参数来验证:
-Dlog4j.debug=true
And then inspect the SystemOut.log
file. 然后检查
SystemOut.log
文件。 Log4J will spit out lots of tracing information about the configuration file(s) it reads. Log4J将吐出大量有关其读取的配置文件的跟踪信息。
The best way to avoid this is to do the following: 避免这种情况的最佳方法是执行以下操作:
As an alternative to step 2, you can bundle your Log4J configuration file with the application itself, however that would carry its own drawbacks (for example, having to repackage your application whenever you perform a Log4J configuration change). 作为第2步的替代方法,您可以将Log4J配置文件与应用程序本身捆绑在一起,但这会带来其自身的缺点(例如,每当执行Log4J配置更改时都必须重新打包应用程序)。
Another common problem is that the JARs you have in your classpath also use log4j and also have their own appenders set. 另一个常见问题是您在类路径中使用的JAR也使用log4j并且还设置了自己的appender。 So depending on the settings that they use, and the packages that your classes reside in, this may lead to the problem you describe.
因此,根据他们使用的设置以及您的类所在的包,这可能会导致您描述的问题。
So: 所以:
Normally, it should be one of these things. 通常,它应该是这些事情之一。 Post more explicit example if it doesn't work.
如果不起作用,请发布更明确的示例。
Good luck! 祝好运!
What I have done in the past is set specific logs for the classes I want to log. 我过去所做的是为我要记录的类设置特定日志。 It sounds like you can try setting your root logger to INFO and see if that gets you the messages you want.
听起来您可以尝试将根记录器设置为INFO,看看是否能获得您想要的消息。 Here's a little bit of my log4j property file.
这是我的log4j属性文件的一小部分。 I set a logger for each class and assign it to my "data" appender, which defines the log layout.
我为每个类设置了一个记录器,并将它分配给我的“data”appender,它定义了日志布局。 In the loggers I specify specific classes I want to log and set their Log level individually.
在记录器中,我指定了要记录的特定类,并单独设置其日志级别。 Any class that logs that is not defined in the Loggers I have use the default log level for the rootCategory.
任何记录未在Loggers中定义的类我都使用rootCategory的默认日志级别。
log4j.rootCategory=INFO, rollingFile, stdout
#GetData Loggers
log4j.logger.com.myapp.data=INFO, data
log4j.logger.com.myapp.data.SybaseConnection=DEBUG, data
log4j.logger.com.myapp.data.GetData=ERROR, data
# data appender
log4j.appender.data=org.apache.log4j.RollingFileAppender
log4j.appender.data.layout=org.apache.log4j.PatternLayout
log4j.appender.data.File=c\:\\Program Files\\MyApp\\logs\\MyApp-data.log
log4j.appender.data.Append=true
log4j.appender.data.layout.ConversionPattern=[%d{ISO8601}]%5p%6.6r[%t]%x - %C.%M(%F:%L) - %m%n
you root logger opens the log properties in the debug mode, root rootger在调试模式下打开日志属性,
use INFO instead of DEbug in the first line of your properties file. 在属性文件的第一行使用INFO而不是DEbug。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.