The Log Tag Library

Apr 10, 2001

0

The Log Tag Library

Posted in : JSP on by : master

The Log Tag Library is designed to give JSP tag-level access to Log4J. This tag was initially called the “Debug Tag Library,” and artifacts of this still remain in the code and example application; my apologies, and these artifacts will likely disappear as the codebase grows.

Sponsor: Nha tien che QSBSteel

Deployment

  1. Download the Log tag library. The source of the library as well as a sample application can be found in a separate file: logsrc-1.1.jar.
  2. Put the library in a directory accessible to your web application (in my case: /u/joeo/epesh.com/main-site/WEB-INF/lib/, where the web application is at .../main-site/.)
  3. Reference the library in your web application’s configuration file (web.xml) like this:
    <taglib>
      <taglib-uri>logtags</taglib-uri>
      <taglib-location>/WEB-INF/lib/logtags-1.0.jar</taglib-location>
    </taglib>
    

    If you’re using Tomcat, this isn’t correct. For this you’ll need to expand the jarfile, and refer to the taglib.tld file directly. I don’t know when Jakarta is planning on changing this.

  4. In your JSP, reference the tag library with a line similar to this:
    <%@ taglib uri="logtags" prefix="log" %>

    This will allow you to use tags named similar to: <log:info message="Now setting up the EJBS" />

  5. You will need to store log4j.jar (available from the Log4J distribution) in the web application’s classpath (the same directory that the taglib resides in should be satisfactory).

debug

<log:debug
  { message="<%= String %>" }
  { category="<%= String %>" }
>
  ... message ...
</log:debug>

The debug tag generates a DEBUG-level message in Log4J. If the message attribute is omitted, the body content is used. If the category attribute is supplied, the Log4J category will be set to this value; otherwise, a default null category is used.

info

<log:info
  { message="<%= String %>" }
  { category="<%= String %>" }
>
  ... message ...
</log:info>

The info tag generates an INFO-level message in Log4J. If the message attribute is omitted, the body content is used. If the category attribute is supplied, the Log4J category will be set to this value; otherwise, a default null category is used.

warn

<log:warn
  { message="<%= String %>" }
  { category="<%= String %>" }
>
  ... message ...
</log:warn>

The warn tag generates a WARN-level message in Log4J. If the message attribute is omitted, the body content is used. If the category attribute is supplied, the Log4J category will be set to this value; otherwise, a default null category is used.

error

<log:error
  { message="<%= String %>" }
  { category="<%= String %>" }
>
  ... message ...
</log:error>

The error tag generates an ERROR-level message in Log4J. If the message attribute is omitted, the body content is used. If the category attribute is supplied, the Log4J category will be set to this value; otherwise, a default null category is used.

Development Notes

The first use of any tag in the Log Tag Library will attempt to configure Log4J, first by using a default BasicConfigurator (which simply logs to the console) and then a PropertyConfigurator, using a property file called debug.properties. If this file is not in the web application’s classpath, Log4J will show an exception; the debug tags will then use the information from BasicConfigurator. I wouldn’t mind figuring out a nice, convenient, easy-to-use way of getting around this.

Scheduled for porting are some of the IN16 project‘s debugging tags, which dump application, session, and request data.

History

  • 2000/01/31
    Initial release and documentation

License

This library is released under the Artistic License.

Sample Page

Unlike the other tag libraries provided here, the Debug Tag Library has server-only output; no sample page is provided.

Thought for the Moment
Long for excellence.

Disclaimer: Use what’s here at your own risk. © Joseph B. Ottinger 1995-2001 unless otherwise stated.