<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'>
Hi Ceki,<br><br>Thanks for your fast response. Are there any there any other known causes for SLF4j in combination with Logback to create a NOP logger? Only ones i found were:<br>- parallel Loggerfactory.getLogger() calls.<br>- not able to bind.<br><br>Your proposal of reassignment may be risky in the second case:<br>&nbsp;&nbsp;&nbsp; Logger initializingLogger = LoggerFactory.getLogger("temporary.SLF4J.initializing.logger");<br>&nbsp;&nbsp;&nbsp; while ("NOP".equals(initializingLogger.getName())){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp; sleep/wait a little until other thread finished getLogger() call<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; initializingLogger = LoggerFactory.getLogger("temporary.SLF4J.initializing.logger");<br>&nbsp;&nbsp;&nbsp; }&nbsp; <br>&nbsp;&nbsp;&nbsp; // continue with (normal) instantiation of the actual logger.<br><br><br>Best regards,<br><br>Rutger<br>

<hr id="ecxEC_[object]">
<br><br><br><div>&gt; Date: Wed, 28 Sep 2011 10:35:32 +0200<br>&gt; From: ceki@qos.ch<br>&gt; To: logback-user@qos.ch<br>&gt; Subject: Re: [logback-user] NOP logger issue/workaround<br>&gt; <br>&gt; Hi Rutger,<br>&gt; <br>&gt; Response in line.<br>&gt; <br>&gt; On 28/09/2011 10:02 AM, Rutger Saalmink wrote:<br>&gt; &gt; Hi all,<br>&gt; &gt;<br>&gt; &gt; Currently I am developing a logging class for weblogic, which functions<br>&gt; &gt; as a tool for writing to a set of logfiles. Several types of external<br>&gt; &gt; parties access this class (e.g. other classes, jars, services, etc),<br>&gt; &gt; potentially concurrent calls. Conceptually it looks like this:<br>&gt; &gt;<br>&gt; &gt; public class myClass{<br>&gt; &gt; private static Logger loggerLog = LoggerFactory.getLogger(myClass.class);<br>&gt; &gt; private static Logger logA = LoggerFactory.getLogger("my.logA");<br>&gt; &gt; private static Logger logB = LoggerFactory.getLogger("my.logB");<br>&gt; &gt;<br>&gt; &gt; public static boolean logStringToA(final String strValue){<br>&gt; &gt; loggerLog.info("Write String to log A.");<br>&gt; &gt; logA.info(strValue);<br>&gt; &gt; }<br>&gt; &gt;<br>&gt; &gt; public static boolean logNodeToB(final Node nodeValue){<br>&gt; &gt; loggerLog.info("Write Node to log B.");<br>&gt; &gt; // do some stuff with the Node<br>&gt; &gt; logB.info(nodeToStringFunction(nodeValue));<br>&gt; &gt; }<br>&gt; &gt; }<br>&gt; &gt;<br>&gt; &gt; The problem is that SLF4j gets instantiated with NOP loggers on the<br>&gt; &gt; first calls to the public methods, possibly due to:<br>&gt; &gt; http://bugzilla.slf4j.org/show_bug.cgi?id=106<br>&gt; &gt; http://bugzilla.slf4j.org/show_bug.cgi?id=176<br>&gt; &gt;<br>&gt; &gt; To fix this problem I try to reload the logback configuration at<br>&gt; &gt; run-time, explained in<br>&gt; &gt; http://logback.qos.ch/manual/configuration.html#joranDirectly . However,<br>&gt; &gt; this means that I will have to reinitialize the loggers in myClass<br>&gt; &gt; (another call to LoggerFactory.getLogger()) before logging starts.<br>&gt; <br>&gt; Yes, that is correct.<br>&gt; <br>&gt; &gt; But that would imply using some kind of reloading thread which checks for<br>&gt; &gt; NOP loggers, which isn't that pretty.<br>&gt; <br>&gt; You could check the type of the returned logger. If it was of type <br>&gt; NOPLogger, you could simply reassign the logger reference (loggerLog, <br>&gt; logA and logB). No additional thread would be necessary.<br>&gt; <br>&gt; &gt; Also I would lose any logging  calls going on in the meanwhile.<br>&gt; <br>&gt; Yes.<br>&gt; <br>&gt; &gt; Anyone has a good idea on how to prevent SLF4j creating these NOP<br>&gt; &gt; loggers, or a solution for the workaround?<br>&gt; <br>&gt; The solution proposed in bug 176 is probably the way to go. Depending on <br>&gt; the use case, reassignment of the logger reference would be a simple<br>&gt; albeit cumbersome solution.<br>&gt; <br>&gt; &gt; Best regards,<br>&gt; &gt;<br>&gt; &gt; Roger<br>&gt; <br>&gt; HTH,<br>&gt; <br>&gt; -- <br>&gt; http://twitter.com/ceki<br>&gt; _______________________________________________<br>&gt; Logback-user mailing list<br>&gt; Logback-user@qos.ch<br>&gt; http://qos.ch/mailman/listinfo/logback-user<br></div>                                               </div></body>
</html>