blob: 4c5c7743c9711f1ce87da92b1187121d51fa0c30 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Jetty Logging Integrations (SLF4J, Log4j, Logback, JCL, JUL)</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty"><link rel="up" href="configuring-logging.html" title="Chapter&nbsp;11.&nbsp;Jetty Logging"><link rel="prev" href="configuring-jetty-request-logs.html" title="Configuring Jetty Request Logs"><link rel="next" href="example-logging-logback-centralized.html" title="Centralized Logging using Logback"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><link rel="stylesheet" href="css/highlighter/foundation.css"><script src="js/highlight.pack.js"></script><script>
hljs.initHighlightingOnLoad();
</script><link type="text/css" rel="stylesheet" href="css/font-awesome/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small">
Version: 9.4.28-SNAPSHOT</span></td><td style="width: 50%"></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Jetty Logging Integrations (SLF4J, Log4j, Logback, JCL, JUL)</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="configuring-jetty-request-logs.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;11.&nbsp;Jetty Logging<br><a accesskey="p" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="example-logging-logback-centralized.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at
<span class="website">www.webtide.com</span></a></h5><p>
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
</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="configuring-logging-modules"></a>Jetty Logging Integrations (SLF4J, Log4j, Logback, JCL, JUL)</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="configuring-logging-modules.html#example-logging-slf4j">Logging with SLF4J</a></span></dt><dt><span class="section"><a href="configuring-logging-modules.html#example-logging-log4j">Logging with Log4j and Log4j2</a></span></dt><dt><span class="section"><a href="configuring-logging-modules.html#example-logging-logback">Logging with Logback</a></span></dt><dt><span class="section"><a href="configuring-logging-modules.html#_logging_with_java_util_logging">Logging with Java Util Logging</a></span></dt><dt><span class="section"><a href="configuring-logging-modules.html#_capturing_console_output">Capturing Console Output</a></span></dt></dl></div><p>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; <a class="link" href="configuring-jetty-request-logs.html" title="Configuring Jetty Request Logs">request logs</a> 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 <a class="link" href="startup-modules.html" title="Managing Startup Modules">own modules</a> or additional configuration.</p><p>Enabling these frameworks in the Jetty distribution is as easy as activating any other module, by adding <code class="literal">--add-to-start=&lt;module name&gt;</code> to the start command for your server, such as:</p><div class="screenexample"><pre class="screen">[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 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</pre></div><p>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.</p><p>A list of the base Jetty logging modules by running <code class="literal">java -jar &lt;path-to-jetty.home&gt;/start.jar --list-modules=logging,-internal</code>.</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">logging-jcl</span></dt><dd>Configures Jetty logging to use Java Commons Logging (JCL), using SLF4J as a binding.</dd><dt><span class="term">logging-jetty</span></dt><dd>Standard Jetty logging that captures <code class="literal">System.err</code> and <code class="literal">System.out</code> output.</dd><dt><span class="term">logging-jul</span></dt><dd>Configures Jetty logging to use Java Util Logging (JUL), using SLF4J as a binding.</dd><dt><span class="term">logging-log4j</span></dt><dd>Configures Jetty logging to use Log4j as the logging implementation, using SLF4J as a binding.</dd><dt><span class="term">logging-log4j2</span></dt><dd>Configures Jetty logging to use Log4j2 as the logging implementation, using SLF4J as a binding.</dd><dt><span class="term">logging-logback</span></dt><dd>Configures Jetty logging to use Logback as the logging implementation, using SLF4J as a binding.</dd><dt><span class="term">logging-slf4j</span></dt><dd>Configures Jetty logging to use SLF4J and provides a <code class="literal">slf4j-impl</code> which can be used by other logging frameworks.
If no other logging is configured, <code class="literal">slf4j-simple</code> is used.</dd></dl></div><p>You can view a list of <span class="strong"><strong>all</strong></span> the Jetty logging modules by running <code class="literal">java -jar &lt;path-to-jetty.home&gt;/start.jar --list-modules=logging</code>.
This will display all logging modules, including implementation and binding modules.</p><p>All these modules (with the exception of <code class="literal">logging-jetty</code>) arrange for the Jetty private logging API to be routed to the named technology to actually be logged.
For example, enabling the <code class="literal">logging-log4j</code> module will do several things:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">it enables an internal Log4j API module so that any container code that uses Log4j will find the API.</li><li class="listitem">it enables an internal Log4j Implementation so that any container code that uses the Log4j API will also use a Log4j implementation to handle the logs (and all the normal Log4j configuration mechanisms etc.)</li><li class="listitem">it enables the internal <code class="literal">slf4j-log4j</code> logging binding so that any container code that uses the SLF4j API to also use the Log4j implementation via the Log4j API.</li><li class="listitem">it configures the Jetty logging API to use the SLF4J API, which is then bound to Log4j.</li></ul></div><p>So, after enabling <code class="literal">logging-log4j</code>, within the server container there are 3 logging APIs available: Jetty, SLF4J and Log4J.
But there is only a single logging <span class="strong"><strong>implementation</strong></span> - Log4j; the 3 APIs act only as facades over the Log4j implementation.</p><p>Note that you can add additional APIs to this configuration.
For example, enabling the internal module <code class="literal">jcl-slf4j</code> would add in a Java Commons Logging facade that also would use the Log4j implementation via the SLF4J binding.</p><p>Most other top level logging modules work in the same way: <code class="literal">logging-jcl</code>, <code class="literal">logging-jul</code>, <code class="literal">logging-slf4j</code>, <code class="literal">logging-log4j2</code> and <code class="literal">logging-logback</code> all bind their implementation via SLF4J.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="example-logging-slf4j"></a>Logging with SLF4J</h3></div></div></div><p>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&#8217;s own to provide simple server logging.
To enable the SLF4J framework, you need to activate the <code class="literal">logging-slf4j</code> module.</p><div class="screenexample"><pre class="screen">[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
DOWNLD: https://repo1.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 module providing slf4j-impl from one of [slf4j-simple-impl, slf4j-logback, slf4j-jul, 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</pre></div><p>As you probably noticed, the system gives an <code class="literal">ERROR</code> when trying to enable the <code class="literal">logging-slf4j</code> on it&#8217;s own.
The <code class="literal">logging-slf4j</code> 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 <code class="literal">slf4j-simple-impl</code> module.</p><div class="screenexample"><pre class="screen">[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
DOWNLD: https://repo1.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-simple-impl/resources/simplelogger.properties to ${jetty.base}/resources/simplelogger.properties
INFO : Base directory was modified
[my-base]$ tree
.
&#9500;&#9472;&#9472; lib
&#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; slf4j
&#9474;&nbsp;&nbsp; &#9500;&#9472;&#9472; slf4j-api-1.7.21.jar
&#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; slf4j-simple-1.7.21.jar
&#9500;&#9472;&#9472; resources
&#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; simplelogger.properties
&#9492;&#9472;&#9472; start.d
&#9500;&#9472;&#9472; logging-slf4j.ini
&#9492;&#9472;&#9472; slf4j-simple-impl.ini</pre></div><p>Jetty is now configured to log using the SLF4J framework.
A standard SLF4J properties file is located in <code class="literal">${jetty.base}/resources/simplelogger.properties</code>.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="example-logging-log4j"></a>Logging with Log4j and Log4j2</h3></div></div></div><p>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 <a class="link" href="http://logging.apache.org/log4j/" target="_top">Apache Log4j</a> via <a class="link" href="http://slf4j.org/manual.html" target="_top">Slf4j</a> and the <a class="link" href="http://slf4j.org/manual.html#swapping" target="_top">Slf4j binding layer for Log4j</a>.
Implementation of Log4j can be done by enabling the <code class="literal">logging-log4j</code> module.</p><div class="screenexample"><pre class="screen">[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
DOWNLD: https://repo1.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
COPY : /Users/admin/.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: https://repo1.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
.
&#9500;&#9472;&#9472; lib
&#9474;&nbsp;&nbsp; &#9500;&#9472;&#9472; log4j
&#9474;&nbsp;&nbsp; &#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; log4j-1.2.17.jar
&#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; slf4j
&#9474;&nbsp;&nbsp; &#9500;&#9472;&#9472; slf4j-api-1.7.21.jar
&#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; slf4j-log4j12-1.7.21.jar
&#9500;&#9472;&#9472; resources
&#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; log4j.xml
&#9492;&#9472;&#9472; start.d
&#9492;&#9472;&#9472; logging-log4j.ini</pre></div><p>Jetty is now configured to log using the Log4j framework.
A standard Log4j configuration file is located in <code class="literal">${jetty.base}/resources/log4j.xml</code>.</p><p>Or, to set up Log4j2, enable the <code class="literal">logging-log4j2</code> module.</p><div class="screenexample"><pre class="screen">[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
DOWNLD: https://repo1.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
DOWNLD: https://repo1.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: https://repo1.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: https://repo1.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
.
&#9500;&#9472;&#9472; lib
&#9474;&nbsp;&nbsp; &#9500;&#9472;&#9472; log4j2
&#9474;&nbsp;&nbsp; &#9474;&nbsp;&nbsp; &#9500;&#9472;&#9472; log4j-api-2.6.1.jar
&#9474;&nbsp;&nbsp; &#9474;&nbsp;&nbsp; &#9500;&#9472;&#9472; log4j-core-2.6.1.jar
&#9474;&nbsp;&nbsp; &#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; log4j-slf4j-impl-2.6.1.jar
&#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; slf4j
&#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; slf4j-api-1.7.21.jar
&#9500;&#9472;&#9472; resources
&#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; log4j2.xml
&#9492;&#9472;&#9472; start.d
&#9492;&#9472;&#9472; logging-log4j2.ini</pre></div><p>At this point Jetty is configured so that the Jetty server itself will log using Log4j2, using the Log4j2 configuration found in <code class="literal">{$jetty.base}/resources/log4j2.xml</code>.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="example-logging-logback"></a>Logging with Logback</h3></div></div></div><p>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 <code class="literal">Logback</code>, which uses <a class="link" href="http://slf4j.org/manual.html" target="_top">Slf4j</a> and the <a class="link" href="http://logback.qos.ch/" target="_top">Logback Implementation for Slf4j</a>.</p><p>To set up Jetty logging via Logback, enable the <code class="literal">logging-logback</code> module.</p><div class="screenexample"><pre class="screen">[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
DOWNLD: https://repo1.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
DOWNLD: https://repo1.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-impl/resources/logback.xml to ${jetty.base}/resources/logback.xml
DOWNLD: https://repo1.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
.
&#9500;&#9472;&#9472; lib
&#9474;&nbsp;&nbsp; &#9500;&#9472;&#9472; logback
&#9474;&nbsp;&nbsp; &#9474;&nbsp;&nbsp; &#9500;&#9472;&#9472; logback-classic-1.1.7.jar
&#9474;&nbsp;&nbsp; &#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; logback-core-1.1.7.jar
&#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; slf4j
&#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; slf4j-api-1.7.21.jar
&#9500;&#9472;&#9472; resources
&#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; logback.xml
&#9492;&#9472;&#9472; start.d
&#9492;&#9472;&#9472; logging-logback.ini</pre></div><p>At this point Jetty is configured so that the Jetty server itself will log using Logback, using the Logback configuration found in <code class="literal">{$jetty.base}/resources/logback.xml</code>.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_logging_with_java_util_logging"></a>Logging with Java Util Logging</h3></div></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="example-logging-java-util-logging"></a>Java Util Logging with SLF4J</h4></div></div></div><p>It is possible to have the Jetty Server logging configured so that <code class="literal">java.util.logging</code> controls the output of logging events produced by Jetty.</p><p>This example demonstrates how to configuring Jetty for logging to <code class="literal">java.util.logging</code> via <a class="link" href="http://slf4j.org/manual.html" target="_top">SLF4J</a> as a binding layer.</p><div class="screenexample"><pre class="screen">[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/etc/java-util-logging.properties to ${jetty.base}/etc/java-util-logging.properties
MKDIR : ${jetty.base}/lib/slf4j
DOWNLD: https://repo1.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: https://repo1.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
.
&#9500;&#9472;&#9472; etc
&#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; java-util-logging.properties
&#9500;&#9472;&#9472; lib
&#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; slf4j
&#9474;&nbsp;&nbsp; &#9500;&#9472;&#9472; slf4j-api-1.7.21.jar
&#9474;&nbsp;&nbsp; &#9492;&#9472;&#9472; slf4j-jdk14-1.7.21.jar
&#9492;&#9472;&#9472; start.d
&#9492;&#9472;&#9472; logging-jul.ini</pre></div><p>Jetty is now configured to log using the JUL framework.
A standard JUL properties file is located in <code class="literal">${jetty.base}/etc/java-util-logging.properties</code>.</p></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_capturing_console_output"></a>Capturing Console Output</h3></div></div></div><p>By default, enabling the above modules will output log information to the console.
Included in the distribution is the <code class="literal">console-capture</code> module, which can be used in lieu of additional configuration to the selected logging module to capture this output to a <code class="literal">logs</code> directory in your <code class="literal">${jetty.base}</code>.
To enable this functionality, activate the <code class="literal">console-capture</code> module.</p><div class="screenexample"><pre class="screen">[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
.
&#9500;&#9472;&#9472; logs
&#9492;&#9472;&#9472; start.d
&#9492;&#9472;&#9472; console-capture.ini</pre></div><p>As an example, here is the output from Logback before using the <code class="literal">console-capture</code> module:</p><div class="screenexample"><pre class="screen">[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</pre></div><p>After enabling <code class="literal">console-capture</code>, the output is as follows, which displays the location the log is being saved to:</p><div class="screenexample"><pre class="screen">[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</pre></div></div></div><script type="text/javascript">
SyntaxHighlighter.all()
</script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="configuring-jetty-request-logs.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="configuring-logging.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="example-logging-logback-centralized.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Configuring Jetty Request Logs&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></td><td width="40%" align="right" valign="top">&nbsp;Centralized Logging using Logback</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout">
See an error or something missing?
<span class="callout"><a href="http://github.com/eclipse/jetty.project">Contribute to this documentation at
<span class="website"><i class="fa fa-github" aria-hidden="true"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2020-03-10)</i></span></div></p></body></html>