pinkavaj commented on a change in pull request #7713:
URL: https://github.com/apache/pulsar/pull/7713#discussion_r562161863
##########
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:
The file and line information is not logged, but I'm not familiar with
the code enought to decide what is more appropriate. From the point of
developer I would preffer the file and line information in the log message.
Probably someone more familiar with this code should speek his opinion.
Otherwise looks good.
----------------------------------------------------------------
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]