aspose file tools*
The moose likes Java in General and the fly likes Saving Java Console output to file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Saving Java Console output to file" Watch "Saving Java Console output to file" New topic
Author

Saving Java Console output to file

John McParland
Ranch Hand

Joined: May 11, 2009
Posts: 92

Hi folks,

I was wondering if there is a way to save the output displayed on the Java console to a file? Unfortunately for the situation I'm testing updating the code is not an option so it would have to be a setting or something I can change.

A web search only ever seems to reveal code changes to make

John


Passed: SCJP 6 (90%), SCJD 6
Other: Spring training, extensive Swing experience
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

The Java console meaning JConsole, or meaning the OS console window (CMD.EXE) ? If it's the latter, the answer varies by OS, of course, but generally there's a way of cutting and pasting out of that window and into a file. For example, in Windows, if you enable "Smart Edit" in the Properties tab for your consoles, then you can rightclick-drag across text to select it. Furthermore, the same Properties wizard lets you set the scrollback of the window so that lines that scroll off the screen don't disappear.

If you mean JConsole, screenshots are about the best you can do, I think.


[Jess in Action][AskingGoodQuestions]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

Use > in the console to redirect the standard output, use 2> to redirect the standard error output:
To merge the standard output and error output redirect the error output to the standard output (it must be put after the standard output redirection or it will redirect to the old standard output - the console):


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
John McParland
Ranch Hand

Joined: May 11, 2009
Posts: 92

Hi Ernest,

thanks for the swift reply.

The console I mean is the one which is shown when you web-start an application (picture attached). Unfortunately a screenshot isn't possible in this case because I'm trying to get some logging from my application at the moment of shutdown (when unfortunately the Java console dissapears also).

To do the same thing (on a windows system), go to control panel -> switch to classic view -> java -> advanced tab -> console -> show console.
Launch a webstarted application (I chose BorderDemo from http://java.sun.com/docs/books/tutorial/uiswing/examples/components/index.html#table)

John



[Thumbnail for javaconsole.JPG]

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

That "Copy" button looks useful -- copy, then paste into a file in Notepad.
John McParland
Ranch Hand

Joined: May 11, 2009
Posts: 92

Hi,

I need to capture logging at the point my application exits. This exits the JVM too (System.exit()) and the console then dies so I do not have time to do the copy.

A way to make the console persist after the application which started it would be helpful too if it is not possible to have it automatically written to a file somewhere.

Regards,

John
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Change your logging options?
Frank Nguyen
Greenhorn

Joined: Mar 11, 2010
Posts: 2
The log file is saved as "plugin#####.log" in C:\Documents and Settings\[your login]\Application Data\Sun\Java\Deployment\log.


[Thumbnail for java console log file.PNG]

Frank Nguyen
Greenhorn

Joined: Mar 11, 2010
Posts: 2
A new plugin log file will be generated every time you open a new browser. You just need to get the latest one, read lines, and collect your outputs or any exceptions.

Frank
Akhash Ramamurthy
Greenhorn

Joined: Nov 02, 2009
Posts: 25
Frank Nguyen wrote:A new plugin log file will be generated every time you open a new browser. You just need to get the latest one, read lines, and collect your outputs or any exceptions.

Frank


Thanks Frank. Saved me a lot of time for me.

Akhash


Software Engg
Akhash
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Saving Java Console output to file