Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
Source Code for Apache Log4j Web Servlet Containers
Apache Log4j Web Servlet Containers
provides support for automatically enabling Log4j in Servlet containers.
Bytecode (Java 8) for Apache Log4j Web Servlet Containers is provided in a separate JAR file like log4j-web-2.14.1.jar.
Source Code files for Apache Log4j IOStreams are provided in both binary packge like apache-log4j-2.14.1-bin.zip and source package like apache-log4j-2.14.1-src.zip. You can download them at Apache Log4j Website.
You can also browse Source Code files for Apache Log4j Web Servlet Containers 2.14.1 below.
✍: FYIcenter.com
⏎ org/apache/logging/log4j/web/appender/ServletAppender.java
/* * 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.web.appender; import java.io.Serializable; import javax.servlet.ServletContext; import org.apache.logging.log4j.core.Filter; import org.apache.logging.log4j.core.Layout; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.appender.AbstractAppender; import org.apache.logging.log4j.core.config.Property; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute; import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory; import org.apache.logging.log4j.core.layout.AbstractStringLayout; import org.apache.logging.log4j.core.layout.PatternLayout; import org.apache.logging.log4j.web.WebLoggerContextUtils; /** * Logs using the ServletContext's log method */ @Plugin(name = "Servlet", category = "Core", elementType = "appender", printObject = true) public class ServletAppender extends AbstractAppender { public static class Builder<B extends Builder<B>> extends AbstractAppender.Builder<B> implements org.apache.logging.log4j.core.util.Builder<ServletAppender> { @PluginBuilderAttribute private boolean logThrowables; @Override public ServletAppender build() { final String name = getName(); if (name == null) { LOGGER.error("No name provided for ServletAppender"); } final ServletContext servletContext = WebLoggerContextUtils.getServletContext(); if (servletContext == null) { LOGGER.error("No servlet context is available"); return null; } Layout<? extends Serializable> layout = getLayout(); if (layout == null) { layout = PatternLayout.createDefaultLayout(); } else if (!(layout instanceof AbstractStringLayout)) { LOGGER.error("Layout must be a StringLayout to log to ServletContext"); return null; } return new ServletAppender(name, layout, getFilter(), servletContext, isIgnoreExceptions(), logThrowables); } /** * Logs with {@link ServletContext#log(String, Throwable)} if true and with {@link ServletContext#log(String)} if false. * * @return whether to log a Throwable with the servlet context. */ public boolean isLogThrowables() { return logThrowables; } /** * Logs with {@link ServletContext#log(String, Throwable)} if true and with {@link ServletContext#log(String)} if false. */ public void setLogThrowables(final boolean logThrowables) { this.logThrowables = logThrowables; } } @PluginBuilderFactory public static <B extends Builder<B>> B newBuilder() { return new Builder<B>().asBuilder(); } private final ServletContext servletContext; private final boolean logThrowables; private ServletAppender(final String name, final Layout<? extends Serializable> layout, final Filter filter, final ServletContext servletContext, final boolean ignoreExceptions, final boolean logThrowables) { super(name, filter, layout, ignoreExceptions, Property.EMPTY_ARRAY); this.servletContext = servletContext; this.logThrowables = logThrowables; } @Override public void append(final LogEvent event) { final String serialized = ((AbstractStringLayout) getLayout()).toSerializable(event); if (logThrowables) { servletContext.log(serialized, event.getThrown()); } else { servletContext.log(serialized); } } /** * Creates a Servlet Appender. * @param layout The layout to use (required). Must extend {@link AbstractStringLayout}. * @param filter The Filter or null. * @param name The name of the Appender (required). * @param ignoreExceptions If {@code true} (default) exceptions encountered when appending events are logged; * otherwise they are propagated to the caller. * @return The ServletAppender. * @deprecated Use {@link #newBuilder()}. */ @Deprecated public static ServletAppender createAppender(final Layout<? extends Serializable> layout, final Filter filter, final String name, final boolean ignoreExceptions) { // @formatter:off return newBuilder().setFilter(filter).setIgnoreExceptions(ignoreExceptions).setLayout(layout).setName(name) .build(); // @formatter:on } }
⏎ org/apache/logging/log4j/web/appender/ServletAppender.java
Or download all of them as a single archive file:
File name: log4j-web-2.14.1-sources.jar File size: 30223 bytes Release date: 2021-03-06 Download
⇒ Source Code for Apache Log4j Tag Library
⇐ Source Code for Apache Log4j IOStreams
2015-11-04, 9867👍, 0💬
Popular Posts:
What Is poi-5.2.3.jar? poi-5.2.3.jar is one of the JAR files for Apache POI 5.2.3, which provides an...
What Is poi-scratchpad-3.5.jar? poi-scratchpad-3.5.jar is one of the JAR files for Apache POI 3.5, w...
Jettison is a collection of Java APIs (like STaX and DOM) which read and write JSON. This allows nea...
Apache Commons Codec library provides implementations of common encoders and decoders such as Base64...
Where to find answers to frequently asked questions on Downloading and Using JDK (Java Development K...