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 2019/09/26 06:21:02 UTC

[GitHub] [pulsar] BlackJohnny commented on a change in pull request #5279: Support for python native logging from python wrapper

BlackJohnny commented on a change in pull request #5279: Support for python native logging from python wrapper
URL: https://github.com/apache/pulsar/pull/5279#discussion_r328450563
 
 

 ##########
 File path: pulsar-client-cpp/python/src/config.cc
 ##########
 @@ -18,6 +18,99 @@
  */
 #include "utils.h"
 
+class LoggerWrapper: public Logger {
+    std::string _logger;
+    PyObject* _pyLogger;
+
+public:
+
+    LoggerWrapper(const std::string &logger, PyObject* pyLogger) : _logger(logger) {
+        _pyLogger = pyLogger;
+        Py_XINCREF(_pyLogger);
+    }
+
+    LoggerWrapper(const LoggerWrapper& other) {
+        _pyLogger = other._pyLogger;
+        Py_XINCREF(_pyLogger);
+    }
+
+    LoggerWrapper& operator=(const LoggerWrapper& other) {
+        _pyLogger = other._pyLogger;
+        Py_XINCREF(_pyLogger);
+        return *this;
+    }
+
+    virtual ~LoggerWrapper() {
+        Py_XDECREF(_pyLogger);
+    }
+
+    bool isEnabled(Level level) {
 
 Review comment:
   Thank you for the suggestion! It seems to me that `RateLimiter` blocks the caller and I think that it's not the intended behavior. Please correct me if I am wrong.
   
   Taking into account that in real life you would not want to change the level at run-time very often, I propose the following options:
   
   **Solution 1**:
   * Initialize a class member `currentLoggingLevel` during the construction of the Logger, by calling the python's "logger.getEffectiveLevel()". Then never update this value. This would imply that whenever the python programmer wants to change the logging behavior he would have to recycle the Client object.
   
   **Solution 2**:
   * Add an internal counter to the logger and only forward the call to python each Nth time `Logger::isEnabled` is called.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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