-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement module scoped logging #361
Conversation
src/fundus/logging/__init__.py
Outdated
def create_logger(name: str) -> logging.Logger: | ||
logger = logging.getLogger(name) | ||
logger.setLevel(logging.ERROR) | ||
logger.addHandler(_stream_handler) | ||
_loggers.append(logger) | ||
return logger | ||
|
||
|
||
def set_log_level(level: int): | ||
for logger in _loggers: | ||
logger.setLevel(level) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This definitely works. But I wondered if such a setup is possible where each module can just call logger.getLogger(__name__)
to get their module logger, just like in the python logging guide. I failed to get this to work but wanted to give the idea here. Maybe you tried this as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. The only problem is see is how we set the log level for all Fundus logger at once? Setting them individually wouldn't be a problem, but I have no solution for how we would set the whole library to DEBUG
without keeping track of the loggers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that was also a problem I encountered. I found this comment but haven't been able to get this working. I would merge this for now as is and maybe try later.
# Conflicts: # scripts/generate_parser_test_files.py # src/fundus/parser/data.py # src/fundus/scraping/crawler.py # src/fundus/scraping/scraper.py # src/fundus/scraping/session.py
Since #357 rewrites a huge part of the core pipeline, this PR is based on the redesign and should be merged afterwards.
This removes the central logging solution of
basic_logger
and implements module-scoped logging. Every module utilizing logging must now have its own logger called__module_logger__
.One can set a global log level
effecting only loggers created with
create_logger
, or setting the log level of individual module-scoped loggers by importing them.