You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by js...@apache.org on 2001/06/26 20:50:17 UTC
cvs commit: jakarta-taglibs/log/xml log.xml
jstrachan 01/06/26 11:50:17
Modified: log build.xml
log/doc/web changes.xml
log/examples/web index.html test5.jsp
log/src/org/apache/taglibs/log DebugTag.java ErrorTag.java
InfoTag.java LoggerTag.java WarnTag.java
log/xml log.xml
Added: log/examples/conf log4j.properties
log/examples/web test6.jsp
log/lib log4j.jar
log/src/org/apache/taglibs/log FatalTag.java
Removed: log/lib log4j-core.jar
Log:
* The log tags now do not initialies log4j themselves. You can do this yourself using your own mechanism, via a log4j Servlet or by putting a log4j.properties file in WEB-INF/classes. I use the latter approach in the example web app as I find it easier.
* Optimised the tags so that the body is not evaluated if log4j has the logging category or priority disabled.
* Added new <log:fatal> tag for support for the FATAL level of log4j logging
Revision Changes Path
1.2 +6 -1 jakarta-taglibs/log/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-taglibs/log/build.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- build.xml 2001/05/10 19:29:47 1.1
+++ build.xml 2001/06/26 18:50:07 1.2
@@ -7,7 +7,7 @@
<project name="log" default="main">
<property environment="env"/>
- <property name="classpath" value="${env.SERVLET_JAR}:lib/log4j-core.jar" />
+ <property name="classpath" value="${env.SERVLET_JAR}:lib/log4j.jar" />
<property name="library.pre" value="library.pre"/>
<!-- =================================================================== -->
@@ -16,6 +16,11 @@
<target name="library.pre" depends="gen-docs">
<copy todir="${build.examples}/WEB-INF/lib">
<fileset dir="lib" includes="*.jar"/>
+ </copy>
+
+ <!-- copy a default log4j config file -->
+ <copy todir="${build.examples}/WEB-INF/classes">
+ <fileset dir="${examples.src}/conf" includes="*.properties"/>
</copy>
</target>
1.3 +32 -21 jakarta-taglibs/log/doc/web/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-taglibs/log/doc/web/changes.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- changes.xml 2001/06/17 07:29:23 1.2
+++ changes.xml 2001/06/26 18:50:08 1.3
@@ -1,21 +1,32 @@
-<?xml version="1.0"?>
-<document url="./changes.xml">
-
- <properties>
- <author>Joseph B. Ottinger</author>
- <author>James Strachan</author>
- <title>Log Tag Library: The Jakarta-Taglibs Project</title>
- </properties>
-
- <body>
-
- <section name="Log Tag Library Revision History" href="Changes">
-
- <p>Initial check into CVS from Joe's original code, ported to the Jakarta-Taglibs
- directory structure and build process.
- </p>
-
- </section>
-
- </body>
-</document>
+<?xml version="1.0"?>
+<document url="./changes.xml">
+
+ <properties>
+ <author>Joseph B. Ottinger</author>
+ <author>James Strachan</author>
+ <title>Log Tag Library: The Jakarta-Taglibs Project</title>
+ </properties>
+
+ <body>
+
+ <section name="Log Tag Library Revision History" href="Changes">
+
+ <p>Initial check into CVS from Joe's original code, ported to the Jakarta-Taglibs
+ directory structure and build process.
+ </p>
+
+ <p>Added new <log:fatal> tag for support for the FATAL level of log4j logging</p>
+
+ <p>The log tags now do not initialise log4j themselves. You can do this yourself using your own
+ mechanism, via a log4j Servlet or by putting a log4j.properties file in WEB-INF/classes.
+ We use the latter approach in the example web app as we find it easier.
+ </p>
+
+ <p>Optimised the tags so that the body is not evaluated if log4j has the logging category or
+ priority disabled.
+ </p>
+
+ </section>
+
+ </body>
+</document>
1.1 jakarta-taglibs/log/examples/conf/log4j.properties
Index: log4j.properties
===================================================================
# Sample properties to initialise log4j
log4j.rootCategory=debug, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=logtags.log
log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=2
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
1.2 +2 -1 jakarta-taglibs/log/examples/web/index.html
Index: index.html
===================================================================
RCS file: /home/cvs/jakarta-taglibs/log/examples/web/index.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- index.html 2001/05/10 19:29:56 1.1
+++ index.html 2001/06/26 18:50:10 1.2
@@ -8,7 +8,8 @@
<LI><A HREF="test2.jsp">Test #2</A> - tests <log:info />
<LI><A HREF="test3.jsp">Test #3</A> - tests <log:warn />
<LI><A HREF="test4.jsp">Test #4</A> - tests <log:error />
-<LI><A HREF="test5.jsp">Test #5</A> - tests <log:dump />
+<LI><A HREF="test5.jsp">Test #5</A> - tests <log:fatal />
+<LI><A HREF="test6.jsp">Test #6</A> - tests <log:dump />
</OL>
</BODY>
</HTML>
1.2 +5 -9 jakarta-taglibs/log/examples/web/test5.jsp
Index: test5.jsp
===================================================================
RCS file: /home/cvs/jakarta-taglibs/log/examples/web/test5.jsp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- test5.jsp 2001/05/10 19:29:56 1.1
+++ test5.jsp 2001/06/26 18:50:10 1.2
@@ -4,15 +4,11 @@
<TITLE>Test #5</TITLE>
</HEAD>
<BODY>
-<jsp:useBean id="p1" class="java.lang.String" scope="page" />
-<H4>request</H4>
-<log:dump scope="request" />
-<H4>page</H4>
-<log:dump scope="page" />
-<H4>session</H4>
-<log:dump scope="session" />
-<H4>application</H4>
-<log:dump scope="application" />
+<log:fatal>This is body content.</log:fatal>
+<log:fatal message="This is attribute content." />
+<log:fatal category="test5">This is body content in category test4.</log:fatal>
+You should see output in the fatal logs now.
+
<H2>File source</H2>
<PRE><%@include file="test5.txt"%></PRE>
</BODY>
1.1 jakarta-taglibs/log/examples/web/test6.jsp
Index: test6.jsp
===================================================================
<%@ taglib uri="http://jakarta.apache.org/taglibs/log-1.0" prefix="log" %>
<HTML>
<HEAD>
<TITLE>Test #5</TITLE>
</HEAD>
<BODY>
<jsp:useBean id="p1" class="java.lang.String" scope="page" />
<H4>request</H4>
<log:dump scope="request" />
<H4>page</H4>
<log:dump scope="page" />
<H4>session</H4>
<log:dump scope="session" />
<H4>application</H4>
<log:dump scope="application" />
<H2>File source</H2>
<PRE><%@include file="test6.txt"%></PRE>
</BODY>
</HTML>
1.1 jakarta-taglibs/log/lib/log4j.jar
<<Binary file>>
1.2 +3 -3 jakarta-taglibs/log/src/org/apache/taglibs/log/DebugTag.java
Index: DebugTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/log/src/org/apache/taglibs/log/DebugTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DebugTag.java 2001/05/10 19:30:00 1.1
+++ DebugTag.java 2001/06/26 18:50:13 1.2
@@ -58,7 +58,7 @@
package org.apache.taglibs.log;
-import org.apache.log4j.Category;
+import org.apache.log4j.Priority;
/** Logs a debug message to the current log4j category.
*
@@ -68,7 +68,7 @@
public class DebugTag extends LoggerTag {
- protected void log( String message ) {
- getCategory().debug( message );
+ protected Priority getPriority() {
+ return Priority.DEBUG;
}
}
1.2 +3 -3 jakarta-taglibs/log/src/org/apache/taglibs/log/ErrorTag.java
Index: ErrorTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/log/src/org/apache/taglibs/log/ErrorTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ErrorTag.java 2001/05/10 19:30:00 1.1
+++ ErrorTag.java 2001/06/26 18:50:14 1.2
@@ -58,7 +58,7 @@
package org.apache.taglibs.log;
-import org.apache.log4j.Category;
+import org.apache.log4j.Priority;
/** Logs an error message to the current log4j category.
*
@@ -68,7 +68,7 @@
public class ErrorTag extends LoggerTag {
- protected void log( String message ) {
- getCategory().error( message );
+ protected Priority getPriority() {
+ return Priority.ERROR;
}
}
1.2 +3 -3 jakarta-taglibs/log/src/org/apache/taglibs/log/InfoTag.java
Index: InfoTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/log/src/org/apache/taglibs/log/InfoTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InfoTag.java 2001/05/10 19:30:00 1.1
+++ InfoTag.java 2001/06/26 18:50:14 1.2
@@ -58,7 +58,7 @@
package org.apache.taglibs.log;
-import org.apache.log4j.Category;
+import org.apache.log4j.Priority;
/** Logs an info message to the current log4j category.
*
@@ -68,7 +68,7 @@
public class InfoTag extends LoggerTag {
- protected void log( String message ) {
- getCategory().info( message );
+ protected Priority getPriority() {
+ return Priority.INFO;
}
}
1.2 +22 -19 jakarta-taglibs/log/src/org/apache/taglibs/log/LoggerTag.java
Index: LoggerTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/log/src/org/apache/taglibs/log/LoggerTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LoggerTag.java 2001/05/10 19:30:00 1.1
+++ LoggerTag.java 2001/06/26 18:50:14 1.2
@@ -62,9 +62,8 @@
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;
-import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Category;
-import org.apache.log4j.PropertyConfigurator;
+import org.apache.log4j.Priority;
/** Abstract base class for the logging tags which log a message to a
* log4j category.
@@ -75,15 +74,7 @@
public abstract class LoggerTag extends BodyTagSupport {
- static {
- // Force log4j to be initialised on Class load...
- // XXXX: Is there a better, more deployment descriptor
- // way of doing this?
- BasicConfigurator.configure();
- //PropertyConfigurator.configure("debug.properties");
- }
-
- private String category = "";
+ private String category;
private String message;
@@ -99,8 +90,12 @@
//-------------------------------------------------------------------------
public int doStartTag() throws JspException {
if ( message != null ) {
- /** Log now as doAfterBody() may not be called for an empty body tag */
- log( message );
+ Category logCategory = getLoggingCategory();
+ Priority priority = getPriority();
+ if ( logCategory.isEnabledFor( priority ) ) {
+ // Log now as doAfterBody() may not be called for an empty tag
+ logCategory.log( priority, message );
+ }
return SKIP_BODY;
}
return EVAL_BODY_TAG;
@@ -108,18 +103,26 @@
public int doAfterBody() throws JspException {
if (message == null) {
- log( getBodyContent().getString().trim() );
+ Category logCategory = getLoggingCategory();
+ Priority priority = getPriority();
+ if ( logCategory.isEnabledFor( priority ) ) {
+ logCategory.log( priority, getBodyContent().getString().trim() );
+ }
}
return SKIP_BODY;
}
// Implementation methods
//-------------------------------------------------------------------------
- protected Category getCategory() {
- return Category.getInstance(category);
- }
-
+ protected abstract Priority getPriority();
- protected abstract void log( String message );
+ protected Category getLoggingCategory() {
+ if ( category == null ) {
+ return Category.getRoot();
+ }
+ else {
+ return Category.getInstance( category );
+ }
+ }
}
1.2 +4 -4 jakarta-taglibs/log/src/org/apache/taglibs/log/WarnTag.java
Index: WarnTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/log/src/org/apache/taglibs/log/WarnTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WarnTag.java 2001/05/10 19:30:00 1.1
+++ WarnTag.java 2001/06/26 18:50:14 1.2
@@ -58,9 +58,9 @@
package org.apache.taglibs.log;
-import org.apache.log4j.Category;
+import org.apache.log4j.Priority;
-/** Logs an info message to the current log4j category.
+/** Logs a warning message to the current log4j category.
*
* @author <a href="mailto:joeo@epesh.com">Joseph Ottinger</a>
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
@@ -68,8 +68,8 @@
public class WarnTag extends LoggerTag {
- protected void log( String message ) {
- getCategory().warn( message );
+ protected Priority getPriority() {
+ return Priority.WARN;
}
}
1.1 jakarta-taglibs/log/src/org/apache/taglibs/log/FatalTag.java
Index: FatalTag.java
===================================================================
/*
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.taglibs.log;
import org.apache.log4j.Priority;
/** Logs a fatal message to the current log4j category.
*
* @author <a href="mailto:joeo@epesh.com">Joseph Ottinger</a>
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
*/
public class FatalTag extends LoggerTag {
protected Priority getPriority() {
return Priority.FATAL;
}
}
1.2 +54 -0 jakarta-taglibs/log/xml/log.xml
Index: log.xml
===================================================================
RCS file: /home/cvs/jakarta-taglibs/log/xml/log.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- log.xml 2001/05/10 19:30:02 1.1
+++ log.xml 2001/06/26 18:50:16 1.2
@@ -22,6 +22,28 @@
output to a variety of destinations thanks to the power of the
<a href="http://jakarta.apache.org/log4j/docs/index.html">log4j</a> project.
</p>
+
+ <b>Initialising log4j</b>
+
+ <p>By default these log tags do not explicitly initialise log4j,
+ you are free to do that however you wish.
+ A common approach is to create a log4j servlet and for it to initialise
+ log4j using some configuration file or options specified in your web.xml
+ </p>
+
+ <p>My own personal preference is just to put a log4j.properties file
+ in the WEB-INF/classes directory and for that to have your log4j
+ configuration. Then without any special servlets or initialisation
+ code log4j will correctly initialise itself. This approach also avoids
+ a single web app accidentally initialising log4j several times
+ (e.g. via 2 different servlets).
+ </p>
+
+ <p>If you have any further questions regarding the configuration of
+ log4j please visit the
+ <a href="http://jakarta.apache.org/log4j/docs/index.html">log4j</a>
+ site or a log4j specific mailing list.
+ </p>
</overview>
<requirements-info>
@@ -155,6 +177,38 @@
<log:error category="foo.bar">
this is a message
</log:error>
+]]></code>
+ </usage>
+ </tag>
+
+ <tag>
+ <name>fatal</name>
+ <tagclass>org.apache.taglibs.log.FatalTag</tagclass>
+ <bodycontents>JSP</bodycontents>
+ <info>Displays a fatal message, usually as the application is about to terminate</info>
+ <script-variable>No</script-variable>
+ <attribute>
+ <name>category</name>
+ <rtexprvalue>true</rtexprvalue>
+ <required>false</required>
+ </attribute>
+ <attribute>
+ <name>message</name>
+ <rtexprvalue>true</rtexprvalue>
+ <required>false</required>
+ </attribute>
+ <restrictions></restrictions>
+ <usage>
+ <comment>
+ </comment>
+ <code><![CDATA[
+<log:fatal message="oh dear I think I'm about to terminate"/>
+
+<log:fatal category="foo.bar" message="oh dear I think I'm about to terminate"/>
+
+<log:fatal category="foo.bar">
+ oh dear I think I'm about to terminate
+</log:fatal>
]]></code>
</usage>
</tag>