How to right align level field in Python logging.Formatter

前端 未结 2 665
走了就别回头了
走了就别回头了 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:10

    Like this:

    logging.Formatter("[%(asctime)s] [%(levelname)8s] --- %(message)s (%(filename)s:%(lineno)s)", "%Y-%m-%d %H:%M:%S")
    
    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题