tags:

views:

72

answers:

2

How can I set up a JTextArea to receive anything that I log (short of creating an interface such as "MyLoggerListener" and implementing it into my JTextArea)

EDIT:

I fixed this problem by creating a TextAreaOutputStream, making a printwriter with it, and adding a WriterAppender with the printwriter in the constructor.

A: 

You can try to redirect it's output to something like this Create Java console inside panel

alt text

That is, you can sort of subclass Console logger ( or whatever it's name is ) and redirect the output to that component.

OscarRyz
+1  A: 

I think @OscarRyz's approach is a reasonable idea.

However, I think you should think hard whether you should try to do this. The problem is that painting log messages into a Java GUI is likely to be CPU intensive. This is likely to make your application logging slow, and is likely to perturb the timing of your application as a result.

(Not that your application should be timing sensitive. But if you do have timing related bugs, it is not helpful if changing logging levels etc causes the application to behave differently.)

My feeling is that embedding a fancy log viewer in your application is likely to be more trouble than it is worth ...

Stephen C
+1 I agree :) Probably you could do a log reader instead that works isolated from the logging it self. Mmm probably http://logging.apache.org/chainsaw/index.html is in order, but I never used it
OscarRyz