all Python 3loggingfunction
logging.warning()
levels
Writes a message at the WARNING level. Use it for potential problems that are not breaking anything right now.
Syntax
logging.warning(msg, *args, **kwargs)
WARNING is the root logger's default threshold, so warning() and anything above it shows up even without basicConfig(), while info() and debug() stay silent — hence the beginner's impression that "only warning works". Don't confuse it with warnings.warn() from the warnings module: that one addresses the programmer (deprecated API, suspicious usage) and by default fires once per call site, whereas logging.warning() records an ordinary runtime event as many times as it occurs.
Examples
import logging
logging.warning('Диск заполнен на %d%%', 90)
logging.warning('Устаревший API вызван: %s', 'old_func')
logging.warning('Не удалось разобрать %r, беру 0', 'abc') # → в stderr: WARNING:root:Не удалось разобрать 'abc', беру 0
logging.info('Это сообщение не появится') # → ничего: уровень root по умолчанию WARNING
print(logging.WARNING) # → 30
See also
Open in the full glossarydocs.python.orgReport an inaccuracy