You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/10/25 20:45:27 UTC

[GitHub] jerrypeng commented on a change in pull request #2847: Cleanup Logging for python functions

jerrypeng commented on a change in pull request #2847: Cleanup Logging for python functions
URL: https://github.com/apache/pulsar/pull/2847#discussion_r228328314
 
 

 ##########
 File path: pulsar-functions/instance/src/main/python/util.py
 ##########
 @@ -36,38 +36,33 @@
 def import_class(from_path, full_class_name):
   from_path = str(from_path)
   full_class_name = str(full_class_name)
-  kclass = import_class_from_path(from_path, full_class_name)
-  if kclass is None:
+  try:
+    return import_class_from_path(from_path, full_class_name)
+  except Exception as e:
     our_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
     api_dir = os.path.join(our_dir, PULSAR_API_ROOT, PULSAR_FUNCTIONS_API_ROOT)
-    kclass = import_class_from_path(api_dir, full_class_name)
-  return kclass
+    try:
+      return import_class_from_path(api_dir, full_class_name)
+    except Exception as e:
+      Log.info("Failed to import class %s from path %s" % (full_class_name, from_path))
+      Log.info(e, exc_info=True)
+      return None
 
 def import_class_from_path(from_path, full_class_name):
-  Log.info('Trying to import %s from path %s' % (full_class_name, from_path))
+  Log.debug('Trying to import %s from path %s' % (full_class_name, from_path))
   split = full_class_name.split('.')
   classname_path = '.'.join(split[:-1])
   class_name = full_class_name.split('.')[-1]
   if from_path not in sys.path:
-    Log.info("Add a new dependency to the path: %s" % from_path)
+    Log.debug("Add a new dependency to the path: %s" % from_path)
     sys.path.insert(0, from_path)
   if not classname_path:
-    try:
-      mod = importlib.import_module(class_name)
-      return mod
-    except Exception as e:
-      Log.info("Import failed class_name %s from path %s" % (class_name, from_path))
-      Log.info(e, exc_info=True)
-      return None
+    mod = importlib.import_module(class_name)
 
 Review comment:
   Can an exception be thrown here?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services