简体   繁体   English

log4j.properties文件在客户端上的哪个位置?

[英]Where on the client to place the log4j.properties file?

A Java application makes use of the Apache logging but am unable to turn it on. Java应用程序使用Apache日志记录,但无法将其打开。

The application is a Java Web Start application which uses a signed Jar file so I am unable to make any changes to the Jar file or the code. 该应用程序是一个Java Web Start应用程序,它使用签名的Jar文件,因此我无法对Jar文件或代码进行任何更改。

A log4j.properties file with the following content was created and place in all the Java_Home/bin directories on my machine to ensure it will be picked up. 创建了一个具有以下内容的log4j.properties文件,并将其放置在我的计算机上的所有Java_Home / bin目录中,以确保将其拾取。

log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFile.File=c:/MyLoggingDir/application6.log
log4j.appender.rollingFile.layout=org.apache.log4j.PatternLayout
log4j.appender.rollingFile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n
log4j.appender.rollingFile.MaxFileSize=10MB
log4j.appender.rollingFile.MaxBackupIndex=5
log4j.appender.rollingFile.append=true

log4j.rootCategory=ALL, rollingFile

When the application starts no output is visible in the Java Console and no files are created in the c:/MyLoggingDir directory. 当应用程序启动时,在Java控制台中看不到任何输出,并且在c:/ MyLoggingDir目录中未创建任何文件。

Is there another requirement missing that needs to be set in order to obtain output? 是否还有其他需要设置的要求才能获得输出?

From the documentation of log4j : log4j文档中

Log4j will inspect the "log4j.configurationFile" system property and, if set, will attempt to load the configuration using the ConfigurationFactory that matches the file extension. Log4j将检查“ log4j.configurationFile”系统属性,如果已设置,将尝试使用与文件扩展名匹配的ConfigurationFactory加载配置。

So, for example, if you put the property file in C:\\Configuration\\log4j.properties , you should run your application with the flag -Dlog4j.configuration="file:C:\\Configuration\\log4j.properties" 因此,例如,如果将属性文件放入C:\\Configuration\\log4j.properties ,则应使用标志-Dlog4j.configuration="file:C:\\Configuration\\log4j.properties"运行应用程序

See also this other answer . 另请参阅其他答案

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

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