Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to log in an applet

 
Angus Comber
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a Java application you can log to a file (or the console) but how can you create logging information in an applet?
 
Nam Ha
Ranch Hand
Posts: 50
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angus Comber wrote:In a Java application you can log to a file (or the console) but how can you create logging information in an applet?


Applet has its own console window called Java Plugin Console.

Have a lookt at: Java Plug-in Console
 
Angus Comber
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah ok I have seen that. So System.out.println() goes there?
 
Nam Ha
Ranch Hand
Posts: 50
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angus Comber wrote:Ah ok I have seen that. So System.out.println() goes there?

That's right.
 
B Alin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a logging library such as log4j from the apache software foundation.

If you decide to use this, a good idea is to get chainsaw also. The idea is to display the logging messages from log4j in a user-friendly interface as chainsaw.

More pointers :
- for each class use it's own logging object :
class MyClass {
static final private Logger logger = Logger.getInstance(MyClass.class);
[ ... code ... ]
}

- how to configure logger in the "log4j.properties" file for your project :

log4j.rootLogger=TRACE, Chainsaw

log4j.appender.Chainsaw=org.apache.log4j.net.SocketAppender
log4j.appender.Chainsaw.layout=org.apache.log4j.PatternLayout
log4j.appender.Chainsaw.layout.ConversionPattern=%M - %L %n%m
#log4j.appender.Chainsaw.RemoteHost=localhost
log4j.appender.Chainsaw.RemoteHost=192.168.0.26
log4j.appender.Chainsaw.Port=4445
log4j.appender.Chainsaw.LocationInfo=true

Works like a charm
 
Tim Moores
Bartender
Posts: 2789
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be very unusual to go to the trouble of setting up log4j in an applet; I wouldn't recommend it.
 
B Alin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
very unusual ?

funny thing, my co-workers agree it's unusual and at the same time expect me to trace bugs using messages to System.out and/or running the applet step-by-step in debug mode (NetBeans or your choice of an IDE).

unusual ? granted. useful ? very.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic