all Python 3loggingfunction
logging.basicConfig()
configuration
Quick basic setup of the logging system: the level, the format, the output file or stream. Call it once, before the first logging call.
Syntax
logging.basicConfig(level=, format=, filename=, filemode=, encoding=)
The call takes effect only while the root logger has no handlers yet: a second call — or even the first one, if a stray logging.warning() already auto-configured the root — is silently ignored unless you pass force=True (available since 3.8). The default level is WARNING, so debug and info messages vanish until you lower it explicitly. Libraries should never call it; leave output configuration to the application.
Examples
import logging
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(message)s'
)
logging.debug('старт') # → в stderr: <дата время> DEBUG старт
logging.info('готово') # → в stderr: <дата время> INFO готово
See also
Open in the full glossarydocs.python.orgReport an inaccuracy