Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.python > #5823

python- loggin.conf

Newsgroups de.comp.lang.python
Date 2022-07-04 04:09 -0700
Message-ID <cc86dde0-419d-46f2-b85f-fd0718d8de57n@googlegroups.com> (permalink)
Subject python- loggin.conf
From Linnea G <mi9877ch@gmail.com>

Show all headers | View raw


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-keyerror-formatters
https://stackoverflow.com/questions/47636747/python3-6-keyerror-formatters
https://stackoverflow.com/questions/29346678/python-3-2-logging-with-config-file-results-in-keyerror-formatters-on-raspbia
https://stackoverflow.com/questions/42209122/python-fileconfig-issue
https://stackoverflow.com/questions/8912708/python-logging-keyerror-when-loading-fileconfig

Wenn jemand weiß, was die Lösung sein könnte, wird es mir sehr helfen.
danke, 
Linnea

Back to de.comp.lang.python | Previous | Next | Find similar


Thread

python- loggin.conf Linnea G <mi9877ch@gmail.com> - 2022-07-04 04:09 -0700

csiph-web