[logback-dev] svn commit: r987 - logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Wed Nov 22 20:31:52 CET 2006
Author: ceki
Date: Wed Nov 22 20:31:52 2006
New Revision: 987
Modified:
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java
Log:
Added filter support
Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java (original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java Wed Nov 22 20:31:52 2006
@@ -13,8 +13,12 @@
import ch.qos.logback.core.Appender;
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.CoreGlobal;
+import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.AppenderAttachable;
import ch.qos.logback.core.spi.AppenderAttachableImpl;
+import ch.qos.logback.core.spi.FilterAttachable;
+import ch.qos.logback.core.spi.FilterAttachableImpl;
+import ch.qos.logback.core.spi.FilterReply;
import ch.qos.logback.core.status.ErrorStatus;
import ch.qos.logback.core.status.WarnStatus;
import ch.qos.logback.core.util.StatusPrinter;
@@ -30,65 +34,66 @@
* be added to the jetty configuration file, namely <em>etc/jetty.xml</em>:
*
* <pre>
- * <Ref id="requestLog">
- * <Set name="requestLog">
- * <New id="requestLogImpl" class="ch.qos.logback.access.jetty.RequestLogImpl"></New>
- * </Set>
- * </Ref>
+ * <Ref id="requestLog">
+ * <Set name="requestLog">
+ * <New id="requestLogImpl" class="ch.qos.logback.access.jetty.RequestLogImpl"></New>
+ * </Set>
+ * </Ref>
* </pre>
*
* By default, RequestLogImpl looks for a logback configuration file called
* logback-access.xml, in the same folder where jetty.xml is located, that is
- * <em>etc/logback-access.xml</em>. The logback-access.xml file is slightly different than the usual
- * logback classic configuration file. Most of it is the same: Appenders and
- * Layouts are declared the exact same way. However, loggers elements are not
- * allowed.
+ * <em>etc/logback-access.xml</em>. The logback-access.xml file is slightly
+ * different than the usual logback classic configuration file. Most of it is
+ * the same: Appenders and Layouts are declared the exact same way. However,
+ * loggers elements are not allowed.
* <p>
* It is possible to put the logback configuration file anywhere, as long as
* it's path is specified. Here is another example, with a path to the
* logback-access.xml file.
*
* <pre>
- * <Ref id="requestLog">
- * <Set name="requestLog">
- * <New id="requestLogImpl" class="ch.qos.logback.access.jetty.RequestLogImpl"></New>
- * <Set name="fileName">path/to/logback.xml</Set>
- * </Set>
- * </Ref>
+ * <Ref id="requestLog">
+ * <Set name="requestLog">
+ * <New id="requestLogImpl" class="ch.qos.logback.access.jetty.RequestLogImpl"></New>
+ * <Set name="fileName">path/to/logback.xml</Set>
+ * </Set>
+ * </Ref>
* </pre>
*
* <p>
* Here is a sample logback-access.xml file that can be used right away:
*
* <pre>
- * <configuration>
- * <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- * <layout class="ch.qos.logback.access.PatternLayout">
- * <param name="Pattern" value="%date %server %remoteIP %clientHost %user %requestURL" />
- * </layout>
- * </appender>
- *
- * <appender-ref ref="STDOUT" />
- * </configuration>
+ * <configuration>
+ * <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ * <layout class="ch.qos.logback.access.PatternLayout">
+ * <param name="Pattern" value="%date %server %remoteIP %clientHost %user %requestURL" />
+ * </layout>
+ * </appender>
+ *
+ * <appender-ref ref="STDOUT" />
+ * </configuration>
* </pre>
*
* <p>
* Another configuration file, using SMTPAppender, could be:
*
* <pre>
- * <configuration>
- * <appender name="SMTP" class="ch.qos.logback.access.net.SMTPAppender">
- * <layout class="ch.qos.logback.access.PatternLayout">
- * <param name="pattern" value="%remoteIP [%date] %requestURL %statusCode %bytesSent" />
- * </layout>
- * <param name="From" value="sender at domaine.org" />
- * <param name="SMTPHost" value="mail.domain.org" />
- * <param name="Subject" value="Last Event: %statusCode %requestURL" />
- * <param name="To" value="server_admin at domain.org" />
- * </appender>
- * <appender-ref ref="SMTP" />
- * </configuration>
+ * <configuration>
+ * <appender name="SMTP" class="ch.qos.logback.access.net.SMTPAppender">
+ * <layout class="ch.qos.logback.access.PatternLayout">
+ * <param name="pattern" value="%remoteIP [%date] %requestURL %statusCode %bytesSent" />
+ * </layout>
+ * <param name="From" value="sender at domaine.org" />
+ * <param name="SMTPHost" value="mail.domain.org" />
+ * <param name="Subject" value="Last Event: %statusCode %requestURL" />
+ * <param name="To" value="server_admin at domain.org" />
+ * </appender>
+ * <appender-ref ref="SMTP" />
+ * </configuration>
* </pre>
+ *
* <p>
* A special, module-specific implementation of PatternLayout was implemented to
* allow http-specific patterns to be used. The
@@ -103,26 +108,29 @@
* @author Sébastien Pennec
*/
public class RequestLogImpl extends ContextBase implements RequestLog,
- AppenderAttachable {
+ AppenderAttachable, FilterAttachable {
public final static String DEFAULT_CONFIG_FILE = "etc" + File.separatorChar
+ "logback-access.xml";
AppenderAttachableImpl aai = new AppenderAttachableImpl();
+ FilterAttachableImpl fai = new FilterAttachableImpl();
String filename;
public RequestLogImpl() {
putObject(CoreGlobal.EVALUATOR_MAP, new HashMap());
}
-
-
+
public void log(Request jettyRequest, Response jettyResponse) {
JettyServerAdapter adapter = new JettyServerAdapter(jettyRequest,
jettyResponse);
AccessEvent accessEvent = new AccessEvent(jettyRequest, jettyResponse,
adapter);
+
+ if (getFilterChainDecision(accessEvent) == FilterReply.DENY) {
+ return;
+ }
// TODO better exception handling
- //check filter decision see AppenderBase
aai.appendLoopOnAppenders(accessEvent);
}
@@ -211,4 +219,20 @@
public Appender detachAppender(String name) {
return aai.detachAppender(name);
}
+
+ public void addFilter(Filter newFilter) {
+ fai.addFilter(newFilter);
+ }
+
+ public void clearAllFilters() {
+ fai.clearAllFilters();
+ }
+
+ public FilterReply getFilterChainDecision(Object event) {
+ return fai.getFilterChainDecision(event);
+ }
+
+ public Filter getFirstFilter() {
+ return fai.getFirstFilter();
+ }
}
More information about the logback-dev
mailing list