简体   繁体   English

记录python-自定义格式化程序的颜色

[英]logging python - custom formatter with colour

I am using logging module in Python and I already use a custom formatter that just changes the format of the message depending on level. 我正在使用Python中的日志记录模块,并且已经使用了自定义格式化程序,该格式化程序仅根据级别更改消息的格式。

As I use a lot of message in the tool I am writing I wonder if there is a way to write a log message with a colour 当我在该工具中使用大量消息时,我想知道是否有一种方法可以用颜色写日志消息

I don't want it to be definitive (ie add colours in the formatter class) I would like to write a log message 我不希望它是确定的(即在formatter类中添加颜色)我想写一条日志消息

logging.info('i am doing this, wait...')

in red (or any other colour) 红色(或其他任何颜色)

regards 问候

Here is a description of how you can do this. 是如何执行此操作的说明。 Available via the logutils package from PyPI (I'm the maintainer). 可通过PyPI的logutils包获得(我是维护者)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM