How to get useful system information in java?

What system information is useful - especially when tracking an exception or other issues - in a Java application?

I think about the details of exceptions, information about java / os, memory / object requirements, environment information, environment / enchodings, etc.

+7
java exception system-properties
source share
5 answers

For applications with pure Java:

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") 
0
source share

Beyond the obvious - tracing the exception stack - the more information you can get is better. Thus, you should get all the properties of the system, as well as the environment variables. Also, if your application has some settings, get all your values. Of course, you should put all this information in your log file, I used System.out for its 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)); } 

In most cases, this will be β€œtoo much” information, but for most cases, stack tracing will be sufficient. As soon as you encounter a serious problem, you will be happy that you will have all this "additional" information.

+2
source share

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

+1
source share

Also, for Java servlet applications:

 response.getCharacterEncoding() request.getSession().getId() request.getRemoteHost() request.getHeader("User-Agent") pageContext.getServletConfig().getServletContext().getServerInfo() 
0
source share

One thing that really helps me is to see where my classes are loading from.

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

note: protectiondomain can be null, as code can generate, so do null checks

0
source share

All Articles