Datasheet

The contents of the log_output.html file are as follows:
<html>
<body>
<table border>
<tr><th>Time</th><th>Log Message</th></tr>
<tr><td>Tue Apr 20 12:43:09 EDT 2004</td><td>This is a fine log
message</td></tr>
<tr><td>Tue Apr 20 12:43:09 EDT 2004</td><td>This is a severe log
message</td></tr>
</table>
</body>
</html>
Note that the root logger, by default, logs messages at level INFO and above. However, because the
ParentLogger is only interested in levels at WARNING and above, log messages with lower levels are
immediately discarded. The HTML file contains all log messages because the
ChildLogger is set to pro-
cess all log messages. The XML file contains only the one
SEVERE log message, because log messages
below the
WARNING level are discarded.
Regular Expressions
Regular expressions are a powerful facility available to solve problems relating to the searching, isolat-
ing, and/or replacing of chunks of text inside strings. The subject of regular expressions (sometimes
abbreviated regexp or regexps) is large enough that it deserves its own book and indeed, books have
been devoted to regular expressions. This section provides an overview of regular expressions and dis-
cusses the support Sun has built in to the
java.util.regex package.
Regular expressions alleviate a lot of the tedium of working with a simple parser, providing complex pat-
tern matching capabilities. Regular expressions can be used to process text of any sort. For more sophisti-
cated examples of regular expressions, consult another book that is dedicated to regular expressions.
If you’ve never seen regular expressions before in a language, you’ve most likely seen a small subset of
regular expressions with file masks on Unix/DOS/Windows. For example, you might see the following
files in a directory:
Test.java
Test.class
StringProcessor.java
StringProcessor.class
Token.java
Token.class
You can type dir *.* at the command line (on DOS/Windows) and every file will be matched and
listed. The asterisks are replaced with any string, and the period is taken literally. If the file mask
T*.class is used, only two files will be matched Test.class and Token.class. The asterisks are
considered meta-characters, and the period and letters are considered normal characters. The meta-
characters are part of the regular expression “language,” and Java has a rich set of these that go well
beyond the simple support in file masks. The normal characters match literally against the string being
tested. There is also a facility to interpret meta-characters literally in the regular expression language.
60
Part I: Thinking Like a Java Developer
05_777106 ch01.qxp 11/28/06 10:43 PM Page 60