I have main.py application and two modules in subfolder called utils: aws_utils.py and logger.py.
Logger contains configuration for logger. I would like my main.py to inititiate an instance from logger.py and ensure that aws_utils.py uses the exact same definition. aws_utils is also called from main.py
How to effectively do that?
#๐ How to use same logger definition in all subclasses?
9 messages ยท Page 1 of 1 (latest)
@nimble topaz
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
I don't understand your question
What does "initiate an instance" mean?
I'd organize your stuff like this ```
2024-12-01 11:11 ./utils/aws_utils.py Page 1
import logging
logger = logging.getLogger(name)
def authenticate():
logger.debug("Pretend I'm authenticating")
2024-12-01 11:12 ./utils/logger.py Page 1
import logging
def configure_logging() -> None:
logging.basicConfig(
# https://docs.python.org/3/library/logging.html#logrecord-attributes
format="{asctime} {levelname:5} {filename} {funcName} {message}",
level=logging.DEBUG,
datefmt="%Y-%m-%dT%H:%M:%S%z",
style="{",
)
2024-12-01 11:11 ./main.py Page 1
import utils.aws_utils
import utils.logger
utils.logger.configure_logging()
utils.aws_utils.authenticate()
Just logging.getLogger(same_name_here)
Main would grab it and configure, then any module using the same logger name will use the same one, with the same config.
Makes sense. Thank you both!
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.