Google App Engine/Python - Change logging formatting

前端 未结 1 1766
隐瞒了意图╮
隐瞒了意图╮ 2021-01-02 17:42

How can one change the formatting of output from the logging module in Google App Engine?

I\'ve tried, e.g.:

  log_format = \"* %(asctim         


        
相关标签:
1条回答
  • 2021-01-02 18:31

    Here is one way you can change the logging format without duplicating output:

    # directly access the default handler and set its format directly
    logging.getLogger().handlers[0].setFormatter(fr)
    

    This is a bit of a hack because you have to directly access the handlers list stored in the root logger. The problem is GAE automatically uses logging before your code is ever run - this creates a default handler. Unfortunately, I don't see how you can get a reference to this handler without directly accessing the handlers list as above.

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