1
1
/**
2
2
* Logback: the reliable, generic, fast and flexible logging framework.
3
3
* Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4
- *
4
+ * <p>
5
5
* This program and the accompanying materials are dual-licensed under
6
6
* either the terms of the Eclipse Public License v1.0 as published by
7
7
* the Eclipse Foundation
8
- *
9
- * or (per the licensee's choosing)
10
- *
8
+ * <p>
9
+ * or (per the licensee's choosing)
10
+ * <p>
11
11
* under the terms of the GNU Lesser General Public License version 2.1
12
12
* as published by the Free Software Foundation.
13
13
*/
54
54
* </p>
55
55
* <h2>Supported Jetty Versions</h2>
56
56
* <p>
57
- * This {@code RequestLogImpl} only supports Jetty 7.0.0 through Jetty 10.
58
- * If you are using Jetty 11 with the new Jakarta Servlets (namespace {@code jakarta.servlet})
59
- * then you will need a more modern version of {@code logback-access}.
57
+ * This {@code RequestLogImpl} only supports Jetty 7.0.0 through Jetty 10.
58
+ * If you are using Jetty 11 with the new Jakarta Servlets (namespace {@code jakarta.servlet})
59
+ * then you will need a more modern version of {@code logback-access}.
60
60
* </p>
61
61
* <h2>Configuring for Jetty 9.4.x through to Jetty 10.0.x</h2>
62
62
* <p>
63
- * Jetty 9.4.x and Jetty 10.x use a modern @{code server.setRequestLog(RequestLog)} interface that
64
- * is based on a Server level RequestLog behavior. This means all requests are logged,
65
- * even bad requests, and context-less requests. The internals of the Jetty Request and
66
- * Response objects track the state of the object at the time they are committed (the
67
- * actual state during the application when an action on the network commits the
68
- * request/response exchange). This prevents behaviors from 3rd party libraries
69
- * that change the state of the request / response before the RequestLog gets a chance
70
- * to log the details. This differs from Jetty 9.3.x and
71
- * older in that those versions used a (now deprecated) {@code RequestLogHandler} and
72
- * would never see bad requests, or context-less requests,
73
- * and if a 3rd party library modifies the the response (for example by setting
74
- * {@code response.setStatus(200)} after the response has been initiated on the network)
75
- * this change in status would be logged, instead of the actual status that was sent.
63
+ * Jetty 9.4.x and Jetty 10.x use a modern {@code org.eclipse.jetty.server.Server.setRequestLog(RequestLog)}
64
+ * interface that is based on a Server level RequestLog behavior. This means all requests are logged,
65
+ * even bad requests, and context-less requests.
66
+ * </p>
67
+ * <p>
68
+ * The internals of the Jetty Request and Response objects track the state of the object at the time
69
+ * they are committed (the actual state during the application when an action on the network commits the
70
+ * request/response exchange). This prevents behaviors from 3rd party libraries
71
+ * that change the state of the request / response before the RequestLog gets a chance
72
+ * to log the details. This differs from Jetty 9.3.x and
73
+ * older in that those versions used a (now deprecated) {@code RequestLogHandler} and
74
+ * would never see bad requests, or context-less requests,
75
+ * and if a 3rd party library modifies the the response (for example by setting
76
+ * {@code response.setStatus(200)} after the response has been initiated on the network)
77
+ * this change in status would be logged, instead of the actual status that was sent.
76
78
* </p>
77
79
* <p>
78
- * First, you must be using the proper {@code ${jetty.home}} and {@code ${jetty.base}}
79
- * directory split. Configure your {@code ${jetty.base}} with at least the `resources` module
80
- * enabled (so that your configuration can be found).
80
+ * First, you must be using the proper {@code ${jetty.home}} and {@code ${jetty.base}}
81
+ * directory split. Configure your {@code ${jetty.base}} with at least the `resources` module
82
+ * enabled (so that your configuration can be found).
81
83
* </p>
82
84
* <p>
83
- * Next, create a {@code ${jetty.base}/etc/logback-access-requestlog .xml} file with the following
84
- * content.
85
+ * Next, create a {@code ${jetty.base}/etc/logback-access.xml} file with the following
86
+ * content.
85
87
* </p>
86
88
* <pre>
87
89
* <?xml version="1.0"?>
93
95
* <Set name="resource">logback-access.xml</Set>
94
96
* </New>
95
97
* </Set>
96
- * </Configure>
97
- * </pre>
98
- * <p/>
98
+ * </Configure></pre>
99
+ *
99
100
* <p>
100
- * Now you'll need a {@code ${jetty.base}/resources/logback-access.xml} configuration file.
101
+ * Now you'll need a {@code ${jetty.base}/resources/logback-access.xml} configuration file.
101
102
* </p>
103
+ *
104
+ * <p>
102
105
* By default, {@code RequestLogImpl} looks for a logback configuration file called
103
106
* {@code etc/logback-access.xml}, in the {@code ${jetty.base}} directory, then
104
107
* the older {@code ${jetty.home}} directory.
108
+ * </p>
109
+ * <p>
105
110
* The {@code logback-access.xml} file is slightly
106
111
* different than the usual logback classic configuration file. Most of it is
107
- * the same: Appenders and Layouts are declared the exact same way. However,
108
- * loggers elements are not allowed. <p> It is possible to put the logback
109
- * configuration file anywhere, as long as it's path is specified. Here is
110
- * another example, with a path to the logback-access.xml file.
112
+ * the same: {@link Appender Appenders} and {@link ch.qos.logback.core.Layout layouts}
113
+ * are declared the exact same way. However,
114
+ * loggers elements are not allowed.
115
+ * </p>
116
+ *
117
+ * <p> It is possible to place the logback configuration file anywhere, as long as it's path is specified.
118
+ * Here is another example, with an arbitrary path to the logback-access.xml file.
111
119
* <p/>
112
- *
120
+ *
113
121
* <pre>
114
122
* <?xml version="1.0"?>
115
123
* <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
116
124
*
117
125
* <Configure id="Server" class="org.eclipse.jetty.server.Server">
118
126
* <Set name="requestLog">
119
127
* <New id="LogbackAccess" class="ch.qos.logback.access.jetty.RequestLogImpl">
120
- * <Set name="fileName">/path/to/logback-access.xml</Set>
128
+ * <Set name="fileName">/arbitrary/ path/to/logback-access.xml</Set>
121
129
* </New>
122
130
* </Set>
123
131
* </Configure>
128
136
* the use of the {@code RequestLogHandler} is the technique available to you.
129
137
* Modify your {@code etc/jetty-requestlog.xml}
130
138
* </p>
139
+ *
131
140
* <pre>
132
141
* <?xml version="1.0"?>
133
142
* <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
146
155
* </Ref>
147
156
* </Configure>
148
157
* </pre>
149
- * <p/>
150
- * By default, RequestLogImpl looks for a logback configuration file called
158
+ *
159
+ * <p> By default, RequestLogImpl looks for a logback configuration file called
151
160
* logback-access.xml, in the same folder where jetty.xml is located, that is
152
161
* <em>etc/logback-access.xml</em>. The logback-access.xml file is slightly
153
162
* different from the usual logback classic configuration file. Most of it is
154
163
* the same: Appenders and Layouts are declared the exact same way. However,
155
164
* loggers elements are not allowed.
165
+ * </p>
166
+ *
156
167
* <p>
157
168
* It is possible to put the logback configuration file anywhere, as long as
158
169
* it's path is specified. Here is another example, with a path to the
159
170
* logback-access.xml file.
160
171
* <p/>
161
- *
172
+ *
162
173
* <pre>
163
174
* <?xml version="1.0"?>
164
175
* <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
179
190
* </Ref>
180
191
* </Configure>
181
192
* </pre>
182
- * <p/>
183
193
* <p>
184
- * Here is a sample logback-access.xml file that can be used right away:
194
+ * Next is a sample logback-access.xml file printing access events on the console.
185
195
* <p/>
186
- *
196
+ *
187
197
* <pre>
188
198
* <configuration>
189
199
* <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
195
205
* <appender-ref ref="STDOUT" />
196
206
* </configuration>
197
207
* </pre>
198
- * <p/>
199
208
* <p>
200
- * Another configuration file, using SMTPAppender, could be :
209
+ * Here is another configuration file, using SMTPAppender:
201
210
* <p/>
202
- *
211
+ *
203
212
* <pre>
204
213
* <configuration>
205
214
* <appender name="SMTP" class="ch.qos.logback.access.net.SMTPAppender">
217
226
*
218
227
* @author Ceki Gülcü
219
228
* @author Sébastien Pennec
229
+ * @author Joakim Erdfelt
220
230
*/
221
- public class RequestLogImpl extends ContextBase implements org .eclipse .jetty .util .component .LifeCycle , RequestLog ,
222
- AppenderAttachable <IAccessEvent >, FilterAttachable <IAccessEvent > {
231
+ public class RequestLogImpl extends ContextBase implements org .eclipse .jetty .util .component .LifeCycle , RequestLog , AppenderAttachable <IAccessEvent >, FilterAttachable <IAccessEvent > {
223
232
224
233
public final static String DEFAULT_CONFIG_FILE = "etc" + File .separatorChar + "logback-access.xml" ;
225
234
226
235
enum State {
227
236
FAILED , STOPPED , STARTING , STARTED , STOPPING
228
237
}
238
+
229
239
State state = State .STOPPED ;
230
240
231
241
AppenderAttachableImpl <IAccessEvent > aai = new AppenderAttachableImpl <IAccessEvent >();
@@ -242,9 +252,7 @@ public RequestLogImpl() {
242
252
243
253
// plumb the depths of Jetty and the environment ...
244
254
if (EnvUtil .isClassAvailable (this .getClass (), "jakarta.servlet.http.HttpServlet" )) {
245
- throw new RuntimeException ("The new jakarta.servlet classes are not supported by this " +
246
- "version of logback-access (check for a newer version of logback-access that " +
247
- "does support it)" );
255
+ throw new RuntimeException ("The new jakarta.servlet classes are not supported by this " + "version of logback-access (check for a newer version of logback-access that " + "does support it)" );
248
256
}
249
257
250
258
// look for modern approach to RequestLog
@@ -286,7 +294,7 @@ public void start() {
286
294
StatusPrinter .print (getStatusManager ());
287
295
}
288
296
state = State .STARTED ;
289
- } catch (Throwable t ) {
297
+ } catch (Throwable t ) {
290
298
t .printStackTrace ();
291
299
state = State .FAILED ;
292
300
}
@@ -305,8 +313,7 @@ protected URL getConfigurationFileURL() {
305
313
if (fileName != null ) {
306
314
addInfo ("Will use configuration file [" + fileName + "]" );
307
315
File file = new File (fileName );
308
- if (!file .exists ())
309
- return null ;
316
+ if (!file .exists ()) return null ;
310
317
return FileUtil .fileToURL (file );
311
318
}
312
319
if (resource != null ) {
@@ -322,7 +329,7 @@ protected URL getConfigurationFileURL() {
322
329
}
323
330
324
331
File file = new File (defaultConfigFile );
325
- if (!file .exists ()) {
332
+ if (!file .exists ()) {
326
333
// Then use ${jetty.home} (not supported in Jetty 10+)
327
334
String jettyHomeProperty = OptionHelper .getSystemProperty ("jetty.home" );
328
335
if (!OptionHelper .isEmpty (jettyHomeProperty )) {
@@ -334,8 +341,7 @@ protected URL getConfigurationFileURL() {
334
341
335
342
file = new File (defaultConfigFile );
336
343
addInfo ("Assuming default configuration file [" + defaultConfigFile + "]" );
337
- if (!file .exists ())
338
- return null ;
344
+ if (!file .exists ()) return null ;
339
345
return FileUtil .fileToURL (file );
340
346
}
341
347
@@ -397,7 +403,6 @@ public boolean isFailed() {
397
403
}
398
404
399
405
400
-
401
406
public boolean isQuiet () {
402
407
return quiet ;
403
408
}
0 commit comments