<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>


<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>

<div dir="ltr">

<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>

<div dir="ltr">

<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>

<div dir="ltr">

<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>

<div dir="ltr"><div><div><font face="'Courier New'" size="2">Hello,</font></div><div><font face="'Courier New'" size="2"><br></font></div><div><font face="'Courier New'" size="2">I'm trying to obtain a certain logging configuration, but so far I'm unsuccessful. I've read through the Logback manual, but I don't know if I can do what I want.</font></div><div><font face="'Courier New'" size="2"><br></font></div><div><font face="'Courier New'" size="2">It is a web application, and my objective is to enable a finer logging level for specific users, getting written to a specific log file, allowing better debugging directly in production environment. When needed, someone will set a tuned XML config using JMX to enable logging for the duration of the tests/data gathering (JMX is working fine). This is the relevant part of my logback.xml file:</font></div><div><font face="'Courier New'" size="2"><br></font></div><div><font face="'Courier New'" size="2"><configuration debug="true"></font></div><div><font face="'Courier New'" size="2"><br></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre"> </span>...</font></div><div><font face="'Courier New'" size="2"><br></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">   </span><appender name="FILTERED" class="ch.qos.logback.core.rolling.RollingFileAppender"></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">              </span> <filter class="com.sample.project.UserFilter"></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">                   </span><!--</font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">                           </span>//filter code</font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">                             </span>if (level != null && !event.getLevel().isGreaterOrEqual(level)) {</font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">                                 </span>return FilterReply.DENY;</font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">                          </span>}</font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">                         </span>if (user.equals(MDC.get("userId"))) {</font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">                                   </span>return FilterReply.ACCEPT;</font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">                                </span>} else {</font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">                                  </span>return FilterReply.DENY;</font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">                          </span>}</font></div><div><font face="'Courier New'" size="2"><br></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">                     </span>--></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">            </span> <span class="Apple-tab-span" style="white-space:pre">   </span><level>DEBUG</level></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">          </span> <span class="Apple-tab-span" style="white-space:pre">   </span><user>123456</user></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">           </span> </filter></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">          </span> </font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">            </span>...</font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">       </span></appender></font></div><div><font face="'Courier New'" size="2"><br></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">     </span><logger name="com.sample.project"></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">                </span><appender-ref ref="FILTERED" /></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">   </span></logger></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">   </span><logger name="com.sample.legacy" additivity="false"></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">            </span><appender-ref ref="LEGACY" /></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">     </span></logger></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">   </span><root level="WARN"></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">               </span><appender-ref ref="STANDARD" /></font></div><div><font face="'Courier New'" size="2"><span class="Apple-tab-span" style="white-space:pre">   </span></root></font></div><div><font face="'Courier New'" size="2"><br></font></div><div><font face="'Courier New'" size="2"></configuration></font></div><div><font face="'Courier New'" size="2"><br></font></div><div><font face="'Courier New'" size="2">With this config, I intend to have:</font></div><div><font face="'Courier New'" size="2">- WARN+ level at root;</font></div><div><font face="'Courier New'" size="2">- events from legacy project tree only on 'LEGACY' (working fine);</font></div><div><font face="'Courier New'" size="2">- 'FILTERED' logging only DEBUG+ events from user '123456' under 'com.sample.project', while its level ramains at WARN (not OK).</font></div><div><font face="'Courier New'" size="2"><br></font></div><div><font face="'Courier New'" size="2">Sample:</font></div><div><font face="'Courier New'" size="2">getLogger("com.sample.abc").warn("...");      //logged to STANDARD</font></div><div><font face="'Courier New'" size="2">getLogger("com.sample.abc").debug("...");     //not logged</font></div><div><font face="'Courier New'" size="2">getLogger("com.sample.legacy").warn("...");   //logged to LEGACY</font></div><div><font face="'Courier New'" size="2">getLogger("com.sample.project").warn("...");  //logged to STANDARD; also logged to FILTERED if user is 123456</font></div><div><font face="'Courier New'" size="2">getLogger("com.sample.project").debug("..."); //logged to FILTERED if user is 123456</font></div><div><font face="'Courier New'" size="2"><br></font></div><div><font face="'Courier New'" size="2">As I tested, a 'logger.debug()' from the desired user does not get logged, the filter is not even called, and I suspect that the effective WARN level denies the event before reaching my filter (I hoped for the other way around). If I set DEBUG on 'com.sample.project', 'FILTERED' will get the correct logging, but 'STANDARD' will be flooded with DEBUG+ logging from 'com.sample.project'. And disabling additivity on it removes all logging belonging to this hierarchy from 'STANDARD'.</font></div><div><font face="'Courier New'" size="2"><br></font></div><div><font face="'Courier New'" size="2">So, I see Logback is working properly, my desired logging seems to be against the standard architecture. But is there a way to archive the described effect?</font></div><div><font face="'Courier New'" size="2">I was thinking of a TurboFilter, allowing lower level events from selected users (not tested yet), but I'm not sure the effective level would kick in first, also it wouldn't do the desired logging separation between 'STANDARD' and 'FILTERED' anyway. As another approach, maybe this would require a custom Logger class, handling specific appenders in a special way. Unfortunately, I have no idea if I can plug in custom Loggers, and also not sure how to code it (Logger class source is quite complex in a quick look).</font></div><div><font face="'Courier New'" size="2"><br></font></div><div><font face="'Courier New'" size="2">Sorry if it wasn't clear, I'm not sure how to present the situation. I can provide further details, if needed.</font></div><div><font face="'Courier New'" size="2">Any help is welcome. If someone could show me which way to follow, maybe classes or methods to extend, I'd be grateful.</font></div><div><font face="'Courier New'" size="2"><br></font></div><div><font face="'Courier New'" size="2">Many thanks!</font></div></div></div>
</div>
</div>
</div>
                                          </div></body>
</html>