简体   繁体   English

log4j.properties,放在哪里

[英]log4j.properties, where to put it

According to log4j manual, I should put log4j.properties to the src folder. 根据log4j手册,我应该将log4j.properties放到src文件夹中。 I copied this file to all the possible places I think it will affect log4j. 我将此文件复制到我认为会影响log4j的所有可能位置。 However, this does not work. 但是,这不起作用。

TestEM class contains many unit test functions (I use testng). TestEM类包含许多单元测试函数(我使用testng)。 I run one of these test functions which references a class in the feedback.strategy package. 我运行其中一个测试函数,它引用了feedback.strategy包中的一个类。

我的日食项目

Here is the content of the log4j.properties file: 以下是log4j.properties文件的内容:

#log for class1
log4j.category.Demo1=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.FileAppender
log4j.appender.dest1.File=C:/Users/Asus/workspace/FeedbackProcess/logs/class1.log
log4j.appender.dest1.layout = org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern= %d %p [%t] (%c) \u2013 %m%n

This is mostly a question of convention and/or personal preference. 这主要是传统和/或个人偏好的问题。 What I am accustomed to is to create another source directory (eg config or resources ) in the project root (next to src and test ), then place the log4j.properties there. 我习惯的是在项目根目录(在srctest旁边)创建另一个源目录 (例如configresources ),然后将log4j.properties放在那里。 This can by done by you right-clicking on the newly created folder and choosing Build Path -> Use as Source Folder . 您可以通过右键单击新创建的文件夹并选择“ 构建路径” - >“用作源文件夹”来完成此操作 Optionally you can specify some inclusion/exclusion patterns too. 您也可以选择指定一些包含/排除模式。

Log4j looks for the properties file on the root of the classpath by default. 默认情况下,Log4j 在类路径根目录中查找属性文件。 With the above setup the properties file gets copied to the output directory and it will be on the root of your classpath during development. 通过上面的设置,属性文件将被复制到输出目录,并且在开发期间它将位于类路径的根目录中。

Later during the deployment the log4j.properties would get bundled in the jar/war file too. 稍后在部署期间, log4j.properties也会捆绑在jar / war文件中。 You might want to override the bundled properties by specifying an alternative config folder on the classpath during runtime. 您可能希望通过在运行时在类路径上指定备用配置文件夹来覆盖捆绑的属性。 (see this other question and the docs about the order entries take precedence on the classpath) (请参阅此其他问题 ,有关订单条目的文档优先于类路径)

您需要将log4j.properties文件放在应用程序类路径上。

maybe the file log4j.properties is being read correctly and the problem is with the configuration in log4j.properties file. 也许正在正确读取文件log4j.properties,问题在于log4j.properties文件中的配置。 Does adding this line to the begining of log4j.properties make any difference (assuming that you are have some logging statements in your class files) 将此行添加到log4j.properties的开头会有什么不同(假设您的类文件中有一些日志记录语句)

log4j.rootLogger=DEBUG, dest1

Place log4j.properties in WEB-INF\\classes of the project . 将log4j.properties放在项目的WEB-INF \\ classes中。

Put log4j-xx.jar under WEB-INF\\lib see here for details 将log4j-xx.jar放在WEB-INF \\ lib下,详细信息请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM