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