From 9569ff64c906c6a2025b71d4b93d5a0609b56765 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Sat, 22 Oct 2016 10:34:14 +1100 Subject: [PATCH 1/5] removed unnecessary dependency #1020 --- jetty-util/src/main/config/modules/jul-impl.mod | 3 --- 1 file changed, 3 deletions(-) diff --git a/jetty-util/src/main/config/modules/jul-impl.mod b/jetty-util/src/main/config/modules/jul-impl.mod index 0b6b8294da6..33beabdab4e 100644 --- a/jetty-util/src/main/config/modules/jul-impl.mod +++ b/jetty-util/src/main/config/modules/jul-impl.mod @@ -6,9 +6,6 @@ logging jul internal -[depends] -resources - [provides] jul-api jul-impl From 726fcd814c9533ecc3f29d1f3bbf5326b1c13751 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Sat, 22 Oct 2016 10:56:50 +1100 Subject: [PATCH 2/5] fixed simple-impl naming #1023 --- jetty-util/src/main/config/modules/slf4j-simple-impl.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetty-util/src/main/config/modules/slf4j-simple-impl.mod b/jetty-util/src/main/config/modules/slf4j-simple-impl.mod index 197e3de40cd..168ff76e6f3 100644 --- a/jetty-util/src/main/config/modules/slf4j-simple-impl.mod +++ b/jetty-util/src/main/config/modules/slf4j-simple-impl.mod @@ -16,7 +16,7 @@ slf4j-impl [files] maven://org.slf4j/slf4j-simple/${slf4j.version}|lib/slf4j/slf4j-simple-${slf4j.version}.jar -basehome:modules/slf4j-impl +basehome:modules/slf4j-simple-impl [lib] lib/slf4j/slf4j-simple-${slf4j.version}.jar From 1e76c994427fcddaec2faf0a4b6cd8eb88c389e4 Mon Sep 17 00:00:00 2001 From: WalkerWatch Date: Fri, 21 Oct 2016 20:07:31 -0400 Subject: [PATCH 3/5] Issue #644 Additional documentation for updated logging modules. (#1021) Signed-off-by: WalkerWatch --- .../logging/configuring-logging-modules.adoc | 179 ++++++++---------- .../default-logging-with-stderrlog.adoc | 77 +++++--- .../example-logback-centralized-logging.adoc | 6 +- 3 files changed, 128 insertions(+), 134 deletions(-) diff --git a/jetty-documentation/src/main/asciidoc/administration/logging/configuring-logging-modules.adoc b/jetty-documentation/src/main/asciidoc/administration/logging/configuring-logging-modules.adoc index f2a59ff228e..f4734338363 100644 --- a/jetty-documentation/src/main/asciidoc/administration/logging/configuring-logging-modules.adoc +++ b/jetty-documentation/src/main/asciidoc/administration/logging/configuring-logging-modules.adoc @@ -27,9 +27,11 @@ Enabling these frameworks in the Jetty distribution is as easy as activating any [source, screen, subs="{sub-order}"] .... [my-base]$ java -jar ../start.jar --add-to-start=logging-jetty -INFO : logging-jetty initialized in ${jetty.base}/start.d/logging-jetty.ini -INFO : resources transitive -INFO : Base directory was modified +INFO : logging-jetty initialized in ${jetty.base}/start.d/logging-jetty.ini +INFO : resources transitively enabled +MKDIR : ${jetty.base}/resources +COPY : ${jetty.home}/modules/logging-jetty/resources/jetty-logging.properties to ${jetty.base}/resources/jetty-logging.properties +INFO : Base directory was modified .... As noted above, Jetty supports a wide array of logging technologies. @@ -78,7 +80,8 @@ Most other top level logging modules work in the same way: `logging-jcl`, `loggi Jetty uses the SLF4J api as a binding to provide logging information to additional frameworks such as Log4j or Logback. It can also be used on it's own to provide simple server logging. To enable the SLF4J framework, you need to activate the `logging-slf4j` module. -By default, log files will be stored in `${jetty.base}/logs`. + +//TODO - Update after 1019 is resolved [source, screen, subs="{sub-order}"] .... @@ -115,9 +118,9 @@ Proceed (y/N)? y INFO : slf4j-api transitively enabled INFO : logging-slf4j initialized in ${jetty.base}/start.d/logging-slf4j.ini MKDIR : ${jetty.base}/lib/slf4j -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar +DOWNLD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar INFO : Base directory was modified -ERROR : Module logging-slf4j requires a `slf4j-impl` module from one of [slf4j-simple-impl, slf4j-logback, slf4j-jul, slf4j-jcl, slf4j-log4j2, slf4j-log4j] +ERROR : Module logging-slf4j requires a module providing slf4j-impl from one of [slf4j-simple-impl, slf4j-logback, slf4j-jul, slf4j-log4j2, slf4j-log4j] ERROR : Unsatisfied module dependencies: logging-slf4j @@ -154,13 +157,15 @@ INFO : Base directory was modified └── slf4j-simple-impl.ini .... +Jetty is now configured to log using the SLF4J framework. +A standard SLF4J properties file is located in `${jetty.base}/resources/simplelogger.properties`. + [[example-logging-log4j]] ==== Logging with Log4j and Log4j2 It is possible to have the Jetty Server logging configured so that Log4j or Log4j2 controls the output of logging events produced by Jetty. This is accomplished by configuring Jetty for logging to http://logging.apache.org/log4j/[Apache Log4j] via http://slf4j.org/manual.html[Slf4j] and the http://slf4j.org/manual.html#swapping[Slf4j binding layer for Log4j]. Implementation of Log4j can be done by enabling the `logging-log4j` module. -By default, log files will be stored in `${jetty.base}/logs`. [source, screen, subs="{sub-order}"] .... @@ -204,13 +209,12 @@ INFO : resources transitively enabled INFO : slf4j-log4j transitively enabled INFO : logging-log4j initialized in ${jetty.base}/start.d/logging-log4j.ini MKDIR : ${jetty.base}/lib/slf4j -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar -MKDIR : ${jetty.base}/resources -COPY : ${jetty.home}/modules/log4j/log4j.properties to ${jetty.base}/resources/log4j.properties +DOWNLD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar MKDIR : ${jetty.base}/lib/log4j -DOWNLOAD: http://central.maven.org/maven2/log4j/log4j/1.2.17/log4j-1.2.17.jar to ${jetty.base}/lib/log4j/log4j-1.2.17.jar -MKDIR : ${jetty.base}/logs -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-log4j12-1.7.21.jar +COPY : /Users/chris/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar to ${jetty.base}/lib/log4j/log4j-1.2.17.jar +MKDIR : ${jetty.base}/resources +COPY : ${jetty.home}/modules/log4j-impl/resources/log4j.xml to ${jetty.base}/resources/log4j.xml +DOWNLD: http://central.maven.org/maven2/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-log4j12-1.7.21.jar INFO : Base directory was modified [my-base]$ tree @@ -221,19 +225,20 @@ INFO : Base directory was modified │   └── slf4j │   ├── slf4j-api-1.7.21.jar │   └── slf4j-log4j12-1.7.21.jar -├── logs ├── resources -│   └── log4j.properties +│   └── log4j.xml └── start.d └── logging-log4j.ini .... -Or, to enable Log4j2, simply enable the `logging-log4j2` module. -By default, log files will be stored in `${jetty.base}/logs`. +Jetty is now configured to log using the Log4j framework. +A standard Log4j configuration file is located in `${jetty.base}/resources/log4j.xml`. + +Or, to set up Log4j2, enable the `logging-log4j2` module. [source, screen, subs="{sub-order}"] .... -[my-base]$ java -jar ../start.jar --add-to-start=logging-log4j2 +[my-base]$ java -jar ../start.jar --add-to-start=logging-log4j2 ALERT: There are enabled module(s) with licenses. The following 2 module(s): @@ -274,34 +279,32 @@ INFO : resources transitively enabled INFO : slf4j-log4j2 transitively enabled INFO : log4j2-impl transitively enabled MKDIR : ${jetty.base}/lib/slf4j -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar -MKDIR : ${jetty.base}/lib/log4j -DOWNLOAD: http://central.maven.org/maven2/org/apache/logging/log4j/log4j-api/2.6.1/log4j-api-2.6.1.jar to ${jetty.base}/lib/log4j/log4j-api-2.6.1.jar -MKDIR : ${jetty.base}/resources -DOWNLOAD: http://central.maven.org/maven2/org/apache/logging/log4j/log4j-slf4j-impl/2.6.1/log4j-slf4j-impl-2.6.1.jar to ${jetty.base}/lib/log4j/log4j-slf4j-impl-2.6.1.jar +DOWNLD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar MKDIR : ${jetty.base}/lib/log4j2 -DOWNLOAD: http://central.maven.org/maven2/org/apache/logging/log4j/log4j-core/2.6.1/log4j-core-2.6.1.jar to ${jetty.base}/lib/log4j2/log4j-core-2.6.1.jar -COPY : ${jetty.home}/modules/log4j2/log4j2.xml to ${jetty.base}/resources/log4j2.xml -MKDIR : ${jetty.base}/logs +DOWNLD: http://central.maven.org/maven2/org/apache/logging/log4j/log4j-api/2.6.1/log4j-api-2.6.1.jar to ${jetty.base}/lib/log4j2/log4j-api-2.6.1.jar +MKDIR : ${jetty.base}/resources +DOWNLD: http://central.maven.org/maven2/org/apache/logging/log4j/log4j-slf4j-impl/2.6.1/log4j-slf4j-impl-2.6.1.jar to ${jetty.base}/lib/log4j2/log4j-slf4j-impl-2.6.1.jar +DOWNLD: http://central.maven.org/maven2/org/apache/logging/log4j/log4j-core/2.6.1/log4j-core-2.6.1.jar to ${jetty.base}/lib/log4j2/log4j-core-2.6.1.jar +COPY : ${jetty.home}/modules/log4j2-impl/resources/log4j2.xml to ${jetty.base}/resources/log4j2.xml INFO : Base directory was modified [my-base]$ tree . ├── lib -│   ├── log4j -│   │   ├── log4j-api-2.6.1.jar -│   │   └── log4j-slf4j-impl-2.6.1.jar │   ├── log4j2 -│   │   └── log4j-core-2.6.1.jar +│   │   ├── log4j-api-2.6.1.jar +│   │   ├── log4j-core-2.6.1.jar +│   │   └── log4j-slf4j-impl-2.6.1.jar │   └── slf4j │   └── slf4j-api-1.7.21.jar -├── logs ├── resources │   └── log4j2.xml └── start.d └── logging-log4j2.ini .... +At this point Jetty is configured so that the Jetty server itself will log using Log4j2, using the Log4j2 configuration found in `{$jetty.base}/resources/log4j2.xml`. + [[example-logging-logback]] ==== Logging with Logback @@ -309,7 +312,6 @@ It is possible to have the Jetty Server logging configured so that Logback contr This is accomplished by configuring Jetty for logging to `Logback`, which uses http://slf4j.org/manual.html[Slf4j] and the http://logback.qos.ch/[Logback Implementation for Slf4j]. To set up Jetty logging via Logback, enable the `logging-logback` module. -By default, log files will be stored in `${jetty.base}/logs`. [source, screen, subs="{sub-order}"] .... @@ -362,13 +364,12 @@ INFO : slf4j-logback transitively enabled INFO : logging-logback initialized in ${jetty.base}/start.d/logging-logback.ini INFO : resources transitively enabled MKDIR : ${jetty.base}/lib/slf4j -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar +DOWNLD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar MKDIR : ${jetty.base}/lib/logback -DOWNLOAD: http://central.maven.org/maven2/ch/qos/logback/logback-core/1.1.7/logback-core-1.1.7.jar to ${jetty.base}/lib/logback/logback-core-1.1.7.jar +DOWNLD: http://central.maven.org/maven2/ch/qos/logback/logback-core/1.1.7/logback-core-1.1.7.jar to ${jetty.base}/lib/logback/logback-core-1.1.7.jar MKDIR : ${jetty.base}/resources -COPY : ${jetty.home}/modules/logback/logback.xml to ${jetty.base}/resources/logback.xml -MKDIR : ${jetty.base}/logs -DOWNLOAD: http://central.maven.org/maven2/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar to ${jetty.base}/lib/logback/logback-classic-1.1.7.jar +COPY : ${jetty.home}/modules/logback-impl/resources/logback.xml to ${jetty.base}/resources/logback.xml +DOWNLD: http://central.maven.org/maven2/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar to ${jetty.base}/lib/logback/logback-classic-1.1.7.jar INFO : Base directory was modified [my-base]$ tree @@ -379,7 +380,6 @@ INFO : Base directory was modified │   │   └── logback-core-1.1.7.jar │   └── slf4j │   └── slf4j-api-1.7.21.jar -├── logs ├── resources │   └── logback.xml └── start.d @@ -387,7 +387,6 @@ INFO : Base directory was modified .... At this point Jetty is configured so that the Jetty server itself will log using Logback, using the Logback configuration found in `{$jetty.base}/resources/logback.xml`. -Log files will be stored in `${jetty.base}/logs`. ==== Logging with Java Util Logging @@ -396,7 +395,8 @@ Log files will be stored in `${jetty.base}/logs`. It is possible to have the Jetty Server logging configured so that `java.util.logging` controls the output of logging events produced by Jetty. This example demonstrates how to configuring Jetty for logging to `java.util.logging` via http://slf4j.org/manual.html[Slf4j] and the http://slf4j.org/manual.html#swapping[Slf4j binding layer for java.util.logging]. -By default, log files will be stored in `${jetty.base}/logs`. + +//TODO - Review after 1020 is resolved [source, screen, subs="{sub-order}"] .... @@ -436,11 +436,10 @@ INFO : slf4j-jul transitively enabled INFO : logging-jul initialized in ${jetty.base}/start.d/logging-jul.ini INFO : resources transitively enabled MKDIR : ${jetty.base}/etc -COPY : ${jetty.home}/modules/jul-impl/java-util-logging.properties to ${jetty.base}/etc/java-util-logging.properties -MKDIR : ${jetty.base}/logs +COPY : ${jetty.home}/modules/jul-impl/etc/java-util-logging.properties to ${jetty.base}/etc/java-util-logging.properties MKDIR : ${jetty.base}/lib/slf4j -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-jdk14/1.7.21/slf4j-jdk14-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-jdk14-1.7.21.jar +DOWNLD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar +DOWNLD: http://central.maven.org/maven2/org/slf4j/slf4j-jdk14/1.7.21/slf4j-jdk14-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-jdk14-1.7.21.jar MKDIR : ${jetty.base}/resources INFO : Base directory was modified @@ -452,76 +451,50 @@ INFO : Base directory was modified │   └── slf4j │   ├── slf4j-api-1.7.21.jar │   └── slf4j-jdk14-1.7.21.jar -├── logs ├── resources └── start.d └── logging-jul.ini .... -[[example-logging-java-commons-logging]] -==== Logging with Java Commons Logging -Jetty provides support of the Java Commons Logging (jcl) through the `logging-jcl` module, using Slf4j as a binding. -This is enabled by activating the `logging-jcl` module. -By default, log files will be stored in `${jetty.base}/logs`. +Jetty is now configured to log using the JUL framework. +A standard JUL properties file is located in `${jetty.base}/etc/java-util-logging.properties`. + +==== Capturing Console Output + +By default, enabling the above modules will output log information to the console. +Included in the distribution is the `console-capture` module, which can be used in lieu of additional configuration to the selected logging module to capture this output to a `logs` directory in your `${jetty.base}`. +To enable this functionality, activate the `console-capture` module. [source, screen, subs="{sub-order}"] .... -[my-base]$ java -jar ../start.jar --add-to-start=logging-jcl - -ALERT: There are enabled module(s) with licenses. -The following 2 module(s): - + contains software not provided by the Eclipse Foundation! - + contains software not covered by the Eclipse Public License! - + has not been audited for compliance with its license - - Module: jcl-impl - + Log4j is released under the Apache 2.0 license. - + http://www.apache.org/licenses/LICENSE-2.0.html - - Module: slf4j-api - + SLF4J is distributed under the MIT License. - + Copyright (c) 2004-2013 QOS.ch - + All rights reserved. - + Permission is hereby granted, free of charge, to any person obtaining - + a copy of this software and associated documentation files (the - + "Software"), to deal in the Software without restriction, including - + without limitation the rights to use, copy, modify, merge, publish, - + distribute, sublicense, and/or sell copies of the Software, and to - + permit persons to whom the Software is furnished to do so, subject to - + the following conditions: - + The above copyright notice and this permission notice shall be - + included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Proceed (y/N)? y -INFO : slf4j-api transitively enabled -INFO : jcl-impl transitively enabled -INFO : resources transitively enabled -INFO : slf4j-jcl transitively enabled -INFO : logging-jcl initialized in ${jetty.base}/start.d/logging-jcl.ini -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar -DOWNLOAD: http://central.maven.org/maven2/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar to ${jetty.base}/lib/jcl/commons-logging-1.1.3.jar -MKDIR: ${jetty.base}/logs -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-jcl/1.7.21/slf4j-jcl-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-jcl-1.7.21.jar -INFO : Base directory was modified +[my-base]$ java -jar ../start.jar --add-to-start=console-capture +INFO : console-capture initialized in ${jetty.base}/start.d/console-capture.ini +MKDIR : ${jetty.base}/logs +INFO : Base directory was modified [my-base]$ tree . -├── lib -│   ├── jcl -│   │   └── commons-logging-1.1.3.jar -│   └── slf4j -│   ├── slf4j-api-1.7.21.jar -│   └── slf4j-jcl-1.7.21.jar ├── logs -├── resources -│   └── commons-logging.properties └── start.d - └── logging-jcl.ini + └── console-capture.ini +.... + +As an example, here is the output from Logback before using the `console-capture` module: + +[source, screen, subs="{sub-order}"] +.... +[my-base]$ java -jar ../start.jar +419 [main] INFO org.eclipse.jetty.util.log - Logging initialized @508ms to org.eclipse.jetty.util.log.Slf4jLog +540 [main] INFO org.eclipse.jetty.server.Server - jetty-9.4.0-SNAPSHOT +575 [main] INFO o.e.jetty.server.AbstractConnector - Started ServerConnector@3c0ecd4b{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} +575 [main] INFO org.eclipse.jetty.server.Server - Started @668ms +.... + +After enabling `console-capture`, the output is as follows: + +[source, screen, subs="{sub-order}"] +.... +[my-base]$ java -jar ../start.jar +151 [main] INFO org.eclipse.jetty.util.log - Logging initialized @238ms to org.eclipse.jetty.util.log.Slf4jLog +196 [main] INFO org.eclipse.jetty.util.log - Console stderr/stdout captured to /installs/jetty-distribution/mybase/logs/2016_10_21.jetty.log .... diff --git a/jetty-documentation/src/main/asciidoc/administration/logging/default-logging-with-stderrlog.adoc b/jetty-documentation/src/main/asciidoc/administration/logging/default-logging-with-stderrlog.adoc index a5af4795221..a750f94a66c 100644 --- a/jetty-documentation/src/main/asciidoc/administration/logging/default-logging-with-stderrlog.adoc +++ b/jetty-documentation/src/main/asciidoc/administration/logging/default-logging-with-stderrlog.adoc @@ -23,21 +23,39 @@ If you do nothing to configure a separate logging framework, Jetty will default to using an internal `org.eclipse.jetty.util.log.StdErrLog` implementation. This will output all logging events to STDERR (aka `System.err`). -Simply use Jetty and `StdErrLog` based logging is output to the console. +Simply use Jetty and `StdErrLog`-based logging is output to the console. -Included in the Jetty distribution is a logging module that is capable of performing simple capturing of all STDOUT (`System.out`) and STDERR (`System.err`) output to a file that is rotated daily. +Included in the Jetty distribution is a logging module named `console-capture` that is capable of performing simple capturing of all STDOUT (`System.out`) and STDERR (`System.err`) output to a file that is rotated daily. -To enable on this feature via the command line: +To enable this feature, simply activate the `console-capture` module on the command line: + +[source, screen, subs="{sub-order}"] +.... +[my-base]$ java -jar ../start.jar --add-to-start=console-capture +INFO : console-capture initialized in ${jetty.base}/start.d/console-capture.ini +MKDIR : ${jetty.base}/logs +INFO : Base directory was modified + +[my-base]$ tree +. +├── logs +└── start.d + └── console-capture.ini +.... + +The default configuration for logging output will create a file `${jetty.base}/logs/yyyy_mm_dd.stderrout.log` which allows configuration of the output directory by setting the `jetty.logs` property. + +Just enabling the `console-capture` will simply output the values of STDERR and STDOUT to a log file. +To customize the log further, a module named `logging-jetty` is available to provides a default properties file to configure. +As with `console-capture`, you activate the `logging-jetty` on the command line. [source, screen, subs="{sub-order}"] .... [my-base]$ java -jar ../start.jar --add-to-start=logging-jetty INFO : logging-jetty initialized in ${jetty.base}/start.d/logging-jetty.ini -INFO : console-capture transitively enabled, ini template available with --add-to-start=console-capture INFO : resources transitively enabled MKDIR : ${jetty.base}/resources -COPY : ${jetty.home}/modules/logging-jetty/jetty-logging.properties to ${jetty.base}/resources/jetty-logging.properties -MKDIR : ${jetty.base}/logs +COPY : ${jetty.home}/modules/logging-jetty/resources/jetty-logging.properties to ${jetty.base}/resources/jetty-logging.properties INFO : Base directory was modified [my-base]$ tree @@ -46,26 +64,31 @@ INFO : Base directory was modified ├── resources │   └── jetty-logging.properties └── start.d + ├── console-capture.ini └── logging-jetty.ini .... -The default configuration for logging output will create a file `${jetty.base}/logs/yyyy_mm_dd.stderrout.log` which allows configuration of the output directory by setting the `jetty.logs` property. - -For more advanced logging configurations, please consider use of a separate logging library. - -The recommended way to configure `StdErrLog` is to create a `${jetty.base}/resources/jetty-logging.properties` file, specify the log implementation to `StdErrLog` and then setup logging levels. +Once activated, you can find the properties file at `${jetty.base}/resources/jetty-logging.properties`. +By default, the following parameters are defined. +To change them, un-comment the line and substitute your naming scheme and configuration choices. [source, properties, subs="{sub-order}"] .... -# Configure Jetty for StdErrLog Logging -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StrErrLog -# Overall Logging Level is INFO -org.eclipse.jetty.LEVEL=INFO -# Detail Logging for WebSocket -org.eclipse.jetty.websocket.LEVEL=DEBUG +## Force jetty logging implementation +#org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog + +## Set logging levels from: ALL, DEBUG, INFO, WARN, OFF +#org.eclipse.jetty.LEVEL=INFO +#com.example.LEVEL=INFO + +## Hide stacks traces in logs? +#com.example.STACKS=false + +## Show the source file of a log location? +#com.example.SOURCE=false .... -There are a number of properties that can be defined in the configuration that will affect the behavior of `StdErrLog`. +There are a number of properties that can be defined in the configuration that will affect the behavior of StdErr logging with `console-capture`. `.LEVEL=`:: Sets the logging level for all loggers within the `name` specified to the level, which can be (in increasing order of restriction) `ALL`, `DEBUG`, `INFO`, `WARN`, `OFF`. @@ -95,22 +118,20 @@ There are a number of properties that can be defined in the configuration that w + [source, screen, subs="{sub-order}"] .... -2014-06-03 14:36:16.013:INFO:oejs.Server:main: jetty-9.2.0.v20140526 -2014-06-03 14:36:16.028:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/opt/jetty/demo-base/webapps/] at interval 1 -2014-06-03 14:36:16.051:INFO:oejsh.ContextHandler:main: Started o.e.j.s.h.MovedContextHandler@7d256e50{/oldContextPath,null,AVAILABLE} -2014-06-03 14:36:17.880:INFO:oejs.ServerConnector:main: Started ServerConnector@34f2d11a{HTTP/1.1}{0.0.0.0:8080} -2014-06-03 14:36:17.888:INFO:oejs.Server:main: Started @257ms +2016-10-21 15:31:01.248:INFO::main: Logging initialized @332ms to org.eclipse.jetty.util.log.StdErrLog +2016-10-21 15:31:01.370:INFO:oejs.Server:main: jetty-9.4.0-SNAPSHOT +2016-10-21 15:31:01.400:INFO:oejs.AbstractConnector:main: Started ServerConnector@2c330fbc{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} +2016-10-21 15:31:01.400:INFO:oejs.Server:main: Started @485ms .... + * Example when set to true: + [source, screen, subs="{sub-order}"] .... -2014-06-03 14:38:19.019:INFO:org.eclipse.jetty.server.Server:main: jetty-9.2.0.v20140526 -2014-06-03 14:38:19.032:INFO:org.eclipse.jetty.deploy.providers.ScanningAppProvider:main: Deployment monitor [file:/opt/jetty/demo-base/webapps/] at interval 1 -2014-06-03 14:38:19.054:INFO:org.eclipse.jetty.server.handler.ContextHandler:main: Started o.e.j.s.h.MovedContextHandler@246d8660{/oldContextPath,null,AVAILABLE} -2014-06-03 14:38:20.715:INFO:org.eclipse.jetty.server.ServerConnector:main: Started ServerConnector@59f625be{HTTP/1.1}{0.0.0.0:8080} -2014-06-03 14:38:20.723:INFO:org.eclipse.jetty.server.Server:main: Started @243ms +2016-10-21 15:31:35.020:INFO::main: Logging initialized @340ms to org.eclipse.jetty.util.log.StdErrLog +2016-10-21 15:31:35.144:INFO:org.eclipse.jetty.server.Server:main: jetty-9.4.0-SNAPSHOT +2016-10-21 15:31:35.174:INFO:org.eclipse.jetty.server.AbstractConnector:main: Started ServerConnector@edf4efb{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} +2016-10-21 15:31:35.175:INFO:org.eclipse.jetty.server.Server:main: Started @495ms .... [[deprecated-parameters]] diff --git a/jetty-documentation/src/main/asciidoc/administration/logging/example-logback-centralized-logging.adoc b/jetty-documentation/src/main/asciidoc/administration/logging/example-logback-centralized-logging.adoc index 2c4600b2c69..27b0a0874d3 100644 --- a/jetty-documentation/src/main/asciidoc/administration/logging/example-logback-centralized-logging.adoc +++ b/jetty-documentation/src/main/asciidoc/administration/logging/example-logback-centralized-logging.adoc @@ -15,9 +15,9 @@ // ======================================================================== [[example-logging-logback-centralized]] -=== Example: Centralized Logging with Logback +=== Centralized Logging using Logback -The term _Centralized Logging_ refers to a forced logging configuration for the Jetty Server and all web applications that are deployed on the server. +The term _Centralized Logging_ refers to a forced logging configuration for the Jetty Server and all web applications that are deployed on the server. It routes all logging events from the web applications to a single configuration on the Server side. The example below shows how to accomplish this with Jetty and Slf4j, using `Logback` to manage the final writing of logs to disk. @@ -30,7 +30,7 @@ ____ This configuration is essentially the multiple logger configuration with added configuration to the deployers to force a `WebAppClassLoader` change to use the server classpath over the webapps classpath for the logger specific classes. -The technique used by this configuration is to provide an link:{JDURL}org/eclipse/jetty/deploy/AppLifeCycle.Binding.html[AppLifeCycle.Binding] against the link:{JDURL}/org/eclipse/jetty/deploy/AppLifeCycle.html[`"deploying"`node] that modifies the link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#addSystemClass(java.lang.String)[WebAppContext.addSystemClass(String)] for the common logging classes. +The technique used by this configuration is to provide an link:{JDURL}org/eclipse/jetty/deploy/AppLifeCycle.Binding.html[AppLifeCycle.Binding] against the link:{JDURL}/org/eclipse/jetty/deploy/AppLifeCycle.html[`"deploying"`node] that modifies the link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#addSystemClass(java.lang.String)[WebAppContext.addSystemClass(String)] for the common logging classes. See https://github.com/jetty-project/jetty-webapp-logging/blob/master/src/main/java/org/eclipse/jetty/webapp/logging/CentralizedWebAppLoggingBinding.java[org.eclipse.jetty.logging.CentralizedWebAppLoggingBinding] for actual implementation. A convenient replacement `logging` module has been created to bootstrap your `${jetty.base}` directory for capturing all Jetty server logging from multiple logging frameworks into a single logging output file managed by Logback. From 7d4b46cef4c987e0a5860459bbf683a7a55bb253 Mon Sep 17 00:00:00 2001 From: WalkerWatch Date: Fri, 21 Oct 2016 16:40:24 -0400 Subject: [PATCH 4/5] Issue #644 Additional documentation for updated logging modules. Signed-off-by: WalkerWatch --- .../logging/configuring-logging-modules.adoc | 185 +++++++----------- .../default-logging-with-stderrlog.adoc | 77 +++++--- .../example-logback-centralized-logging.adoc | 6 +- 3 files changed, 127 insertions(+), 141 deletions(-) diff --git a/jetty-documentation/src/main/asciidoc/administration/logging/configuring-logging-modules.adoc b/jetty-documentation/src/main/asciidoc/administration/logging/configuring-logging-modules.adoc index f2a59ff228e..6462653a4f6 100644 --- a/jetty-documentation/src/main/asciidoc/administration/logging/configuring-logging-modules.adoc +++ b/jetty-documentation/src/main/asciidoc/administration/logging/configuring-logging-modules.adoc @@ -27,9 +27,11 @@ Enabling these frameworks in the Jetty distribution is as easy as activating any [source, screen, subs="{sub-order}"] .... [my-base]$ java -jar ../start.jar --add-to-start=logging-jetty -INFO : logging-jetty initialized in ${jetty.base}/start.d/logging-jetty.ini -INFO : resources transitive -INFO : Base directory was modified +INFO : logging-jetty initialized in ${jetty.base}/start.d/logging-jetty.ini +INFO : resources transitively enabled +MKDIR : ${jetty.base}/resources +COPY : ${jetty.home}/modules/logging-jetty/resources/jetty-logging.properties to ${jetty.base}/resources/jetty-logging.properties +INFO : Base directory was modified .... As noted above, Jetty supports a wide array of logging technologies. @@ -78,7 +80,6 @@ Most other top level logging modules work in the same way: `logging-jcl`, `loggi Jetty uses the SLF4J api as a binding to provide logging information to additional frameworks such as Log4j or Logback. It can also be used on it's own to provide simple server logging. To enable the SLF4J framework, you need to activate the `logging-slf4j` module. -By default, log files will be stored in `${jetty.base}/logs`. [source, screen, subs="{sub-order}"] .... @@ -115,9 +116,9 @@ Proceed (y/N)? y INFO : slf4j-api transitively enabled INFO : logging-slf4j initialized in ${jetty.base}/start.d/logging-slf4j.ini MKDIR : ${jetty.base}/lib/slf4j -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar +DOWNLD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar INFO : Base directory was modified -ERROR : Module logging-slf4j requires a `slf4j-impl` module from one of [slf4j-simple-impl, slf4j-logback, slf4j-jul, slf4j-jcl, slf4j-log4j2, slf4j-log4j] +ERROR : Module logging-slf4j requires a module providing slf4j-impl from one of [slf4j-simple-impl, slf4j-logback, slf4j-jul, slf4j-log4j2, slf4j-log4j] ERROR : Unsatisfied module dependencies: logging-slf4j @@ -134,10 +135,9 @@ To enable the simple SLF4J implementation, we will also need to activate the `sl [my-base]$ java -jar ../start.jar --add-to-start=slf4j-simple-impl INFO : slf4j-simple-impl initialized in ${jetty.base}/start.d/slf4j-simple-impl.ini INFO : resources transitively enabled -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-simple/1.7.21/slf4j-simple-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-simple-1.7.21.jar +DOWNLD: http://central.maven.org/maven2/org/slf4j/slf4j-simple/1.7.21/slf4j-simple-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-simple-1.7.21.jar MKDIR : ${jetty.base}/resources -COPY : ${jetty.home}/modules/slf4j/simplelogger.properties to ${jetty.base}/resources/simplelogger.properties -MKDIR : ${jetty.base}/logs +COPY : ${jetty.home}/modules/slf4j-simple-impl/resources/simplelogger.properties to ${jetty.base}/resources/simplelogger.properties INFO : Base directory was modified [my-base]$ tree @@ -146,7 +146,6 @@ INFO : Base directory was modified │   └── slf4j │   ├── slf4j-api-1.7.21.jar │   └── slf4j-simple-1.7.21.jar -├── logs ├── resources │   └── simplelogger.properties └── start.d @@ -154,13 +153,15 @@ INFO : Base directory was modified └── slf4j-simple-impl.ini .... +Jetty is now configured to log using the SLF4J framework. +A standard SLF4J properties file is located in `${jetty.base}/resources/simplelogger.properties`. + [[example-logging-log4j]] ==== Logging with Log4j and Log4j2 It is possible to have the Jetty Server logging configured so that Log4j or Log4j2 controls the output of logging events produced by Jetty. This is accomplished by configuring Jetty for logging to http://logging.apache.org/log4j/[Apache Log4j] via http://slf4j.org/manual.html[Slf4j] and the http://slf4j.org/manual.html#swapping[Slf4j binding layer for Log4j]. Implementation of Log4j can be done by enabling the `logging-log4j` module. -By default, log files will be stored in `${jetty.base}/logs`. [source, screen, subs="{sub-order}"] .... @@ -204,13 +205,12 @@ INFO : resources transitively enabled INFO : slf4j-log4j transitively enabled INFO : logging-log4j initialized in ${jetty.base}/start.d/logging-log4j.ini MKDIR : ${jetty.base}/lib/slf4j -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar -MKDIR : ${jetty.base}/resources -COPY : ${jetty.home}/modules/log4j/log4j.properties to ${jetty.base}/resources/log4j.properties +DOWNLD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar MKDIR : ${jetty.base}/lib/log4j -DOWNLOAD: http://central.maven.org/maven2/log4j/log4j/1.2.17/log4j-1.2.17.jar to ${jetty.base}/lib/log4j/log4j-1.2.17.jar -MKDIR : ${jetty.base}/logs -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-log4j12-1.7.21.jar +COPY : /Users/chris/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar to ${jetty.base}/lib/log4j/log4j-1.2.17.jar +MKDIR : ${jetty.base}/resources +COPY : ${jetty.home}/modules/log4j-impl/resources/log4j.xml to ${jetty.base}/resources/log4j.xml +DOWNLD: http://central.maven.org/maven2/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-log4j12-1.7.21.jar INFO : Base directory was modified [my-base]$ tree @@ -221,19 +221,20 @@ INFO : Base directory was modified │   └── slf4j │   ├── slf4j-api-1.7.21.jar │   └── slf4j-log4j12-1.7.21.jar -├── logs ├── resources -│   └── log4j.properties +│   └── log4j.xml └── start.d └── logging-log4j.ini .... -Or, to enable Log4j2, simply enable the `logging-log4j2` module. -By default, log files will be stored in `${jetty.base}/logs`. +Jetty is now configured to log using the Log4j framework. +A standard Log4j configuration file is located in `${jetty.base}/resources/log4j.xml`. + +Or, to set up Log4j2, enable the `logging-log4j2` module. [source, screen, subs="{sub-order}"] .... -[my-base]$ java -jar ../start.jar --add-to-start=logging-log4j2 +[my-base]$ java -jar ../start.jar --add-to-start=logging-log4j2 ALERT: There are enabled module(s) with licenses. The following 2 module(s): @@ -274,34 +275,32 @@ INFO : resources transitively enabled INFO : slf4j-log4j2 transitively enabled INFO : log4j2-impl transitively enabled MKDIR : ${jetty.base}/lib/slf4j -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar -MKDIR : ${jetty.base}/lib/log4j -DOWNLOAD: http://central.maven.org/maven2/org/apache/logging/log4j/log4j-api/2.6.1/log4j-api-2.6.1.jar to ${jetty.base}/lib/log4j/log4j-api-2.6.1.jar -MKDIR : ${jetty.base}/resources -DOWNLOAD: http://central.maven.org/maven2/org/apache/logging/log4j/log4j-slf4j-impl/2.6.1/log4j-slf4j-impl-2.6.1.jar to ${jetty.base}/lib/log4j/log4j-slf4j-impl-2.6.1.jar +DOWNLD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar MKDIR : ${jetty.base}/lib/log4j2 -DOWNLOAD: http://central.maven.org/maven2/org/apache/logging/log4j/log4j-core/2.6.1/log4j-core-2.6.1.jar to ${jetty.base}/lib/log4j2/log4j-core-2.6.1.jar -COPY : ${jetty.home}/modules/log4j2/log4j2.xml to ${jetty.base}/resources/log4j2.xml -MKDIR : ${jetty.base}/logs +DOWNLD: http://central.maven.org/maven2/org/apache/logging/log4j/log4j-api/2.6.1/log4j-api-2.6.1.jar to ${jetty.base}/lib/log4j2/log4j-api-2.6.1.jar +MKDIR : ${jetty.base}/resources +DOWNLD: http://central.maven.org/maven2/org/apache/logging/log4j/log4j-slf4j-impl/2.6.1/log4j-slf4j-impl-2.6.1.jar to ${jetty.base}/lib/log4j2/log4j-slf4j-impl-2.6.1.jar +DOWNLD: http://central.maven.org/maven2/org/apache/logging/log4j/log4j-core/2.6.1/log4j-core-2.6.1.jar to ${jetty.base}/lib/log4j2/log4j-core-2.6.1.jar +COPY : ${jetty.home}/modules/log4j2-impl/resources/log4j2.xml to ${jetty.base}/resources/log4j2.xml INFO : Base directory was modified [my-base]$ tree . ├── lib -│   ├── log4j -│   │   ├── log4j-api-2.6.1.jar -│   │   └── log4j-slf4j-impl-2.6.1.jar │   ├── log4j2 -│   │   └── log4j-core-2.6.1.jar +│   │   ├── log4j-api-2.6.1.jar +│   │   ├── log4j-core-2.6.1.jar +│   │   └── log4j-slf4j-impl-2.6.1.jar │   └── slf4j │   └── slf4j-api-1.7.21.jar -├── logs ├── resources │   └── log4j2.xml └── start.d └── logging-log4j2.ini .... +At this point Jetty is configured so that the Jetty server itself will log using Log4j2, using the Log4j2 configuration found in `{$jetty.base}/resources/log4j2.xml`. + [[example-logging-logback]] ==== Logging with Logback @@ -309,7 +308,6 @@ It is possible to have the Jetty Server logging configured so that Logback contr This is accomplished by configuring Jetty for logging to `Logback`, which uses http://slf4j.org/manual.html[Slf4j] and the http://logback.qos.ch/[Logback Implementation for Slf4j]. To set up Jetty logging via Logback, enable the `logging-logback` module. -By default, log files will be stored in `${jetty.base}/logs`. [source, screen, subs="{sub-order}"] .... @@ -362,13 +360,12 @@ INFO : slf4j-logback transitively enabled INFO : logging-logback initialized in ${jetty.base}/start.d/logging-logback.ini INFO : resources transitively enabled MKDIR : ${jetty.base}/lib/slf4j -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar +DOWNLD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar MKDIR : ${jetty.base}/lib/logback -DOWNLOAD: http://central.maven.org/maven2/ch/qos/logback/logback-core/1.1.7/logback-core-1.1.7.jar to ${jetty.base}/lib/logback/logback-core-1.1.7.jar +DOWNLD: http://central.maven.org/maven2/ch/qos/logback/logback-core/1.1.7/logback-core-1.1.7.jar to ${jetty.base}/lib/logback/logback-core-1.1.7.jar MKDIR : ${jetty.base}/resources -COPY : ${jetty.home}/modules/logback/logback.xml to ${jetty.base}/resources/logback.xml -MKDIR : ${jetty.base}/logs -DOWNLOAD: http://central.maven.org/maven2/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar to ${jetty.base}/lib/logback/logback-classic-1.1.7.jar +COPY : ${jetty.home}/modules/logback-impl/resources/logback.xml to ${jetty.base}/resources/logback.xml +DOWNLD: http://central.maven.org/maven2/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar to ${jetty.base}/lib/logback/logback-classic-1.1.7.jar INFO : Base directory was modified [my-base]$ tree @@ -379,7 +376,6 @@ INFO : Base directory was modified │   │   └── logback-core-1.1.7.jar │   └── slf4j │   └── slf4j-api-1.7.21.jar -├── logs ├── resources │   └── logback.xml └── start.d @@ -387,7 +383,6 @@ INFO : Base directory was modified .... At this point Jetty is configured so that the Jetty server itself will log using Logback, using the Logback configuration found in `{$jetty.base}/resources/logback.xml`. -Log files will be stored in `${jetty.base}/logs`. ==== Logging with Java Util Logging @@ -395,8 +390,7 @@ Log files will be stored in `${jetty.base}/logs`. ===== Java Util Logging with SLF4J It is possible to have the Jetty Server logging configured so that `java.util.logging` controls the output of logging events produced by Jetty. -This example demonstrates how to configuring Jetty for logging to `java.util.logging` via http://slf4j.org/manual.html[Slf4j] and the http://slf4j.org/manual.html#swapping[Slf4j binding layer for java.util.logging]. -By default, log files will be stored in `${jetty.base}/logs`. +This example demonstrates how to configuring Jetty for logging to `java.util.logging` via http://slf4j.org/manual.html[SLF4J] as a binding layer. [source, screen, subs="{sub-order}"] .... @@ -436,12 +430,10 @@ INFO : slf4j-jul transitively enabled INFO : logging-jul initialized in ${jetty.base}/start.d/logging-jul.ini INFO : resources transitively enabled MKDIR : ${jetty.base}/etc -COPY : ${jetty.home}/modules/jul-impl/java-util-logging.properties to ${jetty.base}/etc/java-util-logging.properties -MKDIR : ${jetty.base}/logs +COPY : ${jetty.home}/modules/jul-impl/etc/java-util-logging.properties to ${jetty.base}/etc/java-util-logging.properties MKDIR : ${jetty.base}/lib/slf4j -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-jdk14/1.7.21/slf4j-jdk14-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-jdk14-1.7.21.jar -MKDIR : ${jetty.base}/resources +DOWNLD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar +DOWNLD: http://central.maven.org/maven2/org/slf4j/slf4j-jdk14/1.7.21/slf4j-jdk14-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-jdk14-1.7.21.jar INFO : Base directory was modified [my-base]$ tree @@ -452,76 +444,49 @@ INFO : Base directory was modified │   └── slf4j │   ├── slf4j-api-1.7.21.jar │   └── slf4j-jdk14-1.7.21.jar -├── logs -├── resources └── start.d └── logging-jul.ini .... -[[example-logging-java-commons-logging]] -==== Logging with Java Commons Logging -Jetty provides support of the Java Commons Logging (jcl) through the `logging-jcl` module, using Slf4j as a binding. -This is enabled by activating the `logging-jcl` module. -By default, log files will be stored in `${jetty.base}/logs`. +Jetty is now configured to log using the JUL framework. +A standard JUL properties file is located in `${jetty.base}/etc/java-util-logging.properties`. + +==== Capturing Console Output + +By default, enabling the above modules will output log information to the console. +Included in the distribution is the `console-capture` module, which can be used in lieu of additional configuration to the selected logging module to capture this output to a `logs` directory in your `${jetty.base}`. +To enable this functionality, activate the `console-capture` module. [source, screen, subs="{sub-order}"] .... -[my-base]$ java -jar ../start.jar --add-to-start=logging-jcl - -ALERT: There are enabled module(s) with licenses. -The following 2 module(s): - + contains software not provided by the Eclipse Foundation! - + contains software not covered by the Eclipse Public License! - + has not been audited for compliance with its license - - Module: jcl-impl - + Log4j is released under the Apache 2.0 license. - + http://www.apache.org/licenses/LICENSE-2.0.html - - Module: slf4j-api - + SLF4J is distributed under the MIT License. - + Copyright (c) 2004-2013 QOS.ch - + All rights reserved. - + Permission is hereby granted, free of charge, to any person obtaining - + a copy of this software and associated documentation files (the - + "Software"), to deal in the Software without restriction, including - + without limitation the rights to use, copy, modify, merge, publish, - + distribute, sublicense, and/or sell copies of the Software, and to - + permit persons to whom the Software is furnished to do so, subject to - + the following conditions: - + The above copyright notice and this permission notice shall be - + included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Proceed (y/N)? y -INFO : slf4j-api transitively enabled -INFO : jcl-impl transitively enabled -INFO : resources transitively enabled -INFO : slf4j-jcl transitively enabled -INFO : logging-jcl initialized in ${jetty.base}/start.d/logging-jcl.ini -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-api-1.7.21.jar -DOWNLOAD: http://central.maven.org/maven2/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar to ${jetty.base}/lib/jcl/commons-logging-1.1.3.jar -MKDIR: ${jetty.base}/logs -DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-jcl/1.7.21/slf4j-jcl-1.7.21.jar to ${jetty.base}/lib/slf4j/slf4j-jcl-1.7.21.jar -INFO : Base directory was modified +[my-base]$ java -jar ../start.jar --add-to-start=console-capture +INFO : console-capture initialized in ${jetty.base}/start.d/console-capture.ini +MKDIR : ${jetty.base}/logs +INFO : Base directory was modified [my-base]$ tree . -├── lib -│   ├── jcl -│   │   └── commons-logging-1.1.3.jar -│   └── slf4j -│   ├── slf4j-api-1.7.21.jar -│   └── slf4j-jcl-1.7.21.jar ├── logs -├── resources -│   └── commons-logging.properties └── start.d - └── logging-jcl.ini + └── console-capture.ini +.... + +As an example, here is the output from Logback before using the `console-capture` module: + +[source, screen, subs="{sub-order}"] +.... +[my-base]$ java -jar ../start.jar +419 [main] INFO org.eclipse.jetty.util.log - Logging initialized @508ms to org.eclipse.jetty.util.log.Slf4jLog +540 [main] INFO org.eclipse.jetty.server.Server - jetty-9.4.0-SNAPSHOT +575 [main] INFO o.e.jetty.server.AbstractConnector - Started ServerConnector@3c0ecd4b{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} +575 [main] INFO org.eclipse.jetty.server.Server - Started @668ms +.... + +After enabling `console-capture`, the output is as follows, which displays the location the log is being saved to: + +[source, screen, subs="{sub-order}"] +.... +[my-base]$ java -jar ../start.jar +151 [main] INFO org.eclipse.jetty.util.log - Logging initialized @238ms to org.eclipse.jetty.util.log.Slf4jLog +196 [main] INFO org.eclipse.jetty.util.log - Console stderr/stdout captured to /installs/jetty-distribution/mybase/logs/2016_10_21.jetty.log .... diff --git a/jetty-documentation/src/main/asciidoc/administration/logging/default-logging-with-stderrlog.adoc b/jetty-documentation/src/main/asciidoc/administration/logging/default-logging-with-stderrlog.adoc index a5af4795221..a750f94a66c 100644 --- a/jetty-documentation/src/main/asciidoc/administration/logging/default-logging-with-stderrlog.adoc +++ b/jetty-documentation/src/main/asciidoc/administration/logging/default-logging-with-stderrlog.adoc @@ -23,21 +23,39 @@ If you do nothing to configure a separate logging framework, Jetty will default to using an internal `org.eclipse.jetty.util.log.StdErrLog` implementation. This will output all logging events to STDERR (aka `System.err`). -Simply use Jetty and `StdErrLog` based logging is output to the console. +Simply use Jetty and `StdErrLog`-based logging is output to the console. -Included in the Jetty distribution is a logging module that is capable of performing simple capturing of all STDOUT (`System.out`) and STDERR (`System.err`) output to a file that is rotated daily. +Included in the Jetty distribution is a logging module named `console-capture` that is capable of performing simple capturing of all STDOUT (`System.out`) and STDERR (`System.err`) output to a file that is rotated daily. -To enable on this feature via the command line: +To enable this feature, simply activate the `console-capture` module on the command line: + +[source, screen, subs="{sub-order}"] +.... +[my-base]$ java -jar ../start.jar --add-to-start=console-capture +INFO : console-capture initialized in ${jetty.base}/start.d/console-capture.ini +MKDIR : ${jetty.base}/logs +INFO : Base directory was modified + +[my-base]$ tree +. +├── logs +└── start.d + └── console-capture.ini +.... + +The default configuration for logging output will create a file `${jetty.base}/logs/yyyy_mm_dd.stderrout.log` which allows configuration of the output directory by setting the `jetty.logs` property. + +Just enabling the `console-capture` will simply output the values of STDERR and STDOUT to a log file. +To customize the log further, a module named `logging-jetty` is available to provides a default properties file to configure. +As with `console-capture`, you activate the `logging-jetty` on the command line. [source, screen, subs="{sub-order}"] .... [my-base]$ java -jar ../start.jar --add-to-start=logging-jetty INFO : logging-jetty initialized in ${jetty.base}/start.d/logging-jetty.ini -INFO : console-capture transitively enabled, ini template available with --add-to-start=console-capture INFO : resources transitively enabled MKDIR : ${jetty.base}/resources -COPY : ${jetty.home}/modules/logging-jetty/jetty-logging.properties to ${jetty.base}/resources/jetty-logging.properties -MKDIR : ${jetty.base}/logs +COPY : ${jetty.home}/modules/logging-jetty/resources/jetty-logging.properties to ${jetty.base}/resources/jetty-logging.properties INFO : Base directory was modified [my-base]$ tree @@ -46,26 +64,31 @@ INFO : Base directory was modified ├── resources │   └── jetty-logging.properties └── start.d + ├── console-capture.ini └── logging-jetty.ini .... -The default configuration for logging output will create a file `${jetty.base}/logs/yyyy_mm_dd.stderrout.log` which allows configuration of the output directory by setting the `jetty.logs` property. - -For more advanced logging configurations, please consider use of a separate logging library. - -The recommended way to configure `StdErrLog` is to create a `${jetty.base}/resources/jetty-logging.properties` file, specify the log implementation to `StdErrLog` and then setup logging levels. +Once activated, you can find the properties file at `${jetty.base}/resources/jetty-logging.properties`. +By default, the following parameters are defined. +To change them, un-comment the line and substitute your naming scheme and configuration choices. [source, properties, subs="{sub-order}"] .... -# Configure Jetty for StdErrLog Logging -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StrErrLog -# Overall Logging Level is INFO -org.eclipse.jetty.LEVEL=INFO -# Detail Logging for WebSocket -org.eclipse.jetty.websocket.LEVEL=DEBUG +## Force jetty logging implementation +#org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog + +## Set logging levels from: ALL, DEBUG, INFO, WARN, OFF +#org.eclipse.jetty.LEVEL=INFO +#com.example.LEVEL=INFO + +## Hide stacks traces in logs? +#com.example.STACKS=false + +## Show the source file of a log location? +#com.example.SOURCE=false .... -There are a number of properties that can be defined in the configuration that will affect the behavior of `StdErrLog`. +There are a number of properties that can be defined in the configuration that will affect the behavior of StdErr logging with `console-capture`. `.LEVEL=`:: Sets the logging level for all loggers within the `name` specified to the level, which can be (in increasing order of restriction) `ALL`, `DEBUG`, `INFO`, `WARN`, `OFF`. @@ -95,22 +118,20 @@ There are a number of properties that can be defined in the configuration that w + [source, screen, subs="{sub-order}"] .... -2014-06-03 14:36:16.013:INFO:oejs.Server:main: jetty-9.2.0.v20140526 -2014-06-03 14:36:16.028:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/opt/jetty/demo-base/webapps/] at interval 1 -2014-06-03 14:36:16.051:INFO:oejsh.ContextHandler:main: Started o.e.j.s.h.MovedContextHandler@7d256e50{/oldContextPath,null,AVAILABLE} -2014-06-03 14:36:17.880:INFO:oejs.ServerConnector:main: Started ServerConnector@34f2d11a{HTTP/1.1}{0.0.0.0:8080} -2014-06-03 14:36:17.888:INFO:oejs.Server:main: Started @257ms +2016-10-21 15:31:01.248:INFO::main: Logging initialized @332ms to org.eclipse.jetty.util.log.StdErrLog +2016-10-21 15:31:01.370:INFO:oejs.Server:main: jetty-9.4.0-SNAPSHOT +2016-10-21 15:31:01.400:INFO:oejs.AbstractConnector:main: Started ServerConnector@2c330fbc{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} +2016-10-21 15:31:01.400:INFO:oejs.Server:main: Started @485ms .... + * Example when set to true: + [source, screen, subs="{sub-order}"] .... -2014-06-03 14:38:19.019:INFO:org.eclipse.jetty.server.Server:main: jetty-9.2.0.v20140526 -2014-06-03 14:38:19.032:INFO:org.eclipse.jetty.deploy.providers.ScanningAppProvider:main: Deployment monitor [file:/opt/jetty/demo-base/webapps/] at interval 1 -2014-06-03 14:38:19.054:INFO:org.eclipse.jetty.server.handler.ContextHandler:main: Started o.e.j.s.h.MovedContextHandler@246d8660{/oldContextPath,null,AVAILABLE} -2014-06-03 14:38:20.715:INFO:org.eclipse.jetty.server.ServerConnector:main: Started ServerConnector@59f625be{HTTP/1.1}{0.0.0.0:8080} -2014-06-03 14:38:20.723:INFO:org.eclipse.jetty.server.Server:main: Started @243ms +2016-10-21 15:31:35.020:INFO::main: Logging initialized @340ms to org.eclipse.jetty.util.log.StdErrLog +2016-10-21 15:31:35.144:INFO:org.eclipse.jetty.server.Server:main: jetty-9.4.0-SNAPSHOT +2016-10-21 15:31:35.174:INFO:org.eclipse.jetty.server.AbstractConnector:main: Started ServerConnector@edf4efb{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} +2016-10-21 15:31:35.175:INFO:org.eclipse.jetty.server.Server:main: Started @495ms .... [[deprecated-parameters]] diff --git a/jetty-documentation/src/main/asciidoc/administration/logging/example-logback-centralized-logging.adoc b/jetty-documentation/src/main/asciidoc/administration/logging/example-logback-centralized-logging.adoc index 2c4600b2c69..27b0a0874d3 100644 --- a/jetty-documentation/src/main/asciidoc/administration/logging/example-logback-centralized-logging.adoc +++ b/jetty-documentation/src/main/asciidoc/administration/logging/example-logback-centralized-logging.adoc @@ -15,9 +15,9 @@ // ======================================================================== [[example-logging-logback-centralized]] -=== Example: Centralized Logging with Logback +=== Centralized Logging using Logback -The term _Centralized Logging_ refers to a forced logging configuration for the Jetty Server and all web applications that are deployed on the server. +The term _Centralized Logging_ refers to a forced logging configuration for the Jetty Server and all web applications that are deployed on the server. It routes all logging events from the web applications to a single configuration on the Server side. The example below shows how to accomplish this with Jetty and Slf4j, using `Logback` to manage the final writing of logs to disk. @@ -30,7 +30,7 @@ ____ This configuration is essentially the multiple logger configuration with added configuration to the deployers to force a `WebAppClassLoader` change to use the server classpath over the webapps classpath for the logger specific classes. -The technique used by this configuration is to provide an link:{JDURL}org/eclipse/jetty/deploy/AppLifeCycle.Binding.html[AppLifeCycle.Binding] against the link:{JDURL}/org/eclipse/jetty/deploy/AppLifeCycle.html[`"deploying"`node] that modifies the link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#addSystemClass(java.lang.String)[WebAppContext.addSystemClass(String)] for the common logging classes. +The technique used by this configuration is to provide an link:{JDURL}org/eclipse/jetty/deploy/AppLifeCycle.Binding.html[AppLifeCycle.Binding] against the link:{JDURL}/org/eclipse/jetty/deploy/AppLifeCycle.html[`"deploying"`node] that modifies the link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#addSystemClass(java.lang.String)[WebAppContext.addSystemClass(String)] for the common logging classes. See https://github.com/jetty-project/jetty-webapp-logging/blob/master/src/main/java/org/eclipse/jetty/webapp/logging/CentralizedWebAppLoggingBinding.java[org.eclipse.jetty.logging.CentralizedWebAppLoggingBinding] for actual implementation. A convenient replacement `logging` module has been created to bootstrap your `${jetty.base}` directory for capturing all Jetty server logging from multiple logging frameworks into a single logging output file managed by Logback. From 33eb768d6972fe67b5058c96941645cb03fea6e7 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 25 Oct 2016 15:44:54 +0200 Subject: [PATCH 5/5] Fixes #1029 - Restore Request.setHttpVersion(). Also cleaned up the asymmetry in MetaData between the setter (setHttpVersion()) and the getter (getVersion()). --- .../org/eclipse/jetty/http/HttpGenerator.java | 16 ++-- .../java/org/eclipse/jetty/http/MetaData.java | 17 +++- .../eclipse/jetty/http2/hpack/HpackTest.java | 10 +-- .../client/http/HttpReceiverOverHTTP2.java | 2 +- .../http2/server/HttpChannelOverHTTP2.java | 6 +- .../org/eclipse/jetty/server/HttpChannel.java | 4 +- .../jetty/server/HttpChannelOverHttp.java | 6 +- .../org/eclipse/jetty/server/Request.java | 12 ++- .../server/HttpVersionCustomizerTest.java | 81 +++++++++++++++++++ 9 files changed, 125 insertions(+), 29 deletions(-) create mode 100644 jetty-server/src/test/java/org/eclipse/jetty/server/HttpVersionCustomizerTest.java diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java index b03133a96b4..0e5047c1066 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java @@ -214,7 +214,7 @@ public class HttpGenerator // If we have not been told our persistence, set the default if (_persistent==null) { - _persistent=info.getVersion().ordinal() > HttpVersion.HTTP_1_0.ordinal(); + _persistent=info.getHttpVersion().ordinal() > HttpVersion.HTTP_1_0.ordinal(); if (!_persistent && HttpMethod.CONNECT.is(info.getMethod())) _persistent=true; } @@ -226,7 +226,7 @@ public class HttpGenerator // generate ResponseLine generateRequestLine(info,header); - if (info.getVersion()==HttpVersion.HTTP_0_9) + if (info.getHttpVersion()==HttpVersion.HTTP_0_9) throw new BadMessageException(500,"HTTP/0.9 not supported"); generateHeaders(info,header,content,last); @@ -342,7 +342,7 @@ public class HttpGenerator { if (info==null) return Result.NEED_INFO; - HttpVersion version=info.getVersion(); + HttpVersion version=info.getHttpVersion(); if (version==null) throw new BadMessageException(500,"No version"); switch(version) @@ -523,7 +523,7 @@ public class HttpGenerator header.put((byte)' '); header.put(StringUtil.getBytes(request.getURIString())); header.put((byte)' '); - header.put(request.getVersion().toBytes()); + header.put(request.getHttpVersion().toBytes()); header.put(HttpTokens.CRLF); } @@ -628,7 +628,7 @@ public class HttpGenerator case TRANSFER_ENCODING: { - if (_info.getVersion() == HttpVersion.HTTP_1_1) + if (_info.getHttpVersion() == HttpVersion.HTTP_1_1) transfer_encoding = field; // Do NOT add yet! break; @@ -682,7 +682,7 @@ public class HttpGenerator case KEEP_ALIVE: { - if (_info.getVersion() == HttpVersion.HTTP_1_0) + if (_info.getHttpVersion() == HttpVersion.HTTP_1_0) { keep_alive = true; if (response!=null) @@ -774,7 +774,7 @@ public class HttpGenerator // For a request with HTTP 1.0 & Connection: keep-alive // we *must* close the connection, otherwise the client // has no way to detect the end of the content. - if (!isPersistent() || _info.getVersion().ordinal() < HttpVersion.HTTP_1_1.ordinal()) + if (!isPersistent() || _info.getHttpVersion().ordinal() < HttpVersion.HTTP_1_1.ordinal()) _endOfContent = EndOfContent.EOF_CONTENT; } break; @@ -825,7 +825,7 @@ public class HttpGenerator // If this is a response, work out persistence if (response!=null) { - if (!isPersistent() && (close || _info.getVersion().ordinal() > HttpVersion.HTTP_1_0.ordinal())) + if (!isPersistent() && (close || _info.getHttpVersion().ordinal() > HttpVersion.HTTP_1_0.ordinal())) { if (connection==null) header.put(CONNECTION_CLOSE); diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java b/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java index 725870db92b..9f683503d0d 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java @@ -57,10 +57,19 @@ public class MetaData implements Iterable return false; } + /** + * @deprecated use {@link #getHttpVersion()} instead + */ + @Deprecated + public HttpVersion getVersion() + { + return getHttpVersion(); + } + /** * @return the HTTP version of this MetaData object */ - public HttpVersion getVersion() + public HttpVersion getHttpVersion() { return _httpVersion; } @@ -155,7 +164,7 @@ public class MetaData implements Iterable public Request(Request request) { - this(request.getMethod(),new HttpURI(request.getURI()), request.getVersion(), new HttpFields(request.getFields()), request.getContentLength()); + this(request.getMethod(),new HttpURI(request.getURI()), request.getHttpVersion(), new HttpFields(request.getFields()), request.getContentLength()); } // TODO MetaData should be immuttable!!! @@ -218,7 +227,7 @@ public class MetaData implements Iterable { HttpFields fields = getFields(); return String.format("%s{u=%s,%s,h=%d}", - getMethod(), getURI(), getVersion(), fields == null ? -1 : fields.size()); + getMethod(), getURI(), getHttpVersion(), fields == null ? -1 : fields.size()); } } @@ -292,7 +301,7 @@ public class MetaData implements Iterable public String toString() { HttpFields fields = getFields(); - return String.format("%s{s=%d,h=%d}", getVersion(), getStatus(), fields == null ? -1 : fields.size()); + return String.format("%s{s=%d,h=%d}", getHttpVersion(), getStatus(), fields == null ? -1 : fields.size()); } } } diff --git a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java index fce577bbb57..353396d48c0 100644 --- a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java +++ b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java @@ -18,10 +18,6 @@ package org.eclipse.jetty.http2.hpack; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - import java.nio.ByteBuffer; import org.eclipse.jetty.http.BadMessageException; @@ -38,6 +34,10 @@ import org.eclipse.jetty.util.BufferUtil; import org.junit.Assert; import org.junit.Test; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + public class HpackTest { final static HttpField ServerJetty = new PreEncodedHttpField(HttpHeader.SERVER,"jetty"); @@ -187,7 +187,7 @@ public class HpackTest private void assertMetadataSame(MetaData expected, MetaData actual) { assertThat("Metadata.contentLength",actual.getContentLength(),is(expected.getContentLength())); - assertThat("Metadata.version" + ".version", actual.getVersion(), is(expected.getVersion())); + assertThat("Metadata.version" + ".version", actual.getHttpVersion(),is(expected.getHttpVersion())); assertHttpFieldsSame("Metadata.fields",expected.getFields(),actual.getFields()); } diff --git a/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpReceiverOverHTTP2.java b/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpReceiverOverHTTP2.java index f95c09d429f..be8296a615f 100644 --- a/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpReceiverOverHTTP2.java +++ b/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpReceiverOverHTTP2.java @@ -67,7 +67,7 @@ public class HttpReceiverOverHTTP2 extends HttpReceiver implements Stream.Listen HttpResponse response = exchange.getResponse(); MetaData.Response metaData = (MetaData.Response)frame.getMetaData(); - response.version(metaData.getVersion()).status(metaData.getStatus()).reason(metaData.getReason()); + response.version(metaData.getHttpVersion()).status(metaData.getStatus()).reason(metaData.getReason()); if (responseBegin(exchange)) { diff --git a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpChannelOverHTTP2.java b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpChannelOverHTTP2.java index 02ba47cf825..7d6558a333e 100644 --- a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpChannelOverHTTP2.java +++ b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpChannelOverHTTP2.java @@ -126,7 +126,7 @@ public class HttpChannelOverHTTP2 extends HttpChannel LOG.debug("HTTP2 Request #{}/{}, delayed={}:{}{} {} {}{}{}", stream.getId(), Integer.toHexString(stream.getSession().hashCode()), _delayedUntilContent, System.lineSeparator(), - request.getMethod(), request.getURI(), request.getVersion(), + request.getMethod(), request.getURI(), request.getHttpVersion(), System.lineSeparator(), fields); } @@ -157,7 +157,7 @@ public class HttpChannelOverHTTP2 extends HttpChannel Stream stream = getStream(); LOG.debug("HTTP2 PUSH Request #{}/{}:{}{} {} {}{}{}", stream.getId(), Integer.toHexString(stream.getSession().hashCode()), System.lineSeparator(), - request.getMethod(), request.getURI(), request.getVersion(), + request.getMethod(), request.getURI(), request.getHttpVersion(), System.lineSeparator(), request.getFields()); } @@ -199,7 +199,7 @@ public class HttpChannelOverHTTP2 extends HttpChannel { Stream stream = getStream(); LOG.debug("HTTP2 Commit Response #{}/{}:{}{} {} {}{}{}", - stream.getId(), Integer.toHexString(stream.getSession().hashCode()), System.lineSeparator(), info.getVersion(), info.getStatus(), info.getReason(), + stream.getId(), Integer.toHexString(stream.getSession().hashCode()), System.lineSeparator(), info.getHttpVersion(), info.getStatus(), info.getReason(), System.lineSeparator(), info.getFields()); } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java index 88b61a5e0aa..9c1e297fdb1 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java @@ -606,7 +606,7 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor if (LOG.isDebugEnabled()) LOG.debug("REQUEST for {} on {}{}{} {} {}{}{}",request.getURIString(),this,System.lineSeparator(), - request.getMethod(),request.getURIString(),request.getVersion(),System.lineSeparator(), + request.getMethod(),request.getURIString(),request.getHttpVersion(),System.lineSeparator(), request.getFields()); } @@ -752,7 +752,7 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor _committedMetaData=info; if (LOG.isDebugEnabled()) LOG.debug("COMMIT for {} on {}{}{} {} {}{}{}",getRequest().getRequestURI(),this,System.lineSeparator(), - info.getStatus(),info.getReason(),info.getVersion(),System.lineSeparator(), + info.getStatus(),info.getReason(),info.getHttpVersion(),System.lineSeparator(), info.getFields()); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java index 6668678874c..33e63508176 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java @@ -136,7 +136,7 @@ public class HttpChannelOverHttp extends HttpChannel implements HttpParser.Reque case EXPECT: { - if (_metadata.getVersion() == HttpVersion.HTTP_1_1) + if (_metadata.getHttpVersion() == HttpVersion.HTTP_1_1) { HttpHeaderValue expect = HttpHeaderValue.CACHE.get(value); switch (expect == null ? HttpHeaderValue.UNKNOWN : expect) @@ -266,7 +266,7 @@ public class HttpChannelOverHttp extends HttpChannel implements HttpParser.Reque boolean persistent; - switch (_metadata.getVersion()) + switch (_metadata.getHttpVersion()) { case HTTP_0_9: { @@ -350,7 +350,7 @@ public class HttpChannelOverHttp extends HttpChannel implements HttpParser.Reque default: { - throw new IllegalStateException("unsupported version " + _metadata.getVersion()); + throw new IllegalStateException("unsupported version " + _metadata.getHttpVersion()); } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index 05492304feb..8f64c3c5074 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -80,7 +80,6 @@ import org.eclipse.jetty.server.handler.ContextHandler.Context; import org.eclipse.jetty.server.session.AbstractSession; import org.eclipse.jetty.util.Attributes; import org.eclipse.jetty.util.AttributesMap; -import org.eclipse.jetty.util.HostPort; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.MultiMap; import org.eclipse.jetty.util.MultiPartInputStreamParser; @@ -1086,7 +1085,7 @@ public class Request implements HttpServletRequest MetaData.Request metadata = _metaData; if (metadata==null) return null; - HttpVersion version = metadata.getVersion(); + HttpVersion version = metadata.getHttpVersion(); if (version==null) return null; return version.toString(); @@ -1099,7 +1098,7 @@ public class Request implements HttpServletRequest public HttpVersion getHttpVersion() { MetaData.Request metadata = _metaData; - return metadata==null?null:metadata.getVersion(); + return metadata==null?null:metadata.getHttpVersion(); } /* ------------------------------------------------------------ */ @@ -2066,6 +2065,13 @@ public class Request implements HttpServletRequest metadata.setMethod(method); } + public void setHttpVersion(HttpVersion version) + { + MetaData.Request metadata = _metaData; + if (metadata!=null) + metadata.setHttpVersion(version); + } + /* ------------------------------------------------------------ */ public boolean isHead() { diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpVersionCustomizerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpVersionCustomizerTest.java new file mode 100644 index 00000000000..819354879f0 --- /dev/null +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpVersionCustomizerTest.java @@ -0,0 +1,81 @@ +// +// ======================================================================== +// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.server; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.channels.SocketChannel; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.jetty.http.HttpStatus; +import org.eclipse.jetty.http.HttpTester; +import org.eclipse.jetty.http.HttpVersion; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.eclipse.jetty.toolchain.test.TestTracker; +import org.hamcrest.Matchers; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +public class HttpVersionCustomizerTest +{ + @Rule + public TestTracker tracker = new TestTracker(); + + @Test + public void testCustomizeHttpVersion() throws Exception + { + Server server = new Server(); + HttpConfiguration httpConfig = new HttpConfiguration(); + httpConfig.addCustomizer((connector, config, request) -> request.setHttpVersion(HttpVersion.HTTP_1_1)); + ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(httpConfig)); + server.addConnector(connector); + server.setHandler(new AbstractHandler() + { + @Override + public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + { + baseRequest.setHandled(true); + Assert.assertEquals(HttpVersion.HTTP_1_1.asString(), request.getProtocol()); + } + }); + server.start(); + + try + { + try (SocketChannel socket = SocketChannel.open(new InetSocketAddress("localhost", connector.getLocalPort()))) + { + HttpTester.Request request = HttpTester.newRequest(); + request.setVersion(HttpVersion.HTTP_1_0); + socket.write(request.generate()); + + HttpTester.Response response = HttpTester.parseResponse(HttpTester.from(socket)); + Assert.assertNotNull(response); + Assert.assertThat(response.getStatus(), Matchers.equalTo(HttpStatus.OK_200)); + } + } + finally + { + server.stop(); + } + } +}