def after_request(response): writeInstanceLog( getUserId(), 'Request url: ' + request.url + ', request data: ' + request.data, LOG_LVL_INFO) response.headers.add('Access-Control-Allow-Origin', '*') response.headers.add('Access-Control-Allow-Headers', 'Content-Type, Authorization') response.headers.add('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE') writeInstanceLog( getUserId(), 'Status_code: ' + unicode(response.status_code) + ', ' 'response: ' + unicode(response.response)[:2000], LOG_LVL_INFO) return response
def after_request(response): writeInstanceLog(getUserId(), 'Request url: ' + request.url + ', request data: ' + request.data, LOG_LVL_INFO) response.headers.add('Access-Control-Allow-Origin', '*') response.headers.add('Access-Control-Allow-Headers', 'Content-Type, Authorization') response.headers.add('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE') writeInstanceLog(getUserId(), 'Status_code: ' + unicode(response.status_code) + ', ' 'response: ' + unicode(response.response)[:2000], LOG_LVL_INFO) return response
def testLogLvlIstanceLog(self): writeInstanceLog(TEST_USER_ID, TEST_MSG, LOG_LVL_INFO) obj = list(glog.find().sort('_id', DESCENDING).limit(1))[0] self.assertEqual(obj[TEST_LEVEL_FIELD], LOG_LVL_INFO) writeInstanceLog(TEST_USER_ID, TEST_MSG, LOG_LVL_WARNING) obj = list(glog.find().sort('_id', DESCENDING).limit(1))[0] self.assertEqual(obj[TEST_LEVEL_FIELD], LOG_LVL_WARNING) writeInstanceLog(TEST_USER_ID, TEST_MSG, LOG_LVL_ERROR) obj = list(glog.find().sort('_id', DESCENDING).limit(1))[0] self.assertEqual(obj[TEST_LEVEL_FIELD], LOG_LVL_ERROR) writeInstanceLog(TEST_USER_ID, TEST_MSG, LOG_LVL_CRITICAL) obj = list(glog.find().sort('_id', DESCENDING).limit(1))[0] self.assertEqual(obj[TEST_LEVEL_FIELD], LOG_LVL_CRITICAL)
def enablePlugin(api, pluginName): loadMain = PREFIX_LOAD_MAIN + pluginName + LOAD_MAIN_ENDING try: loadModule = __import__(loadMain, globals(), locals(), [ GET_PLUGIN_RESOURCES], -1) pluginResourcesDict = loadModule.getPluginResources() for pluginResource in pluginResourcesDict: api.add_resource(pluginResourcesDict[pluginResource], getPluginUrl( pluginResource, pluginName)) writeInstanceLog(getUserId(), 'Plugin ' + pluginName + ' successfully loaded', LOG_LVL_INFO) except Exception as e: writeInstanceLog(getUserId(), EXCEPT_ERROR_TEXT + pluginName + ', ' + ERROR_DISR_TEXT + unicode(e) + ' ' + unicode(format_exc()), LOG_LVL_ERROR)
def logUserOut(): if USER_ID in session: SESSION_VALUE = session.pop(USER_ID) writeInstanceLog(SESSION_VALUE, LOGOUT, LOG_LVL_INFO)
def logUserIn(_id, user_login=None): session[USER_ID] = _id if user_login is not None: session[USER_LOGIN] = user_login writeInstanceLog(session[USER_ID], LOGIN, LOG_LVL_INFO)