Index: api/pom.xml
===================================================================
--- api/pom.xml (revision 1462167)
+++ api/pom.xml (working copy)
@@ -43,7 +43,6 @@
junit
junit
- 4.3.1
test
Index: api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
===================================================================
--- api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java (revision 1462167)
+++ api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java (working copy)
@@ -143,9 +143,7 @@
* @param t The Throwable.
*/
public void catching(final Level level, final Throwable t) {
- if (isEnabled(level, CATCHING_MARKER, (Object) null, null)) {
- log(CATCHING_MARKER, FQCN, level, messageFactory.newMessage(CATCHING), t);
- }
+ catching(FQCN, level, t);
}
/**
@@ -154,8 +152,19 @@
* @param t The Throwable.
*/
public void catching(final Throwable t) {
- if (isEnabled(Level.ERROR, CATCHING_MARKER, (Object) null, null)) {
- log(CATCHING_MARKER, FQCN, Level.ERROR, messageFactory.newMessage(CATCHING), t);
+ catching(FQCN, Level.ERROR, t);
+ }
+
+ /**
+ * Logs a Throwable that has been caught with location information.
+ *
+ * @param fqcn The fully qualified class name of the caller .
+ * @param level The logging level.
+ * @param t The Throwable.
+ */
+ protected void catching(String fqcn, final Level level, final Throwable t) {
+ if (isEnabled(level, CATCHING_MARKER, (Object) null, null)) {
+ log(CATCHING_MARKER, fqcn, level, messageFactory.newMessage(CATCHING), t);
}
}
@@ -348,9 +357,7 @@
* Logs entry to a method.
*/
public void entry() {
- if (isEnabled(Level.TRACE, ENTRY_MARKER, (Object) null, null)) {
- log(ENTRY_MARKER, FQCN, Level.TRACE, messageFactory.newMessage(" entry"), null);
- }
+ entry(FQCN);
}
/**
@@ -359,8 +366,18 @@
* @param params The parameters to the method.
*/
public void entry(final Object... params) {
+ entry(FQCN, params);
+ }
+
+ /**
+ * Logs entry to a method with location information.
+ *
+ * @param fqcn The fully qualified class name of the caller .
+ * @param params The parameters to the method.
+ */
+ protected void entry(final String fqcn, final Object... params) {
if (isEnabled(Level.TRACE, ENTRY_MARKER, (Object) null, null)) {
- log(ENTRY_MARKER, FQCN, Level.TRACE, entryMsg(params.length, params), null);
+ log(ENTRY_MARKER, fqcn, Level.TRACE, entryMsg(params.length, params), null);
}
}
@@ -564,9 +581,7 @@
* Logs exit from a method.
*/
public void exit() {
- if (isEnabled(Level.TRACE, EXIT_MARKER, (Object) null, null)) {
- log(EXIT_MARKER, FQCN, Level.TRACE, toExitMsg(null), null);
- }
+ exit(FQCN, null);
}
/**
@@ -577,8 +592,19 @@
* @return the Throwable.
*/
public R exit(final R result) {
+ return exit(FQCN, result);
+ }
+
+ /**
+ * Logs exiting from a method with the result and location information.
+ *
+ * @param fqcn The fully qualified class name of the caller .
+ * @param The type of the parameter and object being returned.
+ * @param result The result being returned from the method call.
+ */
+ protected R exit(final String fqcn, final R result) {
if (isEnabled(Level.TRACE, EXIT_MARKER, (Object) null, null)) {
- log(EXIT_MARKER, FQCN, Level.TRACE, toExitMsg(result), null);
+ log(EXIT_MARKER, fqcn, Level.TRACE, toExitMsg(result), null);
}
return result;
}
@@ -1346,10 +1372,7 @@
* @return the Throwable.
*/
public T throwing(final Level level, final T t) {
- if (isEnabled(level, THROWING_MARKER, (Object) null, null)) {
- log(THROWING_MARKER, FQCN, level, messageFactory.newMessage(THROWING), t);
- }
- return t;
+ return throwing(FQCN, level, t);
}
/**
@@ -1360,8 +1383,21 @@
* @return the Throwable.
*/
public T throwing(final T t) {
- if (isEnabled(Level.ERROR, THROWING_MARKER, (Object) null, null)) {
- log(THROWING_MARKER, FQCN, Level.ERROR, messageFactory.newMessage(THROWING), t);
+ return throwing(FQCN, Level.ERROR, t);
+ }
+
+ /**
+ * Logs a Throwable to be thrown with location information.
+ *
+ * @param fqcn The fully qualified class name of the caller .
+ * @param the type of the Throwable.
+ * @param level The logging Level.
+ * @param t The Throwable.
+ * @return the Throwable.
+ */
+ protected T throwing(String fqcn, final Level level, final T t) {
+ if (isEnabled(level, THROWING_MARKER, (Object) null, null)) {
+ log(THROWING_MARKER, fqcn, level, messageFactory.newMessage(THROWING), t);
}
return t;
}
Index: jcl-bridge/pom.xml
===================================================================
--- jcl-bridge/pom.xml (revision 1462167)
+++ jcl-bridge/pom.xml (working copy)
@@ -39,7 +39,6 @@
junit
junit
- 4.3.1
test
Index: log4j12-api/pom.xml
===================================================================
--- log4j12-api/pom.xml (revision 1462167)
+++ log4j12-api/pom.xml (working copy)
@@ -37,7 +37,6 @@
junit
junit
- 4.3.1
test
Index: pom.xml
===================================================================
--- pom.xml (revision 1462167)
+++ pom.xml (working copy)
@@ -245,7 +245,7 @@
javax.servlet
servlet-api
- 2.4
+ 2.5
provided
@@ -555,6 +555,7 @@
jcl-bridge
flume-ng
web
+ taglib
samples
Index: samples/flume-common/pom.xml
===================================================================
--- samples/flume-common/pom.xml (revision 1462167)
+++ samples/flume-common/pom.xml (working copy)
@@ -64,7 +64,6 @@
junit
junit
- 4.3.1
test
Index: samples/flume-embedded/pom.xml
===================================================================
--- samples/flume-embedded/pom.xml (revision 1462167)
+++ samples/flume-embedded/pom.xml (working copy)
@@ -123,7 +123,6 @@
junit
junit
- 4.3.1
test
Index: samples/flume-remote/pom.xml
===================================================================
--- samples/flume-remote/pom.xml (revision 1462167)
+++ samples/flume-remote/pom.xml (working copy)
@@ -76,7 +76,6 @@
junit
junit
- 4.3.1
test
Index: samples/pom.xml
===================================================================
--- samples/pom.xml (revision 1462167)
+++ samples/pom.xml (working copy)
@@ -72,13 +72,13 @@
javax.servlet
servlet-api
- 2.4
+ 2.5
provided
junit
junit
- 3.8.1
+ 4.7
test
Index: src/site/site.xml
===================================================================
--- src/site/site.xml (revision 1462167)
+++ src/site/site.xml (working copy)
@@ -127,6 +127,7 @@
+
Index: taglib/pom.xml
===================================================================
--- taglib/pom.xml (revision 0)
+++ taglib/pom.xml (working copy)
@@ -0,0 +1,201 @@
+
+
+
+ 4.0.0
+
+ org.apache.logging.log4j
+ log4j
+ 2.0-beta5-SNAPSHOT
+ ../
+
+ org.apache.logging.log4j
+ log4j-taglib
+ jar
+ Apache Log4j Tag Library
+ Apache Log4j Tag Library for Web Applications
+
+
+ Nick Williams
+ nicholas@nicholaswilliams.net
+
+
+
+ ${basedir}/..
+ Log4j Tag Library Documentation
+ /taglib
+
+
+
+ org.apache.logging.log4j
+ log4j-api
+
+
+ org.apache.logging.log4j
+ log4j-core
+
+
+ javax.servlet
+ servlet-api
+ 2.5
+ provided
+
+
+ javax.servlet.jsp
+ jsp-api
+ 2.1
+ provided
+
+
+ org.apache.logging.log4j
+ log4j-core
+ test-jar
+ test
+
+
+ junit
+ junit
+ test
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-changes-plugin
+ ${changes.plugin.version}
+
+
+
+ changes-report
+
+
+
+
+ %URL%/show_bug.cgi?id=%ISSUE%
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 2.7
+
+
+ ${log4jParentDir}/checkstyle.xml
+ ${log4jParentDir}/checkstyle-suppressions.xml
+ false
+ basedir=${basedir}
+ licensedir=${log4jParentDir}/checkstyle-header.txt
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ ${javadoc.plugin.version}
+
+ Copyright © {inceptionYear}-{currentYear} {organizationName}. All Rights Reserved.
+ Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo,
+ and the Apache Log4j logo are trademarks of The Apache Software Foundation.
]]>
+
+ false
+ true
+
+
+ issue
+ a
+ JIRA issue:
+
+
+ doubt
+ a
+ Troublesome:
+
+
+ compare
+ a
+ Compare with:
+
+
+
+
+
+ non-aggregate
+
+ javadoc
+
+
+
+
+
+ org.codehaus.mojo
+ findbugs-maven-plugin
+ 2.3.2
+
+ Normal
+ Default
+ findbugs-exclude-filter.xml
+
+
+
+ org.apache.maven.plugins
+ maven-jxr-plugin
+ 2.3
+
+
+ non-aggregate
+
+ jxr
+
+
+
+ aggregate
+
+ aggregate
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-pmd-plugin
+ ${pmd.plugin.version}
+
+ 1.5
+
+
+
+ org.codehaus.mojo
+ cobertura-maven-plugin
+ 2.2
+
+
+
+
+
+
+
+
+ net.sourceforge.maven-taglib
+ maven-taglib-plugin
+ 2.4
+
+
+
+
+
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/CatchingTag.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/CatchingTag.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/CatchingTag.java (working copy)
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.Level;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.Tag;
+
+/**
+ * This class implements the {@code } tag.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+public class CatchingTag extends ExceptionAwareTagSupport {
+ private static final String FQCN = CatchingTag.class.getName();
+
+ private Level level;
+
+ @Override
+ protected void init() {
+ super.init();
+ this.level = null;
+ }
+
+ public void setLevel(Object level) {
+ this.level = TagUtils.resolveLevel(level);
+ }
+
+ @Override
+ public int doEndTag() throws JspException {
+ Log4jTaglibLogger logger = this.getLogger();
+
+ if (this.level == null) {
+ logger.catching(FQCN, Level.ERROR, this.getException());
+ } else {
+ logger.catching(FQCN, this.level, this.getException());
+ }
+
+ return Tag.EVAL_PAGE;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/DebugTag.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/DebugTag.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/DebugTag.java (working copy)
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.Level;
+
+/**
+ * This class implements the {@code } tag.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+public class DebugTag extends LoggingMessageTagSupport {
+ @Override
+ protected Level getLevel() {
+ return Level.DEBUG;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/DumpTag.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/DumpTag.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/DumpTag.java (working copy)
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.tagext.Tag;
+import javax.servlet.jsp.tagext.TagSupport;
+import java.io.IOException;
+import java.util.Enumeration;
+
+/**
+ * This class implements the {@code } tag.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+public class DumpTag extends TagSupport {
+ private int scope;
+
+ public DumpTag() {
+ super();
+ init();
+ }
+
+ @Override
+ public void release() {
+ super.release();
+ this.init();
+ }
+
+ private void init() {
+ this.scope = PageContext.PAGE_SCOPE;
+ }
+
+ public void setScope(String scope) {
+ this.scope = TagUtils.getScope(scope);
+ }
+
+ @Override
+ public int doEndTag() throws JspException {
+ try {
+ Enumeration names = this.pageContext.getAttributeNamesInScope(this.scope);
+ this.pageContext.getOut().write("");
+ while (names.hasMoreElements()) {
+ String name = names.nextElement();
+ Object value = this.pageContext.getAttribute(name, this.scope);
+
+ this.pageContext.getOut().write("" + name + " ");
+ this.pageContext.getOut().write("" + value + " ");
+ }
+ this.pageContext.getOut().write(" ");
+ } catch (IOException e) {
+ throw new JspException("Could not write scope contents. Cause: " + e.toString(), e);
+ }
+
+ return Tag.EVAL_PAGE;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/EntryTag.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/EntryTag.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/EntryTag.java (working copy)
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.Level;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.DynamicAttributes;
+import javax.servlet.jsp.tagext.Tag;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This class implements the {@code } tag.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+public class EntryTag extends LoggerAwareTagSupport implements DynamicAttributes {
+ private static final String FQCN = EntryTag.class.getName();
+
+ private List attributes;
+
+ @Override
+ protected void init() {
+ super.init();
+ if (this.attributes == null) {
+ this.attributes = new ArrayList();
+ } else {
+ this.attributes.clear();
+ }
+ }
+
+ public void setDynamicAttribute(String uri, String name, Object value) {
+ this.attributes.add(value);
+ }
+
+ @Override
+ public int doEndTag() throws JspException {
+ Log4jTaglibLogger logger = this.getLogger();
+
+ if (TagUtils.isEnabled(logger, Level.TRACE, null)) {
+ if (this.attributes.size() == 0) {
+ logger.entry(FQCN);
+ } else {
+ logger.entry(FQCN, this.attributes.toArray());
+ }
+ }
+
+ return Tag.EVAL_PAGE;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/ErrorTag.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/ErrorTag.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/ErrorTag.java (working copy)
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.Level;
+
+/**
+ * This class implements the {@code } tag.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+public class ErrorTag extends LoggingMessageTagSupport {
+ @Override
+ protected Level getLevel() {
+ return Level.ERROR;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/ExceptionAwareTagSupport.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/ExceptionAwareTagSupport.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/ExceptionAwareTagSupport.java (working copy)
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+/**
+ * Implements common methods for all logging tags that accept exceptions.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+abstract class ExceptionAwareTagSupport extends LoggerAwareTagSupport {
+ private Throwable exception;
+
+ @Override
+ protected void init() {
+ super.init();
+ this.exception = null;
+ }
+
+ protected final Throwable getException() {
+ return this.exception;
+ }
+
+ public final void setException(Throwable exception) {
+ this.exception = exception;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/ExitTag.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/ExitTag.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/ExitTag.java (working copy)
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.Level;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.Tag;
+
+/**
+ * This class implements the {@code } tag.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+public class ExitTag extends LoggerAwareTagSupport {
+ private static final String FQCN = ExitTag.class.getName();
+
+ private Object result;
+
+ @Override
+ protected void init() {
+ super.init();
+ this.result = null;
+ }
+
+ public void setResult(Object result) {
+ this.result = result;
+ }
+
+ @Override
+ public int doEndTag() throws JspException {
+ Log4jTaglibLogger logger = this.getLogger();
+
+ if (TagUtils.isEnabled(logger, Level.TRACE, null)) {
+ if (this.result == null) {
+ logger.exit(FQCN, null);
+ } else {
+ logger.exit(FQCN, this.result);
+ }
+ }
+
+ return Tag.EVAL_PAGE;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/FatalTag.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/FatalTag.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/FatalTag.java (working copy)
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.Level;
+
+/**
+ * This class implements the {@code } tag.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+public class FatalTag extends LoggingMessageTagSupport {
+ @Override
+ protected Level getLevel() {
+ return Level.FATAL;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/IfEnabledTag.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/IfEnabledTag.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/IfEnabledTag.java (working copy)
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Marker;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.Tag;
+
+/**
+ * This class implements the {@code } tag.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+public class IfEnabledTag extends LoggerAwareTagSupport {
+ private Object level;
+
+ private Marker marker;
+
+ @Override
+ protected void init() {
+ super.init();
+ this.level = null;
+ this.marker = null;
+ }
+
+ public final void setLevel(Object level) {
+ this.level = level;
+ }
+
+ public final void setMarker(Marker marker) {
+ this.marker = marker;
+ }
+
+ @Override
+ public int doStartTag() throws JspException {
+ Level level = TagUtils.resolveLevel(this.level);
+ if (level == null) {
+ throw new JspException("Level must be of type String or org.apache.logging.log4j.Level.");
+ }
+
+ return TagUtils.isEnabled(this.getLogger(), level, this.marker) ? Tag.EVAL_BODY_INCLUDE : Tag.SKIP_BODY;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/InfoTag.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/InfoTag.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/InfoTag.java (working copy)
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.Level;
+
+/**
+ * This class implements the {@code } tag.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+public class InfoTag extends LoggingMessageTagSupport {
+ @Override
+ protected Level getLevel() {
+ return Level.INFO;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/Log4jTaglibLogger.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/Log4jTaglibLogger.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/Log4jTaglibLogger.java (working copy)
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.message.MessageFactory;
+import org.apache.logging.log4j.spi.AbstractLogger;
+import org.apache.logging.log4j.spi.AbstractLoggerWrapper;
+
+/**
+ * The bridge between the tag library and the Log4j API ensures that the source information for log events is
+ * the JSP Servlet and not one of the taglib classes.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+class Log4jTaglibLogger extends AbstractLoggerWrapper {
+ public Log4jTaglibLogger(AbstractLogger logger, String name, MessageFactory messageFactory) {
+ super(logger, name, messageFactory);
+ }
+
+ @Override
+ protected void entry(String fqcn, Object... params) {
+ super.entry(fqcn, params);
+ }
+
+ @Override
+ protected R exit(String fqcn, R result) {
+ return super.exit(fqcn, result);
+ }
+
+ @Override
+ protected void catching(String fqcn, Level level, Throwable t) {
+ super.catching(fqcn, level, t);
+ }
+
+ @Override
+ protected T throwing(String fqcn, Level level, T t) {
+ return super.throwing(fqcn, level, t);
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/Log4jTaglibLoggerContext.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/Log4jTaglibLoggerContext.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/Log4jTaglibLoggerContext.java (working copy)
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.LoggingException;
+import org.apache.logging.log4j.message.MessageFactory;
+import org.apache.logging.log4j.spi.AbstractLogger;
+import org.apache.logging.log4j.spi.LoggerContext;
+
+import javax.servlet.ServletContext;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * This bridge between the tag library and the Log4j API ensures that instances of {@link Log4jTaglibLogger} are
+ * appropriately held in memory and not constantly recreated.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+final class Log4jTaglibLoggerContext implements LoggerContext {
+ private static final ConcurrentMap CONTEXTS =
+ new ConcurrentHashMap();
+
+ private final ConcurrentMap loggers =
+ new ConcurrentHashMap();
+
+ private final ServletContext servletContext;
+
+ private Log4jTaglibLoggerContext(ServletContext servletContext) {
+ this.servletContext = servletContext;
+ }
+
+ public Object getExternalContext() {
+ return this.servletContext;
+ }
+
+ public Log4jTaglibLogger getLogger(String name) {
+ return this.getLogger(name, null);
+ }
+
+ public Log4jTaglibLogger getLogger(String name, MessageFactory factory) {
+ Log4jTaglibLogger logger = this.loggers.get(name);
+ if (logger != null) {
+ AbstractLogger.checkMessageFactory(logger, factory);
+ return logger;
+ }
+
+ // wrap a logger from an underlying implementation
+ Logger original = factory == null ? LogManager.getLogger(name) : LogManager.getLogger(name, factory);
+ if (original instanceof AbstractLogger) {
+ logger = new Log4jTaglibLogger((AbstractLogger) original, name, original.getMessageFactory());
+ Log4jTaglibLogger existing = this.loggers.putIfAbsent(name, logger);
+ return existing == null ? logger : existing;
+ }
+
+ throw new LoggingException("Log4j Tag Library requires base logging system to extend Log4j AbstractLogger.");
+ }
+
+ public boolean hasLogger(String name) {
+ return this.loggers.containsKey(name);
+ }
+
+ static synchronized Log4jTaglibLoggerContext getInstance(ServletContext servletContext) {
+ if (CONTEXTS.containsKey(servletContext)) {
+ return CONTEXTS.get(servletContext);
+ }
+
+ Log4jTaglibLoggerContext context = new Log4jTaglibLoggerContext(servletContext);
+ Log4jTaglibLoggerContext existing = CONTEXTS.putIfAbsent(servletContext, context);
+ return existing == null ? context : existing;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/LogTag.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/LogTag.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/LogTag.java (working copy)
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.Level;
+
+/**
+ * This class implements the {@code } tag.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+public class LogTag extends LoggingMessageTagSupport {
+ private Level level;
+
+ @Override
+ protected void init() {
+ super.init();
+ this.level = null;
+ }
+
+ @Override
+ protected Level getLevel() {
+ return this.level;
+ }
+
+ public void setLevel(Object level) {
+ this.level = TagUtils.resolveLevel(level);
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/LoggerAwareTagSupport.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/LoggerAwareTagSupport.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/LoggerAwareTagSupport.java (working copy)
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+
+/**
+ * An abstract class for all tags that are logger-aware.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+abstract class LoggerAwareTagSupport extends BodyTagSupport {
+ private Log4jTaglibLoggerContext loggerContext;
+ private Object logger;
+
+ protected LoggerAwareTagSupport() {
+ this.init();
+ }
+
+ protected void init() {
+ this.logger = null;
+ }
+
+ @Override
+ public final void release() {
+ super.release();
+ this.init();
+ }
+
+ @Override
+ public void setPageContext(PageContext pageContext) {
+ super.setPageContext(pageContext);
+ this.loggerContext = Log4jTaglibLoggerContext.getInstance(pageContext.getServletContext());
+ }
+
+ protected final Log4jTaglibLogger getLogger() throws JspException {
+ if (this.logger != null) {
+ return TagUtils.resolveLogger(this.loggerContext, this.logger, null);
+ } else {
+ Log4jTaglibLogger logger = TagUtils.getDefaultLogger(this.pageContext);
+ if (logger == null) {
+ String name = this.pageContext.getPage().getClass().getName();
+ logger = TagUtils.resolveLogger(this.loggerContext, name, null);
+ TagUtils.setDefaultLogger(this.pageContext, logger);
+ }
+ return logger;
+ }
+ }
+
+ public final void setLogger(Object logger) {
+ this.logger = logger;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/LoggingMessageTagSupport.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/LoggingMessageTagSupport.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/LoggingMessageTagSupport.java (working copy)
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.message.Message;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.BodyTag;
+import javax.servlet.jsp.tagext.DynamicAttributes;
+import javax.servlet.jsp.tagext.Tag;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Implements common methods for logging tags that accept messages and markers.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+abstract class LoggingMessageTagSupport extends ExceptionAwareTagSupport implements DynamicAttributes {
+ private static final String FQCN = LoggingMessageTagSupport.class.getName();
+
+ private Object message;
+
+ private Marker marker;
+
+ private List attributes;
+
+ @Override
+ protected void init() {
+ super.init();
+ this.message = null;
+ this.marker = null;
+ if (this.attributes == null) {
+ this.attributes = new ArrayList();
+ } else {
+ this.attributes.clear();
+ }
+ }
+
+ protected final Object getMessage() throws JspException {
+ if (this.message == null) {
+ if (this.getBodyContent() == null) {
+ throw new JspException("Either message attribute or body content must be specified.");
+ }
+ return this.getBodyContent().getString();
+ }
+ return this.message;
+ }
+
+ public final void setMessage(Object message) {
+ this.message = message;
+ }
+
+ protected final Marker getMarker() {
+ return this.marker;
+ }
+
+ public final void setMarker(Marker marker) {
+ this.marker = marker;
+ }
+
+ protected abstract Level getLevel();
+
+ public final void setDynamicAttribute(String uri, String name, Object value) {
+ this.attributes.add(value);
+ }
+
+ @Override
+ public final int doStartTag() {
+ return BodyTag.EVAL_BODY_BUFFERED;
+ }
+
+ @Override
+ public final int doEndTag() throws JspException {
+ Log4jTaglibLogger logger = this.getLogger();
+ Level level = this.getLevel();
+ Marker marker = this.getMarker();
+
+ if (TagUtils.isEnabled(logger, level, marker)) {
+ Object message = this.getMessage();
+ Throwable exception = this.getException();
+ if (message instanceof Message) {
+ logger.log(marker, FQCN, level, (Message) message, exception);
+ } else if (message instanceof String) {
+ Message data;
+ if (this.attributes.size() > 0) {
+ data = logger.getMessageFactory().newMessage((String) message, this.attributes.toArray());
+ } else {
+ data = logger.getMessageFactory().newMessage((String) message);
+ }
+ logger.log(marker, FQCN, level, data, exception);
+ } else {
+ logger.log(marker, FQCN, level, logger.getMessageFactory().newMessage(message), exception);
+ }
+ }
+
+ return Tag.EVAL_PAGE;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/SetLoggerTag.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/SetLoggerTag.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/SetLoggerTag.java (working copy)
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.message.MessageFactory;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+import javax.servlet.jsp.tagext.Tag;
+
+/**
+ * This class implements the {@code } tag.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+public class SetLoggerTag extends BodyTagSupport {
+ private Log4jTaglibLoggerContext loggerContext;
+
+ private Object logger;
+
+ private MessageFactory factory;
+
+ private String var;
+
+ private int scope;
+
+ public SetLoggerTag() {
+ super();
+ init();
+ }
+
+ private void init() {
+ this.logger = null;
+ this.var = null;
+ this.scope = PageContext.PAGE_SCOPE;
+ }
+
+ @Override
+ public void release() {
+ super.release();
+ this.init();
+ }
+
+ @Override
+ public void setPageContext(PageContext pageContext) {
+ super.setPageContext(pageContext);
+ this.loggerContext = Log4jTaglibLoggerContext.getInstance(pageContext.getServletContext());
+ }
+
+ public void setLogger(Object logger) {
+ this.logger = logger;
+ }
+
+ public void setFactory(MessageFactory factory) {
+ this.factory = factory;
+ }
+
+ public void setVar(String var) {
+ this.var = var;
+ }
+
+ public void setScope(String scope) {
+ this.scope = TagUtils.getScope(scope);
+ }
+
+ @Override
+ public int doEndTag() throws JspException {
+ Log4jTaglibLogger logger = TagUtils.resolveLogger(this.loggerContext, this.logger, this.factory);
+
+ if (this.var != null) {
+ this.pageContext.setAttribute(this.var, logger, this.scope);
+ } else {
+ TagUtils.setDefaultLogger(this.pageContext, logger);
+ }
+
+ return Tag.EVAL_PAGE;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/TagUtils.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/TagUtils.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/TagUtils.java (working copy)
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.LoggingException;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.message.MessageFactory;
+import org.apache.logging.log4j.spi.AbstractLogger;
+import org.apache.logging.log4j.status.StatusLogger;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Provides support for logging tags.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+final class TagUtils {
+ private static final StatusLogger log = StatusLogger.getLogger();
+
+ private static final Set WARNED_FOR = new HashSet();
+
+ private static final String LOGGER_SCOPE_ATTRIBUTE = "org.apache.logging.log4j.taglib.LOGGER_SCOPE_ATTRIBUTE";
+
+ private TagUtils() {
+ throw new RuntimeException("TagUtils cannot be instantiated.");
+ }
+
+ static int getScope(String scope) {
+ if ("request".equalsIgnoreCase(scope)) {
+ return PageContext.REQUEST_SCOPE;
+ }
+ if ("session".equalsIgnoreCase(scope)) {
+ return PageContext.SESSION_SCOPE;
+ }
+ if ("application".equalsIgnoreCase(scope)) {
+ return PageContext.APPLICATION_SCOPE;
+ }
+ return PageContext.PAGE_SCOPE;
+ }
+
+ static Level resolveLevel(Object level) {
+ if (level instanceof Level) {
+ return (Level) level;
+ }
+ if (level instanceof String) {
+ return Level.toLevel((String) level);
+ }
+ return null;
+ }
+
+ static Log4jTaglibLogger resolveLogger(final Log4jTaglibLoggerContext context, final Object logger,
+ final MessageFactory factory) throws JspException {
+ if (logger instanceof Logger) {
+ if (logger instanceof Log4jTaglibLogger) {
+ return (Log4jTaglibLogger) logger;
+ }
+ if (logger instanceof AbstractLogger) {
+ if (log.isInfoEnabled() && !WARNED_FOR.contains(logger)) {
+ log.info("Constructing new Log4jTaglibLogger from AbstractLogger {} name and message factory.",
+ logger.getClass().getName());
+ WARNED_FOR.add(logger);
+ }
+ AbstractLogger original = (AbstractLogger) logger;
+ return getLogger(context, original.getName(), original.getMessageFactory());
+ }
+ throw new JspException(
+ "Log4j Tag Library requires base logging system to extend Log4j AbstractLogger.");
+ }
+ if (logger instanceof String) {
+ return getLogger(context, (String) logger, factory);
+ }
+ throw new JspException("Logger must be of type String or org.apache.logging.log4j.Logger.");
+ }
+
+ private static Log4jTaglibLogger getLogger(Log4jTaglibLoggerContext context, String name, MessageFactory factory)
+ throws JspException {
+ try {
+ return context.getLogger(name, factory);
+ } catch (LoggingException e) {
+ throw new JspException(e.getMessage(), e);
+ }
+ }
+
+ static void setDefaultLogger(PageContext pageContext, Log4jTaglibLogger logger) {
+ pageContext.setAttribute(TagUtils.LOGGER_SCOPE_ATTRIBUTE, logger, PageContext.PAGE_SCOPE);
+ }
+
+ static Log4jTaglibLogger getDefaultLogger(PageContext pageContext) {
+ return (Log4jTaglibLogger) pageContext.getAttribute(TagUtils.LOGGER_SCOPE_ATTRIBUTE, PageContext.PAGE_SCOPE);
+ }
+
+ static boolean isEnabled(Log4jTaglibLogger logger, Level level, Marker marker) {
+ if (marker == null) {
+ return logger.isEnabled(level);
+ }
+ return logger.isEnabled(level, marker, (Object) null, null);
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/TraceTag.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/TraceTag.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/TraceTag.java (working copy)
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.Level;
+
+/**
+ * This class implements the {@code } tag.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+public class TraceTag extends LoggingMessageTagSupport {
+ @Override
+ protected Level getLevel() {
+ return Level.TRACE;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/WarnTag.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/WarnTag.java (revision 0)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/WarnTag.java (working copy)
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.taglib;
+
+import org.apache.logging.log4j.Level;
+
+/**
+ * This class implements the {@code } tag.
+ *
+ * @since 2.0
+ * @author Nick Williams
+ */
+public class WarnTag extends LoggingMessageTagSupport {
+ @Override
+ protected Level getLevel() {
+ return Level.WARN;
+ }
+}
Index: taglib/src/main/java/org/apache/logging/log4j/taglib/package-info.java
===================================================================
--- taglib/src/main/java/org/apache/logging/log4j/taglib/package-info.java (working copy)
+++ taglib/src/main/java/org/apache/logging/log4j/taglib/package-info.java (working copy)
@@ -15,6 +15,8 @@
* limitations under the license.
*/
/**
- * Classes to aid integration with Java EE.
+ * Classes (JSP tags) to enable logging in JSPs without using Java scripting.
+ *
+ * @since 2.0
*/
-package org.apache.logging.log4j.core.web;
+package org.apache.logging.log4j.taglib;
Index: taglib/src/main/resources/META-INF/log.tld
===================================================================
--- taglib/src/main/resources/META-INF/log.tld (revision 0)
+++ taglib/src/main/resources/META-INF/log.tld (working copy)
@@ -0,0 +1,634 @@
+
+
+
+
+ Log4j 2 website.
+
+This tag library is based on the Jakarta Commons Log Taglib by Joseph Ottinger and James
+Strachan. For the most part, logging tags written against Jakarta Commons Log Taglib should
+work against this library as well. However, the "category" attribute from Jakarta has become
+the "logger" attribute in this library.
+
+In accordance with the org.apache.logging.log4j.Logger API, this tag library has tags to
+support the following logging calls: "catching", "entry", "exit", "log", "trace", "debug",
+"info", "warn", "error", and "fatal". The "trace" tag was not supported in Jakarta Commons Log
+Taglib. The "setLogger", "catching", "entry", and "trace" tags are new to this library. This
+tag library also supports the conditional tag "ifEnabled" (new) and troubleshooting tag "dump"
+(existed in Jakarta Commons Log Taglib).
+
+By default, this tag library uses a different Logger for each JSP named after the JSP ID.
+You can customize the Logger in any of the logging tags or the "ifEnabled" tag with the
+"logger" attribute. You can also use the "setLogger" tag to specify the Logger that should apply
+for the rest of a JSP's execution. If the "setLogger" tag comes before any other logging tags in
+a JSP, the default Logger for that JSP will not be created, but instead the specified logger is
+the only one that will be used.
+
+Every effort was made to optimize these tags and ensure decent performance, but users of
+this library should keep in mind that the creation and execution of JSP tags adds significant
+overhead to the standard Log4j method calls. While the "trace", "debug", and "info" options are
+available in this library, their uses are not nano-second order of magnitude with logging off
+that users may be used to with standard Log4j method calls. Therefore, they should be used
+sparingly. Use of the "ifEnabled" tag does not improve this performance; this tag is available
+to conditionally evaluate other actions in addition to logging actions.]]>
+ Log4j 2 Tag Library
+ 1.0
+ log
+ http://logging.apache.org/log4j/tld/log
+
+
+ Sets the default Logger to use for the rest of this JSP's execution OR exports
+ an org.apache.logging.log4j.Logger instance as the specified EL variable. The "value"
+ attribute specifies either the String name of a Logger to create or an actual Logger instance.
+ By default, Loggers are constructed and assigned the standard
+ org.apache.logging.log4j.message.ParameterizedMessageFactory. The optional "factory" attribute
+ can be used to override the default message factory.
+ setLogger
+ org.apache.logging.log4j.taglib.SetLoggerTag
+ empty
+
+ The name or instance of the Logger to set as the JSP's default Logger or
+ the name of the Logger to export as the specified EL variable.
+ value
+ true
+ true
+ java.lang.Object
+
+
+ Specify this optional tag to provide a message factory other than the default
+ ParameterizedMessageFactory message factory to use for the Logger. If the Logger has already
+ been created with a different message factory, this will be ignored. Using this attribute
+ makes no sense if the "value" attribute's value is an actual Logger instance, since its
+ message factory cannot be changed.
+ factory
+ false
+ true
+ org.apache.logging.log4j.message.MessageFactory
+
+
+ The optional name of the EL variable to export this Logger as. Using this
+ attribute makes no sense if the "value" attribute's value is an actual Logger instance.
+ That would result in an existing Logger on the scope being re-added to the
+ scope.
+ var
+ false
+ false
+ java.lang.String
+
+
+ Either "page," "request," "session," or "application," the optional scope that
+ the EL variable should be exported to (defaults to "page").
+ scope
+ false
+ false
+ java.lang.String
+
+
+
+
+
+ ]]>
+
+
+
+ Conditional tag that evaluates its body only if the specified log level and
+ marker are enabled.
+ ifEnabled
+ org.apache.logging.log4j.taglib.IfEnabledTag
+ JSP
+
+ The name or instance of the Logger to use to override the default Logger
+ for this JSP.
+ logger
+ false
+ true
+ java.lang.Object
+
+
+ The name of any valid Level (TRACE, DEBUG, INFO, etc.) or an actual Level
+ instance to check whether it is enabled. This value is case-insensitive.
+ level
+ true
+ true
+ java.lang.Object
+
+
+ Marker data to include in the enabled check.
+ marker
+ false
+ true
+ org.apache.logging.log4j.Marker
+
+
+ Evaluate this content
+
+
+
+ Evaluate this content
+
+ ]]>
+
+
+
+ Equivalent of org.apache.logging.log4j.Logger#catching().
+ catching
+ org.apache.logging.log4j.taglib.CatchingTag
+ empty
+
+ The name or instance of the Logger to use to override the default Logger
+ for this JSP.
+ logger
+ false
+ true
+ java.lang.Object
+
+
+ The name of any valid level (TRACE, DEBUG, INFO, etc.) or an actual Level
+ instance to log this at. This value is case-insensitive and defaults to ERROR for this
+ tag.
+ level
+ false
+ true
+ java.lang.Object
+
+
+ The exception that should be logged.
+ exception
+ true
+ true
+ java.lang.Throwable
+
+
+ <%= 5 / 0 %>
+
+
+
+
+ ]]>
+
+
+
+ Equivalent of org.apache.logging.log4j.Logger#entry(). This tag has dynamic
+ attributes enabled. You may specify any number of arbitrary attributes whose values
+ will be logged with this entry (TRACE) statement. The attribute names will be
+ ignored.
+ entry
+ org.apache.logging.log4j.taglib.EntryTag
+ empty
+
+ The name or instance of the Logger to use to override the default Logger
+ for this JSP.
+ logger
+ false
+ true
+ java.lang.Object
+
+ true
+
+
+
+
+ ]]>
+
+
+
+ Equivalent of org.apache.logging.log4j.Logger#exit().
+ exit
+ org.apache.logging.log4j.taglib.ExitTag
+ empty
+
+ The name or instance of the Logger to use to override the default Logger
+ for this JSP.
+ logger
+ false
+ true
+ java.lang.Object
+
+
+ An optional object to log with the exit (TRACE) statement.
+ result
+ false
+ true
+ java.lang.Object
+
+
+
+
+
+ ]]>
+
+
+
+ Equivalent of org.apache.logging.log4j.Logger#log(). This tag has dynamic
+ attributes enabled. You may specify any number of arbitrary attributes whose values will be
+ substituted in the String message. The "message" must be a String for this to work correctly.
+ See the Log4j 2 manual for more information about message parameters and substitution. Only
+ attribute values are used; attribute names are ignored.
+ log
+ org.apache.logging.log4j.taglib.LogTag
+ JSP
+
+ The name or instance of the Logger to use to override the default Logger
+ for this JSP.
+ logger
+ false
+ true
+ java.lang.Object
+
+
+ The name of any valid level (TRACE, DEBUG, INFO, etc.) or an actual Level
+ instance to log this at. This value is case-insensitive.
+ level
+ true
+ true
+ java.lang.Object
+
+
+ The message that should be logged. May be a String, Object, or
+ org.apache.logging.log4j.message.Message. Either this attribute or body content are
+ required.
+ message
+ false
+ true
+ java.lang.Object
+
+
+ Optional marker data to include in this logging event.
+ marker
+ false
+ true
+ org.apache.logging.log4j.Marker
+
+
+ Optional exception that should be logged.
+ exception
+ false
+ true
+ java.lang.Throwable
+
+ true
+
+
+
+ Log this message
+
+ ]]>
+
+
+
+ Equivalent of org.apache.logging.log4j.Logger#trace(). This tag has dynamic
+ attributes enabled. You may specify any number of arbitrary attributes whose values will be
+ substituted in the String message. The "message" must be a String for this to work correctly.
+ See the Log4j 2 manual for more information about message parameters and substitution. Only
+ attribute values are used; attribute names are ignored.
+ trace
+ org.apache.logging.log4j.taglib.TraceTag
+ JSP
+
+ The name or instance of the Logger to use to override the default Logger
+ for this JSP.
+ logger
+ false
+ true
+ java.lang.Object
+
+
+ The message that should be logged. May be a String, Object, or
+ org.apache.logging.log4j.message.Message. Either this attribute or body content are
+ required.
+ message
+ false
+ true
+ java.lang.Object
+
+
+ Optional marker data to include in this logging event.
+ marker
+ false
+ true
+ org.apache.logging.log4j.Marker
+
+
+ Optional exception that should be logged.
+ exception
+ false
+ true
+ java.lang.Throwable
+
+ true
+
+
+
+ Log this message
+
+ ]]>
+
+
+
+ Equivalent of org.apache.logging.log4j.Logger#debug(). This tag has dynamic
+ attributes enabled. You may specify any number of arbitrary attributes whose values will be
+ substituted in the String message. The "message" must be a String for this to work correctly.
+ See the Log4j 2 manual for more information about message parameters and substitution. Only
+ attribute values are used; attribute names are ignored.
+ debug
+ org.apache.logging.log4j.taglib.DebugTag
+ JSP
+
+ The name or instance of the Logger to use to override the default Logger
+ for this JSP.
+ logger
+ false
+ true
+ java.lang.Object
+
+
+ The message that should be logged. May be a String, Object, or
+ org.apache.logging.log4j.message.Message. Either this attribute or body content are
+ required.
+ message
+ false
+ true
+ java.lang.Object
+
+
+ Optional marker data to include in this logging event.
+ marker
+ false
+ true
+ org.apache.logging.log4j.Marker
+
+
+ Optional exception that should be logged.
+ exception
+ false
+ true
+ java.lang.Throwable
+
+ true
+
+
+
+ Log this message
+
+ ]]>
+
+
+
+ Equivalent of org.apache.logging.log4j.Logger#info(). This tag has dynamic
+ attributes enabled. You may specify any number of arbitrary attributes whose values will be
+ substituted in the String message. The "message" must be a String for this to work correctly.
+ See the Log4j 2 manual for more information about message parameters and substitution. Only
+ attribute values are used; attribute names are ignored.
+ info
+ org.apache.logging.log4j.taglib.InfoTag
+ JSP
+
+ The name or instance of the Logger to use to override the default Logger
+ for this JSP.
+ logger
+ false
+ true
+ java.lang.Object
+
+
+ The message that should be logged. May be a String, Object, or
+ org.apache.logging.log4j.message.Message. Either this attribute or body content are
+ required.
+ message
+ false
+ true
+ java.lang.Object
+
+
+ Optional marker data to include in this logging event.
+ marker
+ false
+ true
+ org.apache.logging.log4j.Marker
+
+
+ Optional exception that should be logged.
+ exception
+ false
+ true
+ java.lang.Throwable
+
+ true
+
+
+
+ Log this message
+
+ ]]>
+
+
+
+ Equivalent of org.apache.logging.log4j.Logger#warn(). This tag has dynamic
+ attributes enabled. You may specify any number of arbitrary attributes whose values will be
+ substituted in the String message. The "message" must be a String for this to work correctly.
+ See the Log4j 2 manual for more information about message parameters and substitution. Only
+ attribute values are used; attribute names are ignored.
+ warn
+ org.apache.logging.log4j.taglib.WarnTag
+ JSP
+
+ The name or instance of the Logger to use to override the default Logger
+ for this JSP.
+ logger
+ false
+ true
+ java.lang.Object
+
+
+ The message that should be logged. May be a String, Object, or
+ org.apache.logging.log4j.message.Message. Either this attribute or body content are
+ required.
+ message
+ false
+ true
+ java.lang.Object
+
+
+ Optional marker data to include in this logging event.
+ marker
+ false
+ true
+ org.apache.logging.log4j.Marker
+
+
+ Optional exception that should be logged.
+ exception
+ false
+ true
+ java.lang.Throwable
+
+ true
+
+
+
+ Log this message
+
+ ]]>
+
+
+
+ Equivalent of org.apache.logging.log4j.Logger#error(). This tag has dynamic
+ attributes enabled. You may specify any number of arbitrary attributes whose values will be
+ substituted in the String message. The "message" must be a String for this to work correctly.
+ See the Log4j 2 manual for more information about message parameters and substitution. Only
+ attribute values are used; attribute names are ignored.
+ error
+ org.apache.logging.log4j.taglib.ErrorTag
+ JSP
+
+ The name or instance of the Logger to use to override the default Logger
+ for this JSP.
+ logger
+ false
+ true
+ java.lang.Object
+
+
+ The message that should be logged. May be a String, Object, or
+ org.apache.logging.log4j.message.Message. Either this attribute or body content are
+ required.
+ message
+ false
+ true
+ java.lang.Object
+
+
+ Optional marker data to include in this logging event.
+ marker
+ false
+ true
+ org.apache.logging.log4j.Marker
+
+
+ Optional exception that should be logged.
+ exception
+ false
+ true
+ java.lang.Throwable
+
+ true
+
+
+
+ Log this message
+
+ ]]>
+
+
+
+ Equivalent of org.apache.logging.log4j.Logger#fatal(). This tag has dynamic
+ attributes enabled. You may specify any number of arbitrary attributes whose values will be
+ substituted in the String message. The "message" must be a String for this to work correctly.
+ See the Log4j 2 manual for more information about message parameters and substitution. Only
+ attribute values are used; attribute names are ignored.
+ fatal
+ org.apache.logging.log4j.taglib.FatalTag
+ JSP
+
+ The name or instance of the Logger to use to override the default Logger
+ for this JSP.
+ logger
+ false
+ true
+ java.lang.Object
+
+
+ The message that should be logged. May be a String, Object, or
+ org.apache.logging.log4j.message.Message. Either this attribute or body content are
+ required.
+ message
+ false
+ true
+ java.lang.Object
+
+
+ Optional marker data to include in this logging event.
+ marker
+ false
+ true
+ org.apache.logging.log4j.Marker
+
+
+ Optional exception that should be logged.
+ exception
+ false
+ true
+ java.lang.Throwable
+
+ true
+
+
+
+ Log this message
+
+ ]]>
+
+
+
+ Displays all variables bound to the specified scope.
+ dump
+ org.apache.logging.log4j.taglib.DumpTag
+ empty
+
+ Either "page," "request," "session," or "application," the scope whose bound
+ variables should be dumped onto the page inline.
+ scope
+ true
+ false
+ java.lang.String
+
+
+
+
+
+ ]]>
+
+
+
Index: taglib/src/site/site.xml
===================================================================
--- taglib/src/site/site.xml (working copy)
+++ taglib/src/site/site.xml (working copy)
@@ -1,3 +1,4 @@
+
-
+
Logging Services
../images/ls-logo.jpg
Index: taglib/src/site/xdoc/index.xml
===================================================================
--- taglib/src/site/xdoc/index.xml (working copy)
+++ taglib/src/site/xdoc/index.xml (working copy)
@@ -1,4 +1,4 @@
-
+
-
- Log4j Web
- Ralph Goers
-
+
+ Log4j Tag Library
+ Nick Williams
+
-
-
+
+
-
- Contains classes that can be used to initialize logging within a web application.
-
+ The Log4j Log Tag Library creates the capability of inserting log
+ statements in JSPs without the use of Java scripting. It uses the standard Log4j 2 API to log
+ messages according to your Log4j configuration.
-
- Log4j provides a ServletContextListener that will initialize the LoggerContext for your web
- application. It accepts two initialization parameters:
-
- log4jContextName - the name to be given to the LoggerContext. If not specified this will
- default to the display-name of the web application.
- log4jConfiguration - the location of the Log4j configuration file. If the file protocol
- is not specified then the file will be located both in the class path and on the file system.
- If the location is a relative path the file location will be relative to the current
- working directory of the running server.
-
-
-
-
- The JNDIContextFilter is a Servlet Filter that can be used in conjunction with the JNDIContextSelector
- to identify the LoggerContext that should be used. It accepts two parameters.
-
- context-name - the name to be given to the LoggerContext. A context name must be specified.
- config-location - the location of the Log4j configuration file.
-
-
+ This tag library is based on the
+ Jakarta Commons Log Taglib by Joseph Ottinger and James
+ Strachan. For the most part, logging tags written against Jakarta Commons Log Taglib should
+ work against this library as well. However, the "category" attribute from Jakarta has become
+ the "logger" attribute in this library.
-
+
-
-
- The Log4j web components require at least Java 5.
-
-
+
+
+ The Log4j Tag Library requires at least Java 5, at least Servlet 2.5 (or Java EE 5), and at least
+ JSP 2.1 (or Java EE 5).
+
+
-
+
+ In accordance with the Logger
+ API, this tag library has tags to
+ support the following logging calls: "catching", "entry", "exit", "log", "trace", "debug",
+ "info", "warn", "error", and "fatal". The "trace" tag was not supported in Jakarta Commons Log
+ Taglib. The "setLogger", "catching", "entry", and "trace" tags are new to this library. This
+ tag library also supports the conditional tag "ifEnabled" (new) and troubleshooting tag "dump"
+ (existed in Jakarta Commons Log Taglib).
+
+ By default, this tag library uses a different Logger for each JSP named after the JSP ID.
+ You can customize the Logger in any of the logging tags or the "ifEnabled" tag with the
+ "logger" attribute. You can also use the "setLogger" tag to specify the Logger that should apply
+ for the rest of a JSP's execution. If the "setLogger" tag comes before any other logging tags in
+ a JSP, the default Logger for that JSP will not be created, but instead the specified logger is
+ the only one that will be used.
+
+ Every effort was made to optimize these tags and ensure decent performance, but users of
+ this library should keep in mind that the creation and execution of JSP tags adds significant
+ overhead to the standard Log4j method calls. While the "trace", "debug", and "info" options are
+ available in this library, their uses are not nano-second order of magnitude with logging off
+ that users may be used to with standard Log4j method calls. Therefore, they should be used
+ sparingly. Use of the "ifEnabled" tag does not improve this performance; this tag is available
+ to conditionally evaluate other actions in addition to logging actions.
+
+ For detailed documentation of each tag, see the Tag Library Reference or the
+ TLDDoc Documentation .
+
+
+
\ No newline at end of file
Index: web/pom.xml
===================================================================
--- web/pom.xml (revision 1462167)
+++ web/pom.xml (working copy)
@@ -26,8 +26,8 @@
org.apache.logging.log4j.adapters
log4j-web
jar
- Log4j Web Adapters
- Log4j Adapters for Web Applications
+ Apache Log4j Web Adapters
+ Apache Log4j Adapters for Web Applications
${basedir}/..
Log4j Web Application Documentation
@@ -53,7 +53,7 @@
javax.servlet
servlet-api
- 2.4
+ 2.5
provided
Index: web/src/site/site.xml
===================================================================
--- web/src/site/site.xml (revision 1462167)
+++ web/src/site/site.xml (working copy)
@@ -1,3 +1,4 @@
+