2

Is there a way to turn tracing and logging on for a java application which is neither a Java Web Start nor applet type of java application? I'm talking about an application that would be executed by either double clicking on an executable jar file or launched from the command line by typing java -jar nameofjarfile.jar. I have enabled logging and tracing in the Java Control Panel but this seems to have no effect. The only trace logs that I see are trace logs generated for execution of the java control panel. As far as I can discern from the documentation the options in the java control panel to enable logging and tracing are specific to Web Start and applet style applications. When I launch my desktop java application no .trace file is generated.

Thanks in advance.

George
  • 41
  • 5
  • 1
    Redirect stdout to a file. http://stackoverflow.com/questions/2851234/system-out-to-a-file-in-java – Shankar Shastri Sep 12 '16 at 17:26
  • 1
    Logging and tracing in the control panel is for JVM logging. You need to investigate how the application you use is logging, and configure accordingly. – Thorbjørn Ravn Andersen Sep 12 '16 at 17:33
  • My app isn't using any logging facilities only some output to Standard Out. I need .trace file that should be created when tracing is enabled. Its a requirement for certifying my app to run on my corporate network. Is the reason the .trace file isn't being created because my app is not using any logging or is it that the tracing option in the java control panel and deployment.properties file are only a means to capture a trace log for apps launched with the browser plugin where a java desktop app should be configurable as to where to store a logging frame works trace log? – George Sep 12 '16 at 19:02
  • This comment is in reply to Shankar Shastri: Is a trace file only a redirect of standard out? In the recent past I've seen trace files which output quite a bit of JVM state information. It looked like JVM bootstrap information. Even file paths to particular classes were given. I'm under the impression that it was the java trace facilities providing that information but maybe it was the logging facilities the particular app was using. – George Sep 12 '16 at 19:51

2 Answers2

1

I am not sure exactly what you are looking for, but for logging you can use multiple readily available logging tools such as slf4j or log4j just to name 2 that I used. They could be easily integrated into ANY application regardless whether it is web based or not. Here are the links to those 2: Log4J, slf4j. Also you may find Mgnt library useful. One of its utilities allows you to filter and significantly shorten your stacktrace without loosing meaningful information. But this one is actually the most effective for web based apps that produce very long stacktraces with a lot of meaningless info. Anyway here is the link to the article about Mgnt library with the links to it as well as its sources: Mgnt

Michael Gantman
  • 5,975
  • 1
  • 17
  • 34
  • I'm required to provide a trace log for my application as one of the requirements to receive certification that it runs properly on a specific platform. Judging by the comments received so far I'm thinking that maybe a logging facility such as log4j is required for a trace log to be created. I'm not currently using any logging. Just user notification and some console output. Is it the case that logging must be used in order for the trace log to be created? – George Sep 12 '16 at 18:22
  • 1
    Logging is whatever your app needs to log. You may choose not to log at all, but that wouldn't be an acceptable practice besides the most simple apps. Once you decide to write logs you need to choose what logging tools are you going to use. In my answer I provided 2 best known to me. As for tracing - see this link: http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/jcp/tracing_logging.html#tracing – Michael Gantman Sep 12 '16 at 18:57
  • I have read that article and it specifically mentions Tracing for Java Plug-in and Java Web Start". There is no mention anywhere on how to enable tracing for a java application which is not either Java Web Start or a java applet. Thank you for the links to the logging library's I have been considering log4j for some time now but I plan to integrate it later. Right now I just need to provide a .trace file for the certification my application requires and was hopping there was something simple I was missing as to why one isn't created even though tracing is enabled. – George Sep 12 '16 at 19:22
  • 1
    A quote from the article above "Tracing is a facility to redirect any output in the Java Console to a trace file." So tracing is just moving any output that was meant for console to a file. If you have no output, then there is no trace... This basically would take anything you print with System.out.println() or System.err.println() and put into a file instead of console. – Michael Gantman Sep 13 '16 at 09:53
0

It appears there is no equivalent to the trace option offered in the Java Control Panel for apps that are launched using the regular virtual machine. The options in the Java Control Panel are specifically for Java Web Start Apps and Java Applets. It has no effect on the Java Desktop Applications launched by double clicking an executable jar file or by typing java -jar javaapp.jar at the command line. While the documentation states that tracing is output from the java console to a .trace file the console to which they speak is the Java Console that is only available for Web Start and Applets. They are not speaking of just standard out and standard error. While both standard out and standard error does get output to the Java Console the Java Console also includes boot strap information of the JVM itself such as the java version, the exact path of the java executable file, proxy information and much more. I'm sure there may be a way to generate equivalent data it can not be done through the Java Control Panel's trace and log options or with Deployment Property options such as -DDeployment.trace = true. You can see the information I'm speaking of by going to the java tutorials and launching one of the many web start apps they link to in their tutorials. Make sure to go to the Java Control Panel and tick the Show Console option under the advanced tab. When you launch a Java Web Start App with this option selected the Java Console will open. The output to that console is what is dumped to the .trace file when Enable Tracing is selected in the same Advanced tab of the Java Control Panel. If you also enable logging it appears that console output is output to a .log file but in an XML format.

George
  • 41
  • 5