annotate src/org/eclipse/jetty/server/handler/RequestLogHandler.java @ 856:ea1768c00d03

remove NCSARequestLog and RequestLog
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 21 Sep 2016 00:19:26 -0600
parents 22a4e93ed20e
children 23a57aad34c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 // ------------------------------------------------------------------------
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 // All rights reserved. This program and the accompanying materials
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 // are made available under the terms of the Eclipse Public License v1.0
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 // and Apache License v2.0 which accompanies this distribution.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 // The Eclipse Public License is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 // http://www.eclipse.org/legal/epl-v10.html
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 // The Apache License v2.0 is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 // http://www.opensource.org/licenses/apache2.0.php
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 // You may elect to redistribute this code under either of these licenses.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 package org.eclipse.jetty.server.handler;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
856
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
21 import java.io.File;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
22 import java.io.FileOutputStream;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
23 import java.io.OutputStream;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
24 import java.io.OutputStreamWriter;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
25 import java.io.Writer;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 import java.io.IOException;
856
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
27 import java.text.DateFormat;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
28 import java.text.SimpleDateFormat;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
29 import java.util.Locale;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
30 import java.util.TimeZone;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 import javax.servlet.DispatcherType;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 import javax.servlet.ServletException;
856
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
34 import javax.servlet.http.Cookie;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 import javax.servlet.http.HttpServletRequest;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 import javax.servlet.http.HttpServletResponse;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 import org.eclipse.jetty.continuation.Continuation;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 import org.eclipse.jetty.continuation.ContinuationListener;
856
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
40 import org.eclipse.jetty.http.HttpHeaders;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 import org.eclipse.jetty.server.AsyncContinuation;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 import org.eclipse.jetty.server.Request;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 import org.eclipse.jetty.server.Response;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 import org.eclipse.jetty.server.Server;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 import org.eclipse.jetty.util.component.AbstractLifeCycle;
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
46 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
47 import org.slf4j.LoggerFactory;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 /**
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 * RequestLogHandler.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 * This handler can be used to wrap an individual context for context logging.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 * @org.apache.xbean.XBean
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 public class RequestLogHandler extends HandlerWrapper
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 {
856
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
58 private static final Logger LOG = LoggerFactory.getLogger(RequestLogHandler.class);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
59
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
60 /* ------------------------------------------------------------ */
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
61 /*
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
62 * @see org.eclipse.jetty.server.server.Handler#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
63 */
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
64 @Override
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
65 public void handle(String target, final Request baseRequest, HttpServletRequest request, final HttpServletResponse response)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
66 throws IOException, ServletException
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
67 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
68 AsyncContinuation continuation = baseRequest.getAsyncContinuation();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
69 if (!continuation.isInitial())
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
70 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
71 baseRequest.setDispatchTime(System.currentTimeMillis());
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
72 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
73
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
74 try
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
75 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
76 super.handle(target, baseRequest, request, response);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
77 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
78 finally
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
79 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
80 if (baseRequest.getDispatcherType().equals(DispatcherType.REQUEST))
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
81 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
82 if (continuation.isAsync())
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
83 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
84 if (continuation.isInitial())
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
85 continuation.addContinuationListener(new ContinuationListener()
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
86 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
87
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
88 public void onTimeout(Continuation continuation)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
89 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
90
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
91 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
92
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
93 public void onComplete(Continuation continuation)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
94 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
95 log(baseRequest, (Response)response);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
96 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
97 });
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
98 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
99 else
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
100 log(baseRequest, (Response)response);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
101 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
102 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
103 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
104
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
105 /* ------------------------------------------------------------ */
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
106
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
107 /* ------------------------------------------------------------ */
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
108 /*
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
109 * @see org.eclipse.jetty.server.server.handler.HandlerWrapper#doStart()
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
110 */
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
111 @Override
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
112 protected void doStart() throws Exception
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
113 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
114 super.doStart();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
115 startLog();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
116 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
117
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
118 /* ------------------------------------------------------------ */
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
119 /*
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
120 * @see org.eclipse.jetty.server.server.handler.HandlerWrapper#doStop()
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
121 */
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
122 @Override
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
123 protected void doStop() throws Exception
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
124 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
125 super.doStop();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
126 stopLog();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
127 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
128
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
129
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130
856
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
131 // from NCSARequestLog
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
132
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
133 public String filename = null;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
134 private boolean extended = false;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
135 public long retainTime = 1000L*60*60*24*31; // 31 days
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
136 private boolean _closeOut;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
137 public boolean preferProxiedForAddress = false;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
138 public String logDateFormat = "dd/MMM/yyyy:HH:mm:ss Z";
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
139 public Locale logLocale = Locale.getDefault();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
140 public TimeZone timeZone = TimeZone.getTimeZone("GMT");
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
141 public boolean logLatency = false;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
142 public boolean logCookies = false;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
143 public boolean logServer = false;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
144 public boolean logDispatch = false;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
145
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
146 private transient OutputStream _out;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
147 private transient DateFormat dateFormat;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
148 private transient Writer _writer;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
149
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
150 /* ------------------------------------------------------------ */
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
151 /**
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
152 * Writes the request and response information to the output stream.
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
153 *
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
154 * @see org.eclipse.jetty.server.RequestLog#log(org.eclipse.jetty.server.Request, org.eclipse.jetty.server.Response)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
155 */
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
156 public void log(Request request, Response response)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
157 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
158 try
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
159 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
160 if (_out == null)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
161 return;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
162
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
163 StringBuilder buf = new StringBuilder(256);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
164
856
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
165 if (logServer)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
166 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
167 buf.append(request.getServerName());
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
168 buf.append(' ');
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
169 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
170
856
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
171 String addr = null;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
172 if (preferProxiedForAddress)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
173 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
174 addr = request.getHeader(HttpHeaders.X_FORWARDED_FOR);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
175 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
176
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
177 if (addr == null)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
178 addr = request.getRemoteAddr();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
179
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
180 buf.append(addr);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
181 buf.append(" - [");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
182
856
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
183 synchronized(dateFormat) {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
184 buf.append(dateFormat.format(request.getTimeStamp()));
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
185 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
186
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
187 buf.append("] \"");
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
188 buf.append(request.getMethod());
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
189 buf.append(' ');
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
190 buf.append(request.getUri().toString());
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
191 buf.append(' ');
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
192 buf.append(request.getProtocol());
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
193 buf.append("\" ");
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
194 if (request.getAsyncContinuation().isInitial())
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
195 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
196 int status = response.getStatus();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
197 if (status <= 0)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
198 status = 404;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
199 buf.append((char)('0' + ((status / 100) % 10)));
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
200 buf.append((char)('0' + ((status / 10) % 10)));
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
201 buf.append((char)('0' + (status % 10)));
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
202 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
203 else
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
204 buf.append("Async");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
205
856
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
206 long responseLength = response.getContentCount();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
207 if (responseLength >= 0)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
208 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
209 buf.append(' ');
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
210 if (responseLength > 99999)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
211 buf.append(responseLength);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
212 else
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
213 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
214 if (responseLength > 9999)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
215 buf.append((char)('0' + ((responseLength / 10000) % 10)));
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
216 if (responseLength > 999)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
217 buf.append((char)('0' + ((responseLength / 1000) % 10)));
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
218 if (responseLength > 99)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
219 buf.append((char)('0' + ((responseLength / 100) % 10)));
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
220 if (responseLength > 9)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
221 buf.append((char)('0' + ((responseLength / 10) % 10)));
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
222 buf.append((char)('0' + (responseLength) % 10));
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
223 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
224 buf.append(' ');
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
225 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
226 else
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
227 buf.append(" - ");
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
228
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
229
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
230 if (extended)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
231 logExtended(request, response, buf);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
232
856
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
233 if (logCookies)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
234 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
235 Cookie[] cookies = request.getCookies();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
236 if (cookies == null || cookies.length == 0)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
237 buf.append(" -");
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
238 else
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
239 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
240 buf.append(" \"");
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
241 for (int i = 0; i < cookies.length; i++)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
242 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
243 if (i != 0)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
244 buf.append(';');
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
245 buf.append(cookies[i].getName());
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
246 buf.append('=');
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
247 buf.append(cookies[i].getValue());
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
248 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
249 buf.append('\"');
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
250 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
251 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
252
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
253 if (logDispatch || logLatency)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
254 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
255 long now = System.currentTimeMillis();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
256
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
257 if (logDispatch)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
258 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
259 long d = request.getDispatchTime();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
260 buf.append(' ');
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
261 buf.append(now - (d==0 ? request.getTimeStamp():d));
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
262 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
263
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
264 if (logLatency)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
265 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
266 buf.append(' ');
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
267 buf.append(now - request.getTimeStamp());
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
268 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
269 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
270
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
271 buf.append('\n');
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
272
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
273 String log = buf.toString();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
274 write(log);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
275 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
276 catch (IOException e)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
277 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
278 LOG.warn("",e);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
279 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
280 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
281
856
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
282 /* ------------------------------------------------------------ */
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
283 protected synchronized void write(String log) throws IOException
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
284 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
285 if (_writer==null)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
286 return;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
287 _writer.write(log);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
288 _writer.flush();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
289 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
290
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
291
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
292 /* ------------------------------------------------------------ */
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
293 /**
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
294 * Writes extended request and response information to the output stream.
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
295 *
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
296 * @param request request object
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
297 * @param response response object
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
298 * @param b StringBuilder to write to
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
299 * @throws IOException
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
300 */
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
301 protected void logExtended(Request request,
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
302 Response response,
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
303 StringBuilder b) throws IOException
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
304 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
305 String referer = request.getHeader(HttpHeaders.REFERER);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
306 if (referer == null)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
307 b.append("\"-\" ");
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
308 else
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
309 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
310 b.append('"');
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
311 b.append(referer);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
312 b.append("\" ");
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
313 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
314
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
315 String agent = request.getHeader(HttpHeaders.USER_AGENT);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
316 if (agent == null)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
317 b.append("\"-\" ");
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
318 else
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
319 {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
320 b.append('"');
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
321 b.append(agent);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
322 b.append('"');
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
323 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
324 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
325
856
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
326 private synchronized void startLog() throws Exception {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
327 dateFormat = new SimpleDateFormat(logDateFormat,logLocale);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
328 dateFormat.setTimeZone(timeZone);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
329
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
330 if (filename != null) {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
331 File file = new File(filename);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
332 if( file.exists() ) {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
333 File old = new File(filename+".old");
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
334 if( old.exists() && file.lastModified() - old.lastModified() > retainTime )
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
335 old.delete();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
336 if( !old.exists() )
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
337 file.renameTo(old);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
338 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
339 _out = new FileOutputStream(file,true);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
340 _closeOut = true;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
341 LOG.info("Opened " + filename);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
342 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
343 else
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
344 _out = System.err;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
345
856
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
346 _writer = new OutputStreamWriter(_out);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
347 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
348
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
349 private synchronized void stopLog() throws Exception {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
350 try {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
351 if (_writer != null)
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
352 _writer.flush();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
353 } catch (IOException e) {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
354 LOG.trace("",e);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
355 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
356 if (_closeOut) {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
357 try {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
358 _out.close();
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
359 } catch (IOException e) {
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
360 LOG.trace("",e);
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
361 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
362 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
363 _out = null;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
364 _closeOut = false;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
365 dateFormat = null;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
366 _writer = null;
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
367 }
ea1768c00d03 remove NCSARequestLog and RequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 848
diff changeset
368
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
369 }