Suppose I have got a logger like:
logger = logging.getLogger(__name__)
Then I add a file handler to it. I want all logs go to the file and all info and above log to be printed on screen.
I know I should set the level of the file handler to logging.INFO.
However, if I use logger.setLevel(logging.INFO)
, then the debug logs won't go to the file. If I use logger.setLevel(logging.DEBUG)
, then all debug logs will be printed on screen.
How to solve this problem?