Re: [jetty-user] add external jars to the classpath

Joakim Erdfelt <[email protected]> Sun, 4 Nov 2012 13:52:39 -0700
Newsgroups gmane.comp.java.jetty.support
Message-ID <CAG4zZZAjOBA5x97_ahS2g2cRv7azWJMor0jXLsTS8PqVCaFw=g@mail.gmail.com>
--f46d042ef76baa11dc04cdb18c3f
Content-Type: text/plain; charset=ISO-8859-1

You say "continue logging as JUL", I assume you mean java.util.logging,
right?

You can rely on logback entirely, and setup a sifting logging adapter to
accomplish your end goal of 2 log files, just use the filter
org.eclipse.jetty for jetty.log, and others namespaces to webapp log
adapter.
However you have decided that jetty itself should use java.util.logging.

Note that Slf4J will initalize *very* early in the life of the JVM.  (this
is important to understand)
Easily before Jetty even comes into play.

This will be a delicate configuration, but it might be possible.

The steps.

1) You'll want to configure Jetty's Log impl to be java.util.logging.
You can do that by setting the System Property ...
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.JavaUtilLog

2) Then you'll want to setup the slf4j api + slf4j impl jars in your
${jetty.home}/lib/logging directory (like the blog shows)
There are many slf4j implementation jars.
To have slf4j route to ....
 * Logback, use logback-classic.jar
 * Log4j, use slf4j-log4j12.jar, and log4j.jars
 * Apache Commons Logging, use sfl4j-jcl.jar, commons-logging.jar, and your
commons-logging output implementation. (logging inception!)
 * java.util.logging, use slf4j-jdk14.jar

3) Then you'll want to configure your chosen logging framework in the
mechanism best documented for that framework.

4) Grab the etc/jetty-webapp-logging.xml configuration (and jar files)
outlined in the blog.
This will configure the deployed webapp to use the server side slf4j jars,
and not the ones in the webapp itself.
Essentially, this is a tweak the WebApp's ClassLoader to force the server
side on the webapp.

5) Setup the etc/jetty-webapp-logging.xml in the start.ini (as outlined in
the blog).

6) Start Jetty.

Tip: setup a console logging appender in your chosen logging implementation
while testing this out, so that you know if you have that level setup
correctly.
If you see no logging on console, you have setup / configured something
wrong.


--
Joakim Erdfelt <[email protected]>
webtide.com <http://www.webtide.com/>
Developer advice, services and support
from the Jetty & CometD experts
eclipse.org/jetty - cometd.org



On Sun, Nov 4, 2012 at 12:51 PM, Gaurav Kumar <[email protected]> wrote:

> Hi
>
> @Joakim: Thankyou for the suggested link. It definitely showcases common
> logging mechanism which is really helpful.
>
> I had a rather more specific question where I want to place logback+slf4j
> jars at a common location in jetty environment so the webapps could read it
> but jetty should not load it during its startup. I am maintaining 2
> logfiles, one for jetty logging (say, jetty.log) and one file for common
> application logging for multiple wars (say testapp.log) both of which
> should rollover at midnight and on every server startup.
> If slf4j+logback jars are placed in jetty/lib directory then jetty starts
> logging as slf4j -> logback. I however, want jetty to continue logging as
> JUL in jetty.log, while, all other web applications should log using
> logback in testapp.log.
>
> *Also, if I maintain these jars at an alternate location outside the
> wars, how do I let all my wars know about this new classpath to be included
> in the loading context for each war?*
>
> Please suggest.
>

--f46d042ef76baa11dc04cdb18c3f
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div>You say &quot;continue logging as JUL&quot;, I assume you mean java.ut=
il.logging, right?</div><div><br></div><div>You can rely on logback entirel=
y, and setup a sifting logging adapter to accomplish your end goal of 2 log=
 files, just use the filter org.eclipse.jetty for jetty.log, and others nam=
espaces to webapp log adapter.=A0</div>
<div>However you have decided that jetty itself should use java.util.loggin=
g.</div><div><br></div>Note that Slf4J will initalize *very* early in the l=
ife of the JVM. =A0(this is important to understand)<div>Easily before Jett=
y even comes into play.</div>
<div><br></div><div>This will be a delicate configuration, but it might be =
possible.</div><div><br></div><div>The steps.</div><div><br></div><div>1) Y=
ou&#39;ll want to configure Jetty&#39;s Log impl to be java.util.logging.</=
div>
<div>You can do that by setting the System Property ...</div><div>-Dorg.ecl=
ipse.jetty.util.log.class=3Dorg.eclipse.jetty.util.log.JavaUtilLog</div><di=
v><br></div><div>2) Then you&#39;ll want to setup the slf4j api + slf4j imp=
l jars in your ${jetty.home}/lib/logging directory (like the blog shows)</d=
iv>
<div>There are many slf4j implementation jars.</div><div>To have slf4j rout=
e to ....</div><div>=A0* Logback, use logback-classic.jar</div><div>=A0* Lo=
g4j, use slf4j-log4j12.jar, and log4j.jars</div><div>=A0* Apache Commons Lo=
gging, use sfl4j-jcl.jar, commons-logging.jar, and your commons-logging out=
put implementation. (logging inception!)</div>
<div>=A0* java.util.logging, use slf4j-jdk14.jar</div><div><br></div><div>3=
) Then you&#39;ll want to configure your chosen logging framework in the me=
chanism best documented for that framework.</div><div><br></div><div>4) Gra=
b the etc/jetty-webapp-logging.xml configuration (and jar files) outlined i=
n the blog.</div>
<div>This will configure the deployed webapp to use the server side slf4j j=
ars, and not the ones in the webapp itself.</div><div>Essentially, this is =
a tweak the WebApp&#39;s ClassLoader to force the server side on the webapp=
.</div>
<div><br></div><div>5) Setup the etc/jetty-webapp-logging.xml in the start.=
ini (as outlined in the blog).</div><div><br></div><div>6) Start Jetty.</di=
v><div><br></div><div>Tip: setup a console logging appender in your chosen =
logging implementation while testing this out, so that you know if you have=
 that level setup correctly.</div>
<div>If you see no logging on console, you have setup / configured somethin=
g wrong.</div><div><br></div><div class=3D"gmail_extra"><br clear=3D"all"><=
div>--</div><div>Joakim Erdfelt &lt;<a href=3D"mailto:[email protected]" t=
arget=3D"_blank">[email protected]</a>&gt;</div>
<div><a href=3D"http://www.webtide.com/" target=3D"_blank">webtide.com</a><=
/div><div><span>Developer advice, services and support</span><br><span>from=
 the Jetty &amp; CometD experts</span></div><div><a href=3D"http://eclipse.=
org/jetty/" target=3D"_blank">eclipse.org/jetty</a>=A0-=A0<a href=3D"http:/=
/cometd.org/" target=3D"_blank">cometd.org</a></div>
<br>
<br><br><div class=3D"gmail_quote">On Sun, Nov 4, 2012 at 12:51 PM, Gaurav =
Kumar <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a>&gt;</span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex">
<div dir=3D"ltr">Hi <br><br>@Joakim: Thankyou for the suggested link. It de=
finitely showcases common logging mechanism which is really helpful.<br>=A0=
<br>I had a rather more specific question where I want to place logback+slf=
4j jars at a common location in jetty environment so the webapps could read=
 it but jetty should not load it during its startup. I am maintaining 2 log=
files, one for jetty logging (say, jetty.log) and one file for common appli=
cation logging for multiple wars (say testapp.log) both of which should rol=
lover at midnight and on every server startup. <br>


If slf4j+logback jars are placed in jetty/lib directory then jetty starts l=
ogging as slf4j -&gt; logback. I however, want jetty to continue logging as=
 JUL in jetty.log, while, all other web applications should log using logba=
ck in testapp.log.<br>


<br><b>Also, if I maintain these jars at an alternate location outside the =
wars, how do I let all my wars know about this new classpath to be included=
 in the loading context for each war?</b><br><br>Please suggest.<br></div>


</blockquote></div><br></div>

--f46d042ef76baa11dc04cdb18c3f--