python logging file is not working when using logging.basicConfig

前端 未结 5 666
一生所求
一生所求 2021-01-31 08:01

I have the following lines of code that initialize logging. I comment one out and leave the other to be used. The problem that I\'m facing is that the one that is meant to log t

5条回答
  •  臣服心动
    2021-01-31 08:12

    Another solution that worked for me is instead of tracing down which module might be importing logging or even calling basicConfig before me is to just call setLevel after basicConfig again.

    import os
    import logging
    
    RUNTIME_DEBUG_LEVEL = os.environ.get('RUNTIME_DEBUG_LEVEL').upper()
    LOGGING_KWARGS = {
        'level': getattr(logging, RUNTIME_DEBUG_LEVEL)
    }
    
    logging.basicConfig(**LOGGING_KWARGS)
    logging.setLevel(getattr(logging, RUNTIME_DEBUG_LEVEL))
    

    Sort of crude, seems hacky, fixed my problem, worth a share.

提交回复
热议问题