| 3133 | } |
| 3134 | |
| 3135 | static PyObject* RedisLog(PyObject *cls, PyObject *args, PyObject *kargs){ |
| 3136 | PyObject* logLevel = GearsPyDict_GetItemString(kargs, "level"); |
| 3137 | PyObject* logMsg = NULL; |
| 3138 | if(PyTuple_Size(args) < 1 || PyTuple_Size(args) > 2){ |
| 3139 | PyErr_SetString(GearsError, "log function must get a log message as input"); |
| 3140 | return NULL; |
| 3141 | } |
| 3142 | if(PyTuple_Size(args) == 2){ |
| 3143 | RedisModule_Log(staticCtx, "warning", "Specify log level as the first argument to log function is depricated, use key argument 'level' instead"); |
| 3144 | logLevel = PyTuple_GetItem(args, 0); |
| 3145 | logMsg = PyTuple_GetItem(args, 1); |
| 3146 | }else{ |
| 3147 | logMsg = PyTuple_GetItem(args, 0); |
| 3148 | } |
| 3149 | |
| 3150 | if(!PyUnicode_Check(logMsg)){ |
| 3151 | PyErr_SetString(GearsError, "Log message must be a string"); |
| 3152 | return NULL; |
| 3153 | } |
| 3154 | |
| 3155 | const char* logMsgCStr = PyUnicode_AsUTF8AndSize(logMsg, NULL); |
| 3156 | const char* logLevelCStr = "notice"; |
| 3157 | |
| 3158 | if(logLevel){ |
| 3159 | if(!PyUnicode_Check(logLevel)){ |
| 3160 | PyErr_SetString(GearsError, "Log level must be a sting (debug/verbose/notice/warning)"); |
| 3161 | return NULL; |
| 3162 | } |
| 3163 | logLevelCStr = PyUnicode_AsUTF8AndSize(logLevel, NULL); |
| 3164 | if(strcmp(logLevelCStr, "debug") != 0 && |
| 3165 | strcmp(logLevelCStr, "verbose") != 0 && |
| 3166 | strcmp(logLevelCStr, "notice") != 0 && |
| 3167 | strcmp(logLevelCStr, "warning") != 0){ |
| 3168 | PyErr_SetString(GearsError, "Log level should be one of the following : debug,verbose,notice,warning"); |
| 3169 | return NULL; |
| 3170 | } |
| 3171 | } |
| 3172 | |
| 3173 | RedisModule_Log(staticCtx, logLevelCStr, "GEARS: %s", logMsgCStr); |
| 3174 | Py_INCREF(Py_None); |
| 3175 | return Py_None; |
| 3176 | } |
| 3177 | |
| 3178 | static RedisModuleString** createArgs(PyObject *args){ |
| 3179 | // Declare and initialize variables for arguments processing. |
nothing calls this directly
no test coverage detected