Bklyn commented on a change in pull request #7713:
URL: https://github.com/apache/pulsar/pull/7713#discussion_r595179081



##########
File path: pulsar-client-cpp/python/src/config.cc
##########
@@ -74,6 +74,107 @@ static ClientConfiguration& 
ClientConfiguration_setAuthentication(ClientConfigur
     return conf;
 }
 
+class LoggerWrapper: public Logger {
+    std::string _logger;
+    PyObject* _pyLogger;
+    int _currentPythonLogLevel = _getLogLevelValue(Logger::LEVEL_INFO);
+
+    void _updateCurrentPythonLogLevel() {
+        PyGILState_STATE state = PyGILState_Ensure();
+
+        try {
+            _currentPythonLogLevel = py::call_method<int>(_pyLogger, 
"getEffectiveLevel");
+        } catch (py::error_already_set e) {
+            PyErr_Print();
+        }
+
+        PyGILState_Release(state);
+    };
+
+    int _getLogLevelValue(Level level) {
+        return 10 + (level * 10);
+    }
+
+   public:
+
+    LoggerWrapper(const std::string &logger, PyObject* pyLogger) : 
_logger(logger) {
+        _pyLogger = pyLogger;
+        Py_XINCREF(_pyLogger);
+
+        _updateCurrentPythonLogLevel();
+    }
+
+    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) {
+        return _getLogLevelValue(level) >= _currentPythonLogLevel;
+    }
+
+    void log(Level level, int line, const std::string& message) {

Review comment:
       Not having this info only truly matters if the Python `Logger` is 
connected ultimately to one or more `Formatter`s that has tokens like 
`filename`, `pathname` or `lineno` in its format string.
   
   It _should_ be possible to create a `LogRecord` object 
(https://docs.python.org/3/library/logging.html#logrecord-objects) and pass it 
to `Logger.handle` method instead of using the simpler `info`, `warning` etc 
methods.  I for one think it is not worth the trouble and the implementation is 
fine as-is.




----------------------------------------------------------------
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:
[email protected]


Reply via email to