Доброго времени суток.У меня такая проблема.При запуске кода у меня должен записываться лог в файл 1 раз,но при этом он записывается до бескнечности и не дает программе идти дальше по алгоритму.Вот сам код:
import os
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.lang import Builder
import os
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.uix.button import Button
import bluetooth
from kivy.lang import Builder
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
fh = logging.FileHandler('log_filename.txt')
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
logger.addHandler(fh)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
logger.addHandler(ch)
logger.debug('This is a test log message.')
А вот,что выскакивает в терминале и файле:
2017-09-22 21:53:29,143 - [1;36mDEBUG[0m - This is a test log message.
2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,143 - [1;36mDEBUG[0m - This is a test log message.
2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,143 - [1;36mDEBUG[0m - This is a test log message.
2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,143 - [1;36mDEBUG[0m - This is a test log message.
2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,143 - [1;36mDEBUG[0m - This is a test log message.
2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,143 - [1;36mDEBUG[0m - This is a test log message.
2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,143 - [1;36mDEBUG[0m - This is a test log message.
2017-09-22 21:53:29,147 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,143 - [1;36mDEBUG[0m - This is a test log message.
2017-09-22 21:53:29,147 - WARNING - stderr: 2017-09-22 21:53:29,147 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,143 - [1;36mDEBUG[0m - This is a test log message.
2017-09-22 21:53:29,147 - WARNING - stderr: 2017-09-22 21:53:29,147 - WARNING - stderr: 2017-09-22 21:53:29,147 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,143 - [1;36mDEBUG[0m - This is a test log message.
2017-09-22 21:53:29,148 - WARNING - stderr: 2017-09-22 21:53:29,147 - WARNING - stderr: 2017-09-22 21:53:29,147 - WARNING - stderr: 2017-09-22 21:53:29,147 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,143 - [1;36mDEBUG[0m - This is a test log message.
2017-09-22 21:53:29,148 - WARNING - stderr: 2017-09-22 21:53:29,148 - WARNING - stderr: 2017-09-22 21:53:29,147 - WARNING - stderr: 2017-09-22 21:53:29,147 - WARNING - stderr: 2017-09-22 21:53:29,147 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,146 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,145 - WARNING - stderr: 2017-09-22 21:53:29,143 - [1;36mDEBUG[0m - This is a test log message.
Но при запуске вот этого кода у меня все в норме:
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
fh = logging.FileHandler('log_filename.txt')
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
logger.addHandler(fh)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
logger.addHandler(ch)
logger.debug('This is a test log message.')
Подскажите,как мне исправить ошибку?