B.3. Adding Application-Specific Properties to System PropertiesThe InitServlet uses SystemPropertiesUtil to add the log4j.log.dir property (that represents the directory that holds the log file) from the log4j.extra.properties to the System Properties. The SystemPropertiesUtil utility looks like Example B-8. Example B-8. SystemPropertiesUtil.javapackage com.jbossatwork.util; import java.util.*; public class SystemPropertiesUtil { /** * Making the default (no arg) constructor private * ensures that this class cannnot be instantiated. */ private SystemPropertiesUtil( ) { } public static void addToSystemPropertiesFromPropsFile(String propsFileName) { Properties props = ResourceLoader.getAsProperties(propsFileName), sysProps = System.getProperties( ); // Add the keys/properties from the application-specific properties to // the System Properties. sysProps.putAll(props); } } The SystemPropertiesUtil's addToSystemPropertiesFromPropsFile( ) method adds the keys/properties from an application-specific properties file to the System Properties. The application-specific properties file MUST reside in a directory listed on the CLASSPATH. The SystemPropertiesUtil uses the ResourceLoader.getAsProperties( ) method to retrieve application-specific properties file from the CLASSPATH. We'll cover the ResourceLoader utility after we show the Log4jConfigurator. Now that we have the logging infrastructure in place, let's look more closely at the Log4jConfigurator. |