Java Reference
In-Depth Information
Discussion
Getting the debug output from a desktop client is fairly easy on most operating systems. But
if the program you want to debug is running in a “container” like a servlet engine or an EJB
server, it can be difficult to obtain debugging output, particularly if the container is running
on a remote computer. It would be convenient if you could have your program send mes-
sages back to a program on your desktop machine for immediate display. Needless to say, it's
not that hard to do this with Java's socket mechanism.
Many logging APIs can handle this:
▪ Java has had for years a standard logging API (discussed in Network Logging with
java.util.logging ) that talks to various logging mechanisms including Unix syslog .
▪ The Apache Logging Services Project produces log4j , which is used in many open
source projects that require logging (see Network Logging with log4j ) .
The Apache Jakart Commons Logging (JCL) . Not discussed here; similar to the others.
▪ SLF4J (Simple Logging Facade For Java, see Network Logging with SLF4J ) is the new-
est and, as the name implies, a facade that can use the others.
▪ And, before these became widely used, I wrote a small, simple API to handle this type of
logging function. My netlog is not discussed here because it is preferable to use one of
the standard logging mechanisms; its code is in the logging subdirectory of the javasrc
repo if you want to exhume it.
The JDK logging API, log4j , and SFL4J are more fully fleshed out and can write to such
destinations as a file, an OutputStream or Writer , or a remote log4j , Unix syslog , or Win-
dows Event Log server.
The program being debugged is the “client” from the logging API's point of view—even
though it may be running in a server-side container such as a web server or application serv-
er—because the “network client” is the program that initiates the connection. The program
that runs on your desktop machine is the “server” program for sockets because it waits for a
connection to come along.
If you want to run any network-based logger reachable from any public network, you need to
be more aware of security issues. One common form of attack is a simple denial-of-service
(DoS), during which the attacker makes a lot of connections to your server in order to slow it
down. If you are writing the logto disk, for example, the attacker could fill up your disk by
Search WWH ::




Custom Search