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


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

Ich sende erneut - der Code war nicht klar- python - loggin.conf

X-Received by 2002:a05:620a:1a9f:b0:6af:2348:ad95 with SMTP id bl31-20020a05620a1a9f00b006af2348ad95mr19173865qkb.526.1656933346741; Mon, 04 Jul 2022 04:15:46 -0700 (PDT)
X-Received by 2002:a05:6808:238d:b0:335:8fb6:ccb7 with SMTP id bp13-20020a056808238d00b003358fb6ccb7mr16589989oib.212.1656933346475; Mon, 04 Jul 2022 04:15:46 -0700 (PDT)
Path csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups de.comp.lang.python
Date Mon, 4 Jul 2022 04:15:46 -0700 (PDT)
Injection-Info google-groups.googlegroups.com; posting-host=87.71.7.244; posting-account=TEsHeAoAAAARE3wCPbXq05j6DF-fM4ap
NNTP-Posting-Host 87.71.7.244
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <ff7ebbcc-f21c-40ff-b50d-13f4749b1b74n@googlegroups.com> (permalink)
Subject Ich sende erneut - der Code war nicht klar- python - loggin.conf
From Linnea G <mi9877ch@gmail.com>
Injection-Date Mon, 04 Jul 2022 11:15:46 +0000
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding quoted-printable
Lines 105
Xref csiph.com de.comp.lang.python:5824

Show key headers only | 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 | NextNext in thread | Find similar


Thread

Ich sende erneut - der Code war nicht klar- python - loggin.conf Linnea G <mi9877ch@gmail.com> - 2022-07-04 04:15 -0700
  [Python-de] Re: Ich sende erneut - der Code war nicht klar- python - "Massa, Harald Armin" <chef@ghum.de> - 2022-07-04 13:29 +0200
    Re: [Python-de] Re: Ich sende erneut - der Code war nicht klar- python - Linnea G <mi9877ch@gmail.com> - 2022-07-04 05:26 -0700

csiph-web