What is Python's default logging formatter?

后端 未结 5 1615
有刺的猬
有刺的猬 2021-02-05 01:02

I\'m trying to decipher the information contained in my logs (the logging setup is using the default formatter). The documentation states:

Do formatting f

5条回答
  •  余生分开走
    2021-02-05 01:46

    The default format is located here which is:

    BASIC_FORMAT = "%(levelname)s:%(name)s:%(message)s"  
    

    The Format code will tell you how you can customize it. Here is one example on how you can customize it.

    import sys
    import logging
    
    logging.basicConfig(
        level=logging.DEBUG,
        format="[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s",
        datefmt="%d/%b/%Y %H:%M:%S",
        stream=sys.stdout)
    
    logging.info("HEY")
    

    Which results in:

    [26/May/2013 06:41:40] INFO [root.:1] HEY
    

提交回复
热议问题