CKTIS / Python
logging.warning
warning registra en el registrador raíz un aviso de nivel WARNING (30).
Versión: Python 3.14; repository image, production runtime not attested
Sintaxis
logging.warning(msg, *args, **kwargs)warning registra en el registrador raíz un aviso de nivel WARNING (30).
Sin manejadores la función instala la configuración básica. Los filtros del módulo warnings no controlan este registro.
En el ejemplo el umbral ERROR oculta minor pero deja pasar major, de modo que se imprime ERROR.
import logging,io,warnings
out=io.StringIO()
logging.basicConfig(stream=out,level=logging.WARNING,format='%(levelno)d %(message)s',force=True)
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter('always')
logging.warning('slow')
assert not caught
assert out.getvalue()=='30 slow\n'
logging.getLogger().setLevel(logging.ERROR)
factory=logging.getLogRecordFactory()
created=[]
def record(*args,**kwargs):
created.append(1)
return factory(*args,**kwargs)
logging.setLogRecordFactory(record)
try: logging.warning('hidden')
finally: logging.setLogRecordFactory(factory)
assert not created
assert out.getvalue()=='30 slow\n'
Ejemplos
import logging
from io import StringIO
out = StringIO()
logging.basicConfig(stream=out, level=logging.ERROR, format="%(levelname)s", force=True)
logging.warning("minor")
logging.error("major")
print(out.getvalue().strip())
Resultado
ERROR
En el ejemplo el umbral ERROR oculta minor pero deja pasar major, de modo que se imprime ERROR.