Monday, March 12, 2007

Dumping environment variables

If you ever wanted to know what your "accessible" environment variables are at run time, put the code snippet below anywhere within your code execution path and print either to your log or System.out.

StringBuffer sb = new StringBuffer();
sb.append("Environment vars: ---------------------------------------\n");
Properties props = System.getProperties();
if(props != null && props.size() > 0) {
Enumeration enum = props.keys();
String key = null;
while(enum.hasMoreElements()) {
key = (String)enum.nextElement();
sb.append(key + ": " + props.getProperty(key) + "\n");
}
}
sb.append("\nEnvironment vars: ---------------------------------------\n");
//System.out.println(sb.toString());
logger.info(sb.toString());

No comments:

Post a Comment