0

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?

Unhandled Exception
  • 1,427
  • 14
  • 30
  • Second answer to a quick google search for "log4j.properties location": https://crunchify.com/java-how-to-configure-log4j-logger-property-correctly/ - in short: the file belongs in your classpath, e.g. your src folder, a resources folder or similar, depending on how you build your application. – Thomas Nov 28 '18 at 15:49

1 Answers1

1

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.

cerebro84
  • 28
  • 10
  • I attempted to add this line in the Properties file for the javaws but it does not allow colons or quotes. Checking the Java Control Panel and it can be added there but it only affects java, not javaws. How can it be added for the javaws program. Keep in mind I don't have source access and only access as the end user. – Unhandled Exception Nov 28 '18 at 17:19
  • Using javaws -J--Dlog4j.configuration="file:C:\Configuration\log4j.properties" -localfile ....... runs the applicatoin but still no output file which makes me wonder now if the entry in my initial question is configured wrong for writing to a file. – Unhandled Exception Nov 28 '18 at 17:51
  • Try to run the application with -Dlog4j.debug to display some debug information about log4j configuration at startup, it can give you useful hints. – cerebro84 Nov 29 '18 at 09:29