logging.info doesn't show up on console but warn and error do

前端 未结 3 1760
慢半拍i
慢半拍i 2021-01-30 19:29

When I log an event with logging.info, it doesn\'t appear in the Python terminal.

import logging
logging.info(\'I am info\')  # no output

3条回答
  •  礼貌的吻别
    2021-01-30 19:51

    The above solutions didn't work for me, but the code here did:

    # set up logging to file
    logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                        datefmt='%m-%d %H:%M',
                        filename='/temp/myapp.log',
                        filemode='w')
    # define a Handler which writes INFO messages or higher to the sys.stderr
    console = logging.StreamHandler()
    console.setLevel(logging.INFO)
    # add the handler to the root logger
    logging.getLogger('').addHandler(console)
    

    (I omitted parts of the code for the sake of readability)

提交回复
热议问题