import logging logging.basicConfig(level=logging.INFO) logging.info('This is an informational message') logging.warning('This is a warning message') logging.error('This is an error message')
import structlog log = structlog.get_logger() log.info('This is an informational message', extra={'data': 'some additional data'}) log.warning('This is a warning message', extra={'data': 'some additional data'}) log.error('This is an error message', extra={'data': 'some additional data'})
from loguru import logger logger.add('file.log', rotation='500 MB') logger.info('This is an informational message') logger.warning('This is a warning message') logger.error('This is an error message')This code sets up a logger using the loguru package. It logs three different messages and also writes them to a file with a maximum size of 500 MB before rotating. The loguru package is designed to be easy to use and provides additional features like colorized output. It needs to be installed separately from the Python standard library. In summary, Python Logs are a powerful tool for monitoring the behavior of a program. Depending on the need of the user at that particular moment, packages like built-in logging module, structlog, or loguru can be used.