Смотрите этот пример:
Код: Выделить всё
import logging
import open3d as o3d
logger = logging.getLogger(__name__)
def main():
# set base level of logger on a module level
logger.setLevel(logging.DEBUG)
# create file handler which logs even debug messages
fh = logging.FileHandler('log.log')
fh.setLevel(logging.DEBUG)
# create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
# add the handlers to the logger
logger.addHandler(fh)
logger.addHandler(ch)
logger.info('This gets printed twice to console and once to log file.')
if __name__=="__main__":
main()
Код: Выделить всё
2022-03-29 15:06:20,533 - __main__ - INFO - This gets printed twice to console and once to log file.
INFO - 2022-03-29 15:06:20,533 - test - This gets printed twice to console and once to log file.
Спасибо за помощь!
Решение, которое сработало для меня:
С подсказкой Благодаря ответу @Cargo23 и помощи этого вопроса я смог проверить все регистраторы и обработчики и нашел StreamHandler в RootLogger.
С помощью этих строк сразу после импорта я смог удалить его:
Код: Выделить всё
rootlogger = logging.getLogger()
rootlogger.handlers.pop()
Подробнее здесь: https://stackoverflow.com/questions/716 ... use-loggin
Мобильная версия