<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 28, 2017 at 1:04 PM, Christopher Larson <span dir="ltr">&lt;<a href="mailto:chris_larson@mentor.com" target="_blank">chris_larson@mentor.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><span class=""><div class="gmail_quote">On Tue, Mar 28, 2017 at 12:50 PM, Paul Eggleton <span dir="ltr">&lt;<a href="mailto:paul.eggleton@linux.intel.com" target="_blank">paul.eggleton@linux.intel.com</a><wbr>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="m_-3061383614194082498gmail-">On Wednesday, 29 March 2017 5:01:31 AM NZDT Christopher Larson wrote:<br>
&gt; On Mon, Mar 27, 2017 at 5:51 PM, Paul Eggleton &lt;<br>
&gt; <a href="mailto:paul.eggleton@linux.intel.com" target="_blank">paul.eggleton@linux.intel.com</a>&gt; wrote:<br>
&gt; &gt; BufferedLogger was sending log records to the target logger using<br>
&gt; &gt; handle() - this meant that the filtering (e.g. log level set)<br>
&gt; &gt; on the target logger was bypassed, leading for example to debug records<br>
&gt; &gt; getting printed when the log level was set to logging.WARNING.<br>
&gt; &gt;<br>
&gt; &gt; Signed-off-by: Paul Eggleton &lt;<a href="mailto:paul.eggleton@linux.intel.com" target="_blank">paul.eggleton@linux.intel.com</a><wbr>&gt;<br>
&gt;<br>
&gt; The ‘filter’ method of a Logger instance doesn’t log anything, it’s a<br>
&gt; subclass of Filterer, which just checks whether it should be logged. The<br>
&gt; ‘handle’ method of a Logger already consults self.filter(), if you check<br>
&gt; the code:<br>
&gt;<br>
&gt;    def handle(self, record):<br>
&gt;           &quot;&quot;&quot;<br>
&gt;           Call the handlers for the specified record.<br>
&gt;<br>
&gt;           This method is used for unpickled records received from a socket,<br>
&gt; as<br>
&gt;           well as those created locally. Logger-level filtering is applied.<br>
&gt;           &quot;&quot;&quot;<br>
&gt;           if (not self.disabled) and self.filter(record):<br>
&gt;               self.callHandlers(record)<br>
<br>
</span>Oops, you&#39;re right. I&#39;m still confused about why I&#39;m seeing debugging messages<br>
when the target logger is set to INFO then. Do you have any suggestions on how<br>
we fix this?<br>
<br>
(I&#39;ve attached a simplified test script demonstrating the issue.)</blockquote></div><br></span>handle() obeys filter(), but it seems filter() only checks to see if this logger is or isn’t responsible for a given message, it doesn’t actually check to see whether the logger is enabled for a given record given its level. The level based checking for a logger (as opposed to a handler) seems to be done in the actual message function, i.e.:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">    def debug(self, msg, *args, **kwargs):</div><div class="gmail_extra">          if self.isEnabledFor(DEBUG):</div><div class="gmail_extra">              self._log(DEBUG, msg, args, **kwargs)</div><div><br></div><div>The setLevel() for the BufferLogger itself ensures that anything of that level (logging.DEBUG) or higher severity gets buffered, but then we bypass the isEnabledFor() on the main logger by calling handle directly rather than the individual level-based methods. I expect we should use isEnabledFor rather than filter, and keep the conditional ourselves:</div><div><br></div><div><span class=""><span style="font-size:12.800000190734863px">     def flush(self):</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">         for record in self.buffer:</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">-            self.target.handle(record)</span><br style="font-size:12.800000190734863px"></span><span style="font-size:12.800000190734863px">+            if self.target.isEnabledFor(<wbr>record.level):</span></div><div><span style="font-size:12.800000190734863px">+                self.target.handle(record)</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">         self.buffer = []</span></div></div></blockquote></div><br>s/\.level/.levelno/<br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>Christopher Larson<br>kergoth at gmail dot com<br>Founder - BitBake, OpenEmbedded, OpenZaurus<br>Senior Software Engineer, Mentor Graphics</div></div></div></div></div></div></div>
</div></div>