<div dir="ltr">The recipe as you pointed out works by logging to both (just using multiple handlers).<div>The objective is to log *up to a level* to stdout and the rest to stderr.<br><br>See the example console handler <a href="https://github.com/mariocj89/cpython/commit/501cfcd0f4cad1e04d87b89784988c52a77a80ad" target="_blank">here</a> and the filter <a href="https://gist.github.com/mariocj89/7d873fc84bf8723f5e2740adbeccde12">here</a>.</div><div><br></div><div>Good point about just adding it to the how-to.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 10 February 2018 at 20:20, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Sun, Feb 11, 2018 at 6:29 AM, Mario Corchero <<a href="mailto:mariocj89@gmail.com">mariocj89@gmail.com</a>> wrote:<br>
> Hello All!<br>
><br>
> I got asked how to configure the logging stack to be able to output directly<br>
> to console using both stdout and stderr and I could not really find a great<br>
> answer as adding both as StreamHandlers will result in error and above<br>
> messages going to stdout.<br>
<br>
</span>There's a recipe in the docs that shows how to "fork" to console and file:<br>
<br>
<a href="https://docs.python.org/3/howto/logging-cookbook.html#logging-to-multiple-destinations" rel="noreferrer" target="_blank">https://docs.python.org/3/<wbr>howto/logging-cookbook.html#<wbr>logging-to-multiple-<wbr>destinations</a><br>
<br>
I presume that's what you were looking at? Because yes, that'll do<br>
exactly what you say.<br>
<span class=""><br>
> The usecase is having a cli or app that wants to log to console as other<br>
> tools. Errors and bove to stderr and normal information to stdout. I know<br>
> the recommended way in Python is to just use print on simple scripts, but it<br>
> can happen that you import a library you want to see the logs of, and<br>
> therefore you need to set the logging stack.<br>
><br>
> I have drafted two implementations but I am open to suggestions:<br>
> 1) A "Console Handler" that uses multiple streams and chooses based on the<br>
> level.<br>
> 2) An inverted filter that can be used to filter everything above info for<br>
> the stdout Stream handler.<br>
><br>
> What do you people think?<br>
> If people like it I'll send an issue + PR.<br>
<br>
</span>It would be an interesting variant on the recipe to say "debug and<br>
above, but NOT error and above, goes to this stream". How complex are<br>
the implementations? Would they fit nicely into the cookbook?<br>
<br>
ChrisA<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</blockquote></div><br></div>