Skip to content
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

Use importlib.resources to load default logging config file #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
'simplejson==3.11.1',
'python-dateutil>=2.6.0',
'backoff==1.8.0',
'ciso8601',
'ciso8601',
'importlib-resources>=1.3; python_version<"3.9"',
],
extras_require={
'dev': [
Expand Down
13 changes: 9 additions & 4 deletions singer/logger.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import logging
import logging.config
import os
import sys

if sys.version_info < (3, 9):
import importlib_resources
else:
from importlib import resources as importlib_resources


def get_logger():
"""Return a Logger instance appropriate for using in a Tap or a Target."""
this_dir, _ = os.path.split(__file__)
path = os.path.join(this_dir, 'logging.conf')
path = importlib_resources.files(__package__).joinpath('logging.conf')
# See
# https://docs.python.org/3.5/library/logging.config.html#logging.config.fileConfig
# for a discussion of why or why not to set disable_existing_loggers
# to False. The long and short of it is that if you don't set it to
# False it ruins external module's abilities to use the logging
# facility.
logging.config.fileConfig(path, disable_existing_loggers=False)
with path.open() as f:
logging.config.fileConfig(f, disable_existing_loggers=False)
return logging.getLogger()


Expand Down