From 8111b77e95b083137faf888aeb5892073adf7ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 27 Jun 2018 16:59:37 +0200 Subject: New upstream version 2.0.0 --- modules/modpy/Makefile.am | 4 ++-- modules/modpy/interface.cpp | 23 +++++++++-------------- modules/modpy/py.cpp | 32 +++++++++++++------------------- modules/modpy/py.h | 2 ++ 4 files changed, 26 insertions(+), 35 deletions(-) (limited to 'modules') diff --git a/modules/modpy/Makefile.am b/modules/modpy/Makefile.am index eccb2a2..231031a 100644 --- a/modules/modpy/Makefile.am +++ b/modules/modpy/Makefile.am @@ -10,8 +10,8 @@ mod_py_la_SOURCES = \ py.h py.cpp \ interface.h interface.cpp -AM_CPPFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir)/src \ - ${PYTHON_INCLUDES} ${libconfig_CFLAGS} ${log4cpp_CFLAGS} +AM_CPPFLAGS = -std=c++11 -I$(top_srcdir)/lib -I$(top_srcdir)/src \ + ${PYTHON_INCLUDES} ${libconfig_CFLAGS} mod_py_la_LIBADD = ${PYTHON_LIBS} endif diff --git a/modules/modpy/interface.cpp b/modules/modpy/interface.cpp index 948fa5c..60e1c7b 100644 --- a/modules/modpy/interface.cpp +++ b/modules/modpy/interface.cpp @@ -19,10 +19,11 @@ #include "interface.h" -#include #include #include -#include +#include + +static auto _logger = spdlog::get( "bitz-server" ); PyObject * bitz_get_request( PyObject * self, PyObject * pyrequest ) { @@ -31,9 +32,7 @@ PyObject * bitz_get_request( PyObject * self, PyObject * pyrequest ) { PyObject * pypayload; icap::Request * request; - // logger - bitz::Logger &logger = bitz::Logger::instance(); - logger.debug( "[modpy.interface] get_request()" ); + _logger->debug( "[modpy.interface] get_request()" ); // initialise return dictionary pyreturn = PyDict_New(); @@ -65,7 +64,7 @@ PyObject * bitz_get_request( PyObject * self, PyObject * pyrequest ) { Py_DECREF( pypayload ); } else { - logger.warn( "[modpy.interface] failed to get request object pointer" ); + _logger->warn( "[modpy.interface] failed to get request object pointer" ); } return pyreturn; @@ -80,15 +79,13 @@ PyObject * bitz_get_response_from_status( PyObject * self, PyObject * args ) { unsigned int resp_status; - // logger - bitz::Logger &logger = bitz::Logger::instance(); - logger.debug( "[modpy.interface] get_response_from_status()" ); + _logger->debug( "[modpy.interface] get_response_from_status()" ); // parse args if ( PyArg_ParseTuple( args, "I", &resp_status ) ) { response = new icap::Response( (icap::ResponseHeader::status_t) resp_status ); } else { - logger.warn( "[modpy.interface] failed to parse arguments" ); + _logger->warn( "[modpy.interface] failed to parse arguments" ); response = new icap::Response( icap::ResponseHeader::SERVER_ERROR ); } @@ -114,9 +111,7 @@ PyObject * bitz_get_response( PyObject * self, PyObject * args ) { Py_ssize_t pybuflen; - // logger - bitz::Logger &logger = bitz::Logger::instance(); - logger.debug( "[modpy.interface] get_response()" ); + _logger->debug( "[modpy.interface] get_response()" ); // parse args if ( PyArg_ParseTuple( args, "IO!", &resp_status, &PyDict_Type, &pypayload ) ) { @@ -142,7 +137,7 @@ PyObject * bitz_get_response( PyObject * self, PyObject * args ) { response->payload( payload ); } else { - logger.warn( "[modpy.interface] failed to parse arguments" ); + _logger->warn( "[modpy.interface] failed to parse arguments" ); } // sanity check diff --git a/modules/modpy/py.cpp b/modules/modpy/py.cpp index 51cb38f..a1d330d 100644 --- a/modules/modpy/py.cpp +++ b/modules/modpy/py.cpp @@ -21,7 +21,6 @@ #include "interface.h" #include -#include namespace bitz { @@ -35,6 +34,9 @@ namespace bitz { _config.module_name = "modpy"; _config.module_path = ""; + // logger + _logger = spdlog::get( "bitz-server" ); + // load configs load_configs(); @@ -92,21 +94,19 @@ namespace bitz { PyObject * pymethod; PyObject * pyreturn; - // logger - Logger &logger = Logger::instance(); // python core Py_Initialize(); // bitz python module if ( Py_InitModule( "bitz", bitz_methods ) == NULL ) { - logger.warn( "[modpy] failed to init C interface module: bitz" ); + _logger->warn( "[modpy] failed to init C interface module: bitz" ); } // setup python environment if ( _config.module_path != "" ) { - logger.debug( std::string( "[modpy] appending to sys.path, module_path: " ).append( _config.module_path ) ); + _logger->debug( std::string( "[modpy] appending to sys.path, module_path: " ).append( _config.module_path ) ); sys_path = PySys_GetObject( (char *) "path" ); pymodule_path = PyString_FromString( _config.module_path.c_str() ); @@ -115,14 +115,14 @@ namespace bitz { } // load the interface module - logger.debug( std::string( "[modpy] interface module: " ).append( _config.module_name ) ); + _logger->debug( std::string( "[modpy] interface module: " ).append( _config.module_name ) ); pymodule_name = PyString_FromString( _config.module_name.c_str() ); _pymodule = PyImport_Import( pymodule_name ); if ( _pymodule != NULL ) { - logger.debug( "[modpy] interface module loaded successfully" ); + _logger->debug( "[modpy] interface module loaded successfully" ); // call init() in the interface module pymethod = PyObject_GetAttrString( _pymodule, "init" ); @@ -131,13 +131,13 @@ namespace bitz { pyreturn = PyObject_CallObject( pymethod, NULL ); Py_DECREF( pyreturn ); } else { - logger.warn ( "[modpy] failed to call init() in interface module" ); + _logger->warn ( "[modpy] failed to call init() in interface module" ); } Py_DECREF( pymethod ); } else { - logger.warn( "[modpy] failed to load interface module" ); + _logger->warn( "[modpy] failed to load interface module" ); } @@ -154,9 +154,6 @@ namespace bitz { PyObject * pymethod; PyObject * pyreturn; - // logger - Logger &logger = Logger::instance(); - // cleanup if ( _pymodule != NULL ) { @@ -168,7 +165,7 @@ namespace bitz { pyreturn = PyObject_CallObject( pymethod, NULL ); Py_DECREF( pyreturn ); } else { - logger.warn ( "[modpy] failed to call cleanup() in interface module" ); + _logger->warn ( "[modpy] failed to call cleanup() in interface module" ); } Py_DECREF( pymethod ); @@ -199,9 +196,6 @@ namespace bitz { PyObject * pyargs; PyObject * pyrequest, * pyresponse; - // logger - Logger &logger = Logger::instance(); - // initialise the response object response = NULL; @@ -231,18 +225,18 @@ namespace bitz { response = static_cast(p); } else { - logger.warn( std::string( "[modpy] invalid capsule response, method: " ).append( method ) ); + _logger->warn( std::string( "[modpy] invalid capsule response, method: " ).append( method ) ); } Py_DECREF( pyresponse ); } else { - logger.warn( std::string( "[modpy] response is NULL, method: " ).append( method ) ); + _logger->warn( std::string( "[modpy] response is NULL, method: " ).append( method ) ); } } else { - logger.warn ( std::string( "[modpy] failed to call the method in interface module, method: " ).append( method ) ); + _logger->warn ( std::string( "[modpy] failed to call the method in interface module, method: " ).append( method ) ); } // cleanup diff --git a/modules/modpy/py.h b/modules/modpy/py.h index 358c36f..f171063 100644 --- a/modules/modpy/py.h +++ b/modules/modpy/py.h @@ -23,6 +23,7 @@ #include #include +#include namespace bitz { @@ -44,6 +45,7 @@ namespace bitz { private: config_t _config; PyObject * _pymodule; + std::shared_ptr _logger; void load_configs() throw(); void init_python() throw(); -- cgit v1.2.3