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

feat: switch logger to non-root logger in protobuf #158

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions dgp/utils/protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
get_string_from_s3_file,
)

logger = logging.getLogger(__name__)


def open_pbobject(path, pb_class):
"""Load JSON as a protobuf (pb2) object.
Expand Down Expand Up @@ -68,7 +70,7 @@ def parse_pbobject(source, pb_class):
pb_object.ParseFromString(source)
return pb_object
else:
logging.error(f'cannot parse type {type(source)}')
logger.error(f'cannot parse type {type(source)}')


def open_remote_pb_object(s3_object_uri, pb_class):
Expand Down Expand Up @@ -154,20 +156,20 @@ def open_ontology_pbobject(ontology_file):
try:
ontology = parse_pbobject(ontology_file, OntologyV2Pb2)
if ontology is not None:
logging.info('Successfully loaded Ontology V2 spec.')
logger.debug('Successfully loaded Ontology V2 spec.')
return ontology
except Exception:
logging.error('Failed to load ontology file with V2 spec, trying V1 spec.')
logger.error('Failed to load ontology file with V2 spec, trying V1 spec.')
try:
ontology = parse_pbobject(ontology_file, OntologyV1Pb2)
if ontology is not None:
logging.info('Successfully loaded Ontology V1 spec.')
logger.debug('Successfully loaded Ontology V1 spec.')
return ontology
except Exception:
if isinstance(ontology_file, str):
logging.error('Failed to load ontology file' + ontology_file + 'with V1 spec also, returning None.')
logger.error('Failed to load ontology file' + ontology_file + 'with V1 spec also, returning None.')
else:
logging.error('Failed to load ontology file with V1 spec also, returning None.')
logger.error('Failed to load ontology file with V1 spec also, returning None.')


def open_feature_ontology_pbobject(ontology_file):
Expand All @@ -187,10 +189,10 @@ def open_feature_ontology_pbobject(ontology_file):
try:
ontology = open_pbobject(ontology_file, FeatureOntologyPb2)
if ontology is not None:
logging.info('Successfully loaded FeatureOntology spec.')
logger.debug('Successfully loaded FeatureOntology spec.')
return ontology
except Exception:
logging.error('Failed to load ontology file' + ontology_file + '.')
logger.error('Failed to load ontology file' + ontology_file + '.')


def generate_uid_from_pbobject(pb_object):
Expand Down
Loading