Skip to content

Commit

Permalink
feat: switch logger to non-root logger in protobuf (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisochoatri authored Dec 22, 2023
1 parent 82d431f commit 76e34d2
Showing 1 changed file with 10 additions and 8 deletions.
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

0 comments on commit 76e34d2

Please sign in to comment.