14.01.2013 Views

Chapter 9: Using the Apache Log Tag Library - BeKnowledge

Chapter 9: Using the Apache Log Tag Library - BeKnowledge

Chapter 9: Using the Apache Log Tag Library - BeKnowledge

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Chapter</strong> 9: <strong>Using</strong> <strong>the</strong> <strong>Apache</strong> <strong>Log</strong> <strong>Tag</strong> <strong>Library</strong><br />

log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n<br />

log4j.appender.R=org.apache.log4j.RollingFileAppender<br />

log4j.appender.R.File=logtags.log<br />

log4j.appender.R.MaxFileSize=100KB<br />

# Keep one backup file<br />

log4j.appender.R.MaxBackupIndex=2<br />

log4j.appender.R.layout=org.apache.log4j.PatternLayout<br />

log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n<br />

With <strong>the</strong>se settings in place, execute <strong>the</strong> JSP presented in Listing 9-8. This JSP includes a TRACE-level<br />

message.<br />

Listing 9-8: Simple<strong>Log</strong>Trace.jsp<br />

<br />

<br />

<br />

Test <strong>Log</strong> <strong>Tag</strong> <strong>Library</strong><br />

Trace level message.<br />

You should see output in <strong>the</strong> debug logs now.<br />

<br />

<br />

Executing this JSP will produce <strong>the</strong> following message with <strong>the</strong> TRACE level in <strong>the</strong> Web server<br />

console:<br />

TRACE [Thread-11] (<strong>Log</strong>ger<strong>Tag</strong>.java:109) - Trace level message.<br />

Conclusion<br />

Page 10 of 11<br />

In this chapter, we discussed a newly released tag library, <strong>Log</strong>, from <strong>Apache</strong>, for using log4j within a<br />

JSP to perform logging. This solves <strong>the</strong> age-old problem of having controlled logging from within a<br />

JSP. By changing <strong>the</strong> configuration, it is possible to redirect logging information to any preferred<br />

destination in any desired format. But careful consideration is required before you include in your Web<br />

application CPU-intensive logging operations such as writing logging data to a database, as it might<br />

affect <strong>the</strong> performance of that application.<br />

This brings us to <strong>the</strong> end of <strong>the</strong> log4j discussion. All <strong>the</strong> topics explained in <strong>Chapter</strong>s 5 through 9 should<br />

help you understand <strong>the</strong> internals of log4j and how to use it in practical applications. The smaller<br />

examples provided should enable you to grasp <strong>the</strong> concepts presented and see quick results to better<br />

understand <strong>the</strong> use of log4j. The more extensive examples should help you to correlate <strong>the</strong> use of log4j<br />

file://C:\Documents and Settings\deepak\Local Settings\Temp\~hh572B.htm<br />

6/14/2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!