eclipse log4j.properties,放在哪里

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15525328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:13:04  来源:igfitidea点击:

log4j.properties, where to put it

javaeclipselog4j

提问by v4r

According to log4j manual, I should put log4j.properties to the src folder. I copied this file to all the possible places I think it will affect log4j. However, this does not work.

根据 log4j 手册,我应该将 log4j.properties 放在 src 文件夹中。我将此文件复制到我认为会影响 log4j 的所有可能位置。但是,这不起作用。

TestEM class contains many unit test functions (I use testng). I run one of these test functions which references a class in the feedback.strategy package.

TestEM 类包含许多单元测试函数(我使用 testng)。我运行这些测试函数之一,它引用了feedback.strategy 包中的一个类。

My eclipse project

我的日食项目

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

采纳答案by GJ13

maybe the file log4j.properties is being read correctly and the problem is with the configuration in log4j.properties file. 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.properties 文件中的配置。将此行添加到 log4j.properties 的开头是否有任何区别(假设您的类文件中有一些日志记录语句)

log4j.rootLogger=DEBUG, dest1

回答by Daniel Dinnyes

This is mostly a question of convention and/or personal preference. What I am accustomed to is to create another source directory(e.g. configor resources) in the project root (next to srcand test), then place the log4j.propertiesthere. 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.

这主要是惯例和/或个人偏好的问题。我习惯于在项目根目录(和旁边)创建另一个源目录(例如config或),然后将其放在那里。这可以通过右键单击新创建的文件夹并选择Build Path -> Use as Source Folder 来完成。您也可以选择指定一些包含/排除模式。resourcessrctestlog4j.properties

Log4j looks for the properties file on the root of the classpathby default. 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.

默认情况下,Log4j在类路径根目录上查找属性文件。通过上述设置,属性文件被复制到输出目录中,并且在开发过程中它将位于类路径的根目录中。

Later during the deployment the log4j.propertieswould get bundled in the jar/war file too. You might want to override the bundled properties by specifying an alternative config folder on the classpath during runtime. (see this other questionand the docsabout the order entries take precedence on the classpath)

稍后在部署期间,它log4j.properties也会被捆绑在 jar/war 文件中。您可能希望通过在运行时在类路径上指定备用配置文件夹来覆盖捆绑的属性。(请参阅this other question和有关订单条目的文档优先于类路径)

回答by Stijn Haus

You need to put the log4j.properties file on the application classpath.

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

回答by PSR

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 下 查看详情