<font size=2 face="Verdana">Hello Ceki,</font>
<br>
<br><font size=2 face="Verdana">Java on Domino means, you are working with
3 types of processes</font>
<br><font size=2 face="Verdana">Agents: Every Agent has it's on VM, It
has it's own Session, it could deal with static loggers.</font>
<br><font size=2 face="Verdana">WebServices: Every Request has it's own
Thread with it's own Session, but the VM remains open until the Server
shuts down</font>
<br><font size=2 face="Verdana">Servlets: Every Request has it's own Thread
with it's own Session, but the VM remains open until the Server shuts down</font>
<br>
<br><font size=2 face="Verdana">As I said we want to log into a database.
To log into a database we need a session. A session is available for a
Thread. This means for WebServices and Servlets, that we need a way to
find the correct DatabaseAppender for the corresponding thread with the
corresponding session from static Loggers. That's why I thought about the
ContextSelector.</font>
<br>
<table>
<tr valign=top>
<td><font size=1 color=#0000a1 face="Verdana">_______________________________<b><br>
Martin Burchard<br>
 </b><br>
 <br>
Tel: +49 89 54493730<br>
Fax: +49 89 54493737<br>
Mob: +49-(0)172-8520299</font><font size=1 color=blue face="Verdana"><u><br>
</u></font><a href=callto:nabor_gilgalad><font size=1 color=blue face="Verdana"><u>Skype:
nabor_gilgalad</u></font></a><font size=1 color=blue face="Verdana"><u><br>
</u></font><a href=mailto:martin.burchard@pentos.com><font size=1 color=blue face="Verdana"><u>martin.burchard@pentos.com</u></font></a><font size=1 color=#0000a1 face="Verdana"><br>
_______________________________</font>
<td><font size=1 color=#0000a1 face="Verdana">_______________________________<b><br>
Pentos AG<br>
 </b><br>
 <br>
Landsberger Straße 6<br>
80339 München<br>
Tel: +49 89 54493730<br>
Fax: +49 89 54493737</font><font size=1 color=blue face="Verdana"><u><br>
</u></font><a href=http://www.pentos.com/><font size=1 color=blue face="Verdana"><u>www.pentos.com</u></font></a><font size=1 color=#0000a1 face="Verdana"><br>
_______________________________</font></table>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">From:</font>
<td><font size=1 face="sans-serif">Ceki Gulcu &lt;ceki@qos.ch&gt;</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">To:</font>
<td><font size=1 face="sans-serif">logback users list &lt;logback-user@qos.ch&gt;</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Date:</font>
<td><font size=1 face="sans-serif">05.03.2009 15:32</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Subject:</font>
<td><font size=1 face="sans-serif">Re: [logback-user] ContextSelector and
getLogger</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Sent by:</font>
<td><font size=1 face="sans-serif">logback-user-bounces@qos.ch</font></table>
<br>
<hr noshade>
<br>
<br>
<br><tt><font size=2><br>
Hello Martin,<br>
<br>
Could you please describe your use case in your terms without assuming
the use <br>
of a ContextSelector?<br>
<br>
Martin Burchard wrote:<br>
&gt; Hello,<br>
&gt; <br>
&gt; I currently try to get SLF4J and Logback to work on IBM Lotus Domino
Server<br>
&gt; 8.5.<br>
&gt; It's working.<br>
&gt; We need to do logging an a per Thread basis because we log into a
Domino<br>
&gt; database. The Java object of a Domino database is based on a session
object,<br>
&gt; and that can not exist over more then one thread.<br>
&gt; Okay, I created a simple ContextSelector:<br>
&gt; <br>
&gt; package de.pentos.domino.logging;<br>
&gt; <br>
&gt; import java.util.Arrays;<br>
&gt; import java.util.List;<br>
&gt; <br>
&gt; import ch.qos.logback.classic.LoggerContext;<br>
&gt; <br>
&gt; /**<br>
&gt; &nbsp;* @author Martin Burchard<br>
&gt; &nbsp;*/<br>
&gt; public class ContextSelector implements<br>
&gt; &nbsp; &nbsp; ch.qos.logback.classic.selector.ContextSelector {<br>
&gt; <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;private
final LoggerContext defaultContext;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;private
static final ThreadLocal&lt;LoggerContext&gt; threadLocal = new<br>
&gt; ThreadLocal&lt;LoggerContext&gt;();<br>
&gt; <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public
ContextSelector(final LoggerContext context) {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
defaultContext = context;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
&gt; <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public
LoggerContext detachLoggerContext(final String loggerContextName) {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
return getLoggerContext();<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
&gt; <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public
List&lt;String&gt; getContextNames() {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
return Arrays.asList(getLoggerContext().getName());<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
&gt; <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public
LoggerContext getDefaultLoggerContext() {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
return defaultContext;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
&gt; <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public
LoggerContext getLoggerContext() {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
LoggerContext lc = threadLocal.get();<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
if (lc == null) {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;threadLocal.set(new
LoggerContext());<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
}<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
return threadLocal.get();<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
&gt; <br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public
LoggerContext getLoggerContext(final String name) {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
if (getLoggerContext().getName().equals(name)) {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return
getLoggerContext();<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
}<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
return null;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
&gt; <br>
&gt; }<br>
&gt; <br>
&gt; As long as all Loggers are used like this:<br>
&gt; <br>
&gt; private Logger log = LoggerFactory.getLogger(DemoWebService.class);<br>
&gt; <br>
&gt; everything works fine, I get my logging.<br>
&gt; <br>
&gt; But also this is a common way to get my Logger:<br>
&gt; <br>
&gt; private static final Logger log =<br>
&gt; LoggerFactory.getLogger(DemoWebService.class);<br>
&gt; <br>
&gt; Because for WebServices and Servlets the VM is not terminated and
these<br>
&gt; Logger Instance will live a long time without ever get refreshed.<br>
&gt; After the first run I don't see logging any more.<br>
&gt; <br>
&gt; How can I deal with external JARs like Apache HTTP Client and other
that<br>
&gt; instantiate the loggers in a static way?<br>
&gt; <br>
&gt; Regards,<br>
&gt; Martin<br>
<br>
-- <br>
Ceki Gülcü<br>
Logback: The reliable, generic, fast and flexible logging framework for
Java.<br>
</font></tt><a href=http://logback.qos.ch/><tt><font size=2>http://logback.qos.ch</font></tt></a><tt><font size=2><br>
_______________________________________________<br>
Logback-user mailing list<br>
Logback-user@qos.ch<br>
</font></tt><a href="http://qos.ch/mailman/listinfo/logback-user"><tt><font size=2>http://qos.ch/mailman/listinfo/logback-user</font></tt></a><tt><font size=2><br>
</font></tt>
<br>
<br>