def testUpperStackLogging(self): """Tests whether we can define logger at client level and log before and after the API request is made.""" logger = logging.getLogger('LoggerTest') logger.setLevel(logging.DEBUG) fh = logging.FileHandler(self.__class__.TMP_LOG) fh.setLevel(logging.DEBUG) logger.addHandler(fh) # Clean up temporary log file. Utils.PurgeLog(self.__class__.TMP_LOG) logger.debug(self.__class__.DEBUG_MSG1) info_service = client.GetInfoService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) selector = { 'apiUsageType': 'TOTAL_USAGE_API_UNITS_PER_MONTH' } info_service.Get(selector) logger.debug(self.__class__.DEBUG_MSG2) data = Utils.ReadFile(self.__class__.TMP_LOG) self.assertEqual(data.find(self.__class__.DEBUG_MSG1), 0) self.assertEqual(data.find(self.__class__.DEBUG_MSG2), len(self.__class__.DEBUG_MSG1) + 1) # Clean up and remove temporary log file. Utils.PurgeLog(self.__class__.TMP_LOG) os.remove(self.__class__.TMP_LOG)
def testUpperStackLogging(self): """Tests whether we can define logger at client level and log before and after the API request is made.""" logger = logging.getLogger('LoggerTest') logger.setLevel(logging.DEBUG) fh = logging.FileHandler(self.__class__.TMP_LOG) fh.setLevel(logging.DEBUG) logger.addHandler(fh) # Clean up temporary log file. Utils.PurgeLog(self.__class__.TMP_LOG) logger.debug(self.__class__.DEBUG_MSG1) account_service = client.GetAccountService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) account_service.GetAccountInfo() logger.debug(self.__class__.DEBUG_MSG2) data = Utils.ReadFile(self.__class__.TMP_LOG) self.assertEqual(data.find(self.__class__.DEBUG_MSG1), 0) self.assertEqual(data.find(self.__class__.DEBUG_MSG2), len(self.__class__.DEBUG_MSG1) + 1) # Clean up and remove temporary log file. Utils.PurgeLog(self.__class__.TMP_LOG) os.remove(self.__class__.TMP_LOG)