views:

144

answers:

5

Which system information are useful - especially when tracing an exception or other problems down - in a java application?

I am thinking about details about exceptions, java/os information, memory/object consumptions, io information, environment/enchodings etc.

+1  A: 

Besides the obvious - the exception stack trace - the more info you can get is better. So you should get all the system properties as well as environment variables. Also if your application have some settings, get all their values. Of course you should put all this info into your log file, I used System.out her for simplicity:

System.out.println("----Java System Properties----");       
System.getProperties().list(System.out);

System.out.println("----System Environment Variables----");
Map<String, String> env = System.getenv();
Set<String> keys = env.keySet();
for (String key : keys) {
    System.out.println(key + "=" + env.get(key));
}

For most cases this will be "too much" information, but for most cases the stack trace will be enough. Once you will get a tough issue you will be happy that you have all that "extra" information

ZloiAdun
A: 

For pure java applications:

System.getProperty("org.xml.sax.driver") 
System.getProperty("java.version")
System.getProperty("java.vm.version")
System.getProperty("os.name")
System.getProperty("os.version")
System.getProperty("os.arch")
MRalwasser
Maybe System.getProperties().list to get all of them?
ZloiAdun
A: 

In addition, for java servlet applications:

response.getCharacterEncoding()
request.getSession().getId()
request.getRemoteHost()
request.getHeader("User-Agent") 
pageContext.getServletConfig().getServletContext().getServerInfo()
MRalwasser
+1  A: 

Check out the Javadoc for System.getProperties() which documents the properties that are guaranteed to exist in every JVM.

krock
A: 

One thing that really helps me- to see where my classes are getting loaded from.

obj.getClass().getProtectionDomain().getCodeSource().getLocation();

note: protectiondomain can be null as can code source so do the needed null checks

unmaskableinterrupt