Java Reference
In-Depth Information
Example 9-7. A logging properties file
handlers = java . util . logging . FileHandler
java . util . logging . FileHandler . pattern = / var / logs / daytime / requests . log
java . util . logging . FileHandler . limit = 10000000
java . util . logging . FileHandler . count = 2
java . util . logging . FileHandler . formatter = java . util . logging . SimpleFormatter
java . util . logging . FileHandler . append = true
java . util . logging . SimpleFormatter . format =% 4 $s : % 5 $s [% 1 $tc ]% n
requests . level = INFO
audit . level = SEVERE
Here's some typical log output (note that it looks like the timestamp is doubled in request
messages because the log message also includes the current time; this would not typically
be the case for a server whose purpose was anything other than serving the current
time):
SEVERE: Couldn ' t start server [ Sat Apr 13 10 : 07 : 01 EDT 2013 ]
INFO: Sat Apr 13 10 : 08 : 05 EDT 2013 / 0 : 0 : 0 : 0 : 0 : 0 : 0 : 1 : 57275
[ Sat Apr 13 10 : 08 : 05 EDT 2013 ]
INFO: Sat Apr 13 10 : 08 : 06 EDT 2013 / 0 : 0 : 0 : 0 : 0 : 0 : 0 : 1 : 57276
[ Sat Apr 13 10 : 08 : 06 EDT 2013 ]
The one thing I don't like about the Java Logging API is that it doesn't
give you an easy way to specify by configuration alone that different
messages belong in different logs. For instance, you can't easily sepa‐
rate your error and your audit log. It can be done, but it requires you
to define a new subclass of FileHandler for each separate log so you
can assign it a new file.
Finally, once you've configured your servers with logging, don't forget to look in them,
especially the error logs. There's no point to a logfile no one ever looks at. You'll also
want to plan for and implement log rotation and retention policies. Hard drives get
bigger every year, but it's still possible for a high-volume server to fill up a filesystem
with log data if you aren't paying attention. Murphy's law says this is most likely to
happen at 4:00 A.M. on New Year's Day when you're on vacation halfway around the
world.
Constructing Server Sockets
There are four public ServerSocket constructors:
public ServerSocket ( int port ) throws BindException , IOException
public ServerSocket ( int port , int queueLength )
throws BindException , IOException
public ServerSocket ( int port , int queueLength , InetAddress bindAddress )
Search WWH ::




Custom Search