views:

271

answers:

3

Hey

This is a bit of a weird request but I am trying to set some jvmargs in the log4j.properties file. At present I use ant to for example set some args....

jvmarg value="-Dmail.smtp.socketFactory.port=465"

... but it would be great to group a few of these logging relevant arguments into the .properties file. Does anyone know how to do this?

Thanks in advance!

+1  A: 

Log4j is only going to read the properties file after the JVM has already started - that means it can't affect the JVM arguments.

Jon Skeet
A: 

If your example is from your actual situation then you can set this value programatically for the java mail...

The SMTP protocol provider supports the following properties, which may be set in the JavaMail Session object. The properties are always set as strings; the Type column describes how the string is interpreted. For example, use

    props.put("mail.smtp.port", "888");

http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html

This example above should work for mail.smtp.socketFactory.port also.

grahamrb
This is something we have looked at, but ideally we would like to keep the configuration separate from the code so we can swap in different logging systems easily at a later date...I am trying to set:mail.smtp.portmail.smtp.socketFactory.classmail.smtp.socketFactory.portmail.smtp.socketFactory.fallbackSetting them in the ant build file is ok... but not ideal :(
Thomas
A: 

If the properties can be added after JVM startup, you could add a property to your properties file that lists all properties that you want to add to the SystemProperties collection, something like:

# property names of system properties
systemprops=mail.smtp.port mail.smtp.socketFactory.class

mail.smtp.port=465
mail.smtp.socketFactory.class=some.class

Your startup code can read the systemprops value, split on whitespace and add the resulting list of properties to the SystemProperties collection while reading the values from your properties collection.

This way your code does not need to know which properties to add to system props, only that the properties to add are defined by the systemprops property.

rsp