Unhandled Exception
Unhandled Exception

Reputation: 1513

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.

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.

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.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.

Is there another requirement missing that needs to be set in order to obtain output?

Upvotes: 0

Views: 421

Answers (1)

cerebro84
cerebro84

Reputation: 28

From the documentation of 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.

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"

See also this other answer.

Upvotes: 1

Related Questions