![]() Version: 9.4.0.RC1 |
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development
Jetty provides support for several logging frameworks including SLF4J, Java Commons Logging (JCL), Java Util Logging (JUL), Log4j (including version 2), and Logback. This page includes examples of how to enable the associated modules for these different frameworks. These modules are designed to capture container/server logs; request logs and application logs need to be configured separately. Please note that enabling these modules provides typical and basic functionality for each framework; advanced implementations may require their own modules or additional configuration.
Enabling these frameworks in the Jetty distribution is as easy as activating any other module, by adding --add-to-start=<module name>
to the start command for your server, such as:
[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
As noted above, Jetty supports a wide array of logging technologies. If a particular logging framework requires additional jar files, Jetty will automatically download these as part of enabling the associated module and any dependent modules will be transitively enabled.
A list of the base Jetty logging modules by running java -jar <path-to-jetty.home>/start.jar --list-modules=logging,-internal
.
System.err
and System.out
output.slf4j-impl
which can be used by other logging frameworks.
If no other logging is configured, slf4j-simple
is used.You can view a list of all the Jetty logging modules by running java -jar <path-to-jetty.home>/start.jar --list-modules=logging
.
This will display all logging modules, including implementation and binding modules.
All these modules (with the exception of logging-jetty
) arrange for the Jetty private logging API to be routed to the named technology to actually be logged.
For example, enabling the logging-log4j
module will do several things:
slf4j-log4j
logging binding so that any container code that uses the SLF4j API to also use the Log4j implementation via the Log4j API.So, after enabling logging-log4j
, within the server container there are 3 logging APIs available: Jetty, SLF4J and Log4J.
But there is only a single logging implementation - Log4j; the 3 APIs act only as facades over the Log4j implementation.
Note that you can add additional APIs to this configuration.
For example, enabling the internal module jcl-slf4j
would add in a Java Commons Logging facade that also would use the Log4j implementation via the SLF4J binding.
Most other top level logging modules work in the same way: logging-jcl
, logging-jul
, logging-slf4j
, logging-log4j2
and logging-logback
all bind their implementation via SLF4J.
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
.
[my-base]$ java -jar ../start.jar --add-to-start=logging-slf4j ALERT: There are enabled module(s) with licenses. The following 1 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: 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 : 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 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 : Unsatisfied module dependencies: logging-slf4j Usage: java -jar $JETTY_HOME/start.jar [options] [properties] [configs] java -jar $JETTY_HOME/start.jar --help # for more information
As you probably noticed, the system gives an ERROR
when trying to enable the logging-slf4j
on it’s own.
The logging-slf4j
module itself provides the SLF4J api, but as SLF4J is often used as a binding for other logging frameworks does not by default provide an implementation.
To enable the simple SLF4J implementation, we will also need to activate the slf4j-simple-impl
module.
[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 MKDIR : ${jetty.base}/resources COPY : ${jetty.home}/modules/slf4j/simplelogger.properties to ${jetty.base}/resources/simplelogger.properties MKDIR : ${jetty.base}/logs INFO : Base directory was modified [my-base]$ tree . ├── lib │ └── slf4j │ ├── slf4j-api-1.7.21.jar │ └── slf4j-simple-1.7.21.jar ├── logs ├── resources │ └── simplelogger.properties └── start.d ├── logging-slf4j.ini └── slf4j-simple-impl.ini
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 Apache Log4j via Slf4j and the 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
.
[my-base]$ java -jar ../start.jar --add-to-start=logging-log4j 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: log4j-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 : log4j-impl transitively enabled 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 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 INFO : Base directory was modified [my-base]$ tree . ├── lib │ ├── log4j │ │ └── log4j-1.2.17.jar │ └── slf4j │ ├── slf4j-api-1.7.21.jar │ └── slf4j-log4j12-1.7.21.jar ├── logs ├── resources │ └── log4j.properties └── 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
.
[my-base]$ java -jar ../start.jar --add-to-start=logging-log4j2 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: log4j2-api + 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 : logging-log4j2 initialized in ${jetty.base}/start.d/logging-log4j2.ini INFO : log4j2-api transitively enabled 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 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 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 │ └── slf4j │ └── slf4j-api-1.7.21.jar ├── logs ├── resources │ └── log4j2.xml └── start.d └── logging-log4j2.ini
It is possible to have the Jetty Server logging configured so that Logback controls the output of logging events produced by Jetty.
This is accomplished by configuring Jetty for logging to Logback
, which uses Slf4j and the 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
.
[my-base]$ java -jar ../start.jar --add-to-start=logging-logback 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: logback-impl + Logback: the reliable, generic, fast and flexible logging framework. + Copyright (C) 1999-2012, QOS.ch. All rights reserved. + This program and the accompanying materials are dual-licensed under + either: + the terms of the Eclipse Public License v1.0 + as published by the Eclipse Foundation: + http://www.eclipse.org/legal/epl-v10.html + or (per the licensee's choosing) under + the terms of the GNU Lesser General Public License version 2.1 + as published by the Free Software Foundation: + http://www.gnu.org/licenses/old-licenses/lgpl-2.1.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 : logback-impl transitively enabled 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 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 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 INFO : Base directory was modified [my-base]$ tree . ├── lib │ ├── logback │ │ ├── logback-classic-1.1.7.jar │ │ └── logback-core-1.1.7.jar │ └── slf4j │ └── slf4j-api-1.7.21.jar ├── logs ├── resources │ └── logback.xml └── start.d └── logging-logback.ini
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
.
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 Slf4j and the Slf4j binding layer for java.util.logging.
By default, log files will be stored in ${jetty.base}/logs
.
[my-base]$ java -jar ../start.jar --add-to-start=logging-jul ALERT: There are enabled module(s) with licenses. The following 1 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: 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 : jul-impl transitively enabled INFO : slf4j-api transitively enabled 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 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 INFO : Base directory was modified [my-base]$ tree . ├── etc │ └── java-util-logging.properties ├── lib │ └── slf4j │ ├── slf4j-api-1.7.21.jar │ └── slf4j-jdk14-1.7.21.jar ├── logs ├── resources └── start.d └── logging-jul.ini
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
.
[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]$ 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