Guten Tag Wenn möglich habe ich eine Frage: Das ist mein Code: mainbcdbcd.py import logging import logging.config logging.config.fileConfig('loggin.conf') logger=logging.getLogger('simpleExample') #create handler stream_h=logging.StreamHandler() file_h=logging.FileHandler('file.log') #level and the format stream_h.setLevel(logging.WARNING) file_h.setLevel(logging.ERROR) formatter=logging.Formatter('%(name)s - %(levelname)s - %(message)s') stream_h.setFormatter(formatter) file_h.setFormatter(formatter) logger.addHandler(stream_h) logger.addHandler(file_h) logger.warning('this is a warning') logger.error('this is an error')loggin.conf [logger] keys=root,simpleExample [handler] keys=consoleHandler [logger_root] level=DEBUG handlers=consoleHandler [logger_simpleExample] level=DEBUG handlers=consoleHandler qualname=simpleExample propagate=0 [handler_consoleHandler] class=StreamHandler level=DEBUG formatter=simpleFormatter args=(sys.stdout,) [formatter_simpleFormatter] format='%(asctime)s - %(name)s %(levelname)s - %(message)s' Als ich lief, bekam ich diesen Fehler: C:\Users\User\python_logs\venv\Scripts\python.exe C:/Users/User/python_logs/venv/bcdbcd.py Traceback (most recent call last): File "C:/Users/User/python_logs/venv/bcdbcd.py", line 3, in <module> import mainbcdbcd File "C:\Users\User\python_logs\venv\mainbcdbcd.py", line 4, in <module> logging.config.fileConfig('loggin.conf') File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\logging\config.py", line 71, in fileConfig formatters = _create_formatters(cp) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\logging\config.py", line 104, in _create_formatters flist = cp["formatters"]["keys"] File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\configparser.py", line 958, in __getitem__ raise KeyError(key) KeyError: 'formatters' Process finished with exit code 1 Ich habe alle in diesen Links beschriebenen Lösungen ausprobiert: https://stackoverflow.com/questions/23161745/python-logging-file-config-keye... https://stackoverflow.com/questions/47636747/python3-6-keyerror-formatters https://stackoverflow.com/questions/29346678/python-3-2-logging-with-config-... https://stackoverflow.com/questions/42209122/python-fileconfig-issue https://stackoverflow.com/questions/8912708/python-logging-keyerror-when-loa... Wenn jemand weiß, was die Lösung sein könnte, wird es mir sehr helfen. danke, Linnea
participants (1)
-
Linnea G