Optimal solution for coloring logging output

Mark Lawrence breamoreboy at yahoo.co.uk
Mon Aug 3 16:31:11 CEST 2015


On 03/08/2015 10:13, c.buhtz at posteo.jp wrote:
> I don't want to ask how to do this because there are so many
> "solutions" about it.
> <http://stackoverflow.com/questions/384076/how-can-i-color-python-logging-output>
>
> There are so much different and part of unpythontic solutions I can not
> decide myself. What do you (as real pythontics) think about that.
> Which of the solutions fit to concepts of Python and its logging
> package?
>
> Coloring means here not only the message itself. The (levelname) should
> be included in the coloring.
> For myself coloring the (levelname) would be enough to avoid to much
> color in the output.
>
> 1.
> The solution itself shouldn't care about plattform differences because
> there are still some packages which are able to offer
> plattform-independent console-coloring. Which would you prefere? ;)
>
> 2.
> Some solutions derive from StreamHandler or much more bad hacking the
> emit() function. I think both of them are not responsible for how the
> output should look or be presented.
>
> 3.
> How to present the output is IMO the responsibility of a Formater, isn't
> it? So I should derive from the Formater.
>
> What do you as Pythonics think of that? ;)
>

I'd go for this https://pypi.python.org/pypi/colorlog as recommended on 
a couple of answers on the stackoverflow thread you've referenced.

A slight aside, we're "Pythonistas", not "pythontics" or "Pythonics " :)

<take cover>
Should we subclass Pythonista into Pythonista2 and Pythonista3 so that 
people can show their preferred version?
</take cover>

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Python-list mailing list