How to right align level field in Python logging.Formatter

前端 未结 2 667
走了就别回头了
走了就别回头了 2021-02-01 01:20

I\'m currently trying to right align the logging level field in my Python logger so that output such as:

[2011-10-14 13:47:51] [DEBUG] --- starting... (smtphandl         


        
2条回答
  •  情歌与酒
    2021-02-01 02:25

    Try with this format line :

    logging.Formatter("[%(asctime)s] [%(levelname)8s] --- %(message)s (%(filename)s:%(lineno)s)", "%Y-%m-%d %H:%M:%S")
    

    python logger formatter use the standard python string formatting rules

提交回复
热议问题