Nov-01-2025, 09:38 PM
I'm newbie in Python development.
I was reading several logging tutorials. For example, in "Medium" you have this guide:
A Step-by-Step Guide to Configuring Python Logging with YAML Files
It suggests to load configuration file in order to log a message, this way:
Are there any way to avoid this boilerplate?
Is there a solution in the standard library for this issue?
Thank you, in advance.
--
Adrián E. Córdoba
I was reading several logging tutorials. For example, in "Medium" you have this guide:
A Step-by-Step Guide to Configuring Python Logging with YAML Files
It suggests to load configuration file in order to log a message, this way:
import logging.config
import yaml
# Load the config file
with open('logging_config.yaml', 'rt') as f:
config = yaml.safe_load(f.read())
# Configure the logging module with the config file
logging.config.dictConfig(config)
# Get a logger object
logger = logging.getLogger('development')
# Log some messages
logger.debug('This is a debug message')But, when I have an application with several modules, I have to repeat this code in every module that need to log.Are there any way to avoid this boilerplate?
Is there a solution in the standard library for this issue?
Thank you, in advance.
--
Adrián E. Córdoba
--
Adrián E. Córdoba
Adrián E. Córdoba
