CKTIS / Python
logging.info
info protokolliert normalen Arbeitsfortschritt auf Stufe INFO (20).
Version: Python 3.14; repository image, production runtime not attested
Syntax
logging.info(msg, *args, **kwargs)info protokolliert normalen Arbeitsfortschritt auf Stufe INFO (20).
Der Root-Logger beginnt mit WARNING, deshalb setzt das Beispiel INFO und erhält INFO rows=3. Das Wörterbuch extra ergänzt eigene Felder wie job für das Ausgabeformat.
message über extra zu überschreiben löst KeyError aus.
import io,logging
out=io.StringIO()
logging.basicConfig(stream=out,level=logging.INFO,format='%(levelno)d %(job)s %(message)s',force=True)
logging.info('rows=%d',3,extra={'job':'import'})
assert out.getvalue()=='20 import rows=3\n'
try: logging.info('x',extra={'message':'collision'})
except KeyError: pass
else: raise AssertionError
Beispiele
import logging
from io import StringIO
out = StringIO()
logging.basicConfig(stream=out, level=logging.INFO, format="%(levelname)s %(message)s", force=True)
logging.info("rows=%d", 3)
print(out.getvalue().strip())
Ergebnis
INFO rows=3
message über extra zu überschreiben löst KeyError aus.