Python logging only log from script

前端 未结 2 878
有刺的猬
有刺的猬 2021-02-03 23:53

I\'m using the Python logging module in a simple script of mine with the following setup at the moment.

logging.basicConfig(format=\'%(asctime)s %(message)s\', l         


        
2条回答
  •  终归单人心
    2021-02-04 00:16

    Using named loggers in your modules:

    import logging
    logger = logging.getLogger(__name__)
    logger.info("my info")
    logger.error("my error")
    

    you can set the log level for all the other loggers to error and for your loggers to debug:

    import logging
    logging.basicConfig(level=logging.ERROR)
    logging.getLogger(my_module.__name__).setLevel(logging.DEBUG)
    

提交回复
热议问题