def test_02setShowThreadIDsHeaders(self): """ Create a subsubsublogger and create a logrecord """ gLogger.showHeaders(False) gLogger.showThreadIDs(False) gLogger.notice('message') self.assertEqual("message\n", self.buffer.getvalue()) self.buffer.truncate(0) gLogger.showHeaders(False) gLogger.showThreadIDs(True) gLogger.notice('message') self.assertEqual("message\n", self.buffer.getvalue()) self.buffer.truncate(0) gLogger.showHeaders(True) gLogger.showThreadIDs(False) gLogger.notice('message') logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFrameworkNOTICE:message\n", logstring1) self.buffer.truncate(0) gLogger.showHeaders(True) gLogger.showThreadIDs(True) gLogger.notice('message') logstring1 = cleaningLog(self.buffer.getvalue()) self.assertIn(str(thread.get_ident()), logstring1) self.buffer.truncate(0)
def test_01displayLogs(self): """ Test the display of the logs according to the value of the boolean in the method. """ # Enabled gLogger.enableLogsFromExternalLibs() # modify the output to capture logs of the root logger bufferRoot = StringIO() logging.getLogger().handlers[0].stream = bufferRoot logging.getLogger().info("message") logstring1 = cleaningLog(bufferRoot.getvalue()) self.assertEqual("UTCExternalLibrary/rootINFO:message\n", logstring1) bufferRoot.truncate(0) # this is a direct child of root, as the logger in DIRAC logging.getLogger("sublog").info("message") logstring1 = cleaningLog(bufferRoot.getvalue()) self.assertEqual("UTCExternalLibrary/sublogINFO:message\n", logstring1) bufferRoot.truncate(0) # Disabled gLogger.disableLogsFromExternalLibs() logging.getLogger().info("message") # this is a direct child of root, as the logger in DIRAC logging.getLogger("sublog").info("message") self.assertEqual("", bufferRoot.getvalue())
def test_07fatal(self): """ Create Fatal log and test it """ gLogger.fatal("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFrameworkFATAL:message\n", logstring1) self.buffer.truncate(0) self.log.fatal("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFramework/logFATAL:message\n", logstring1) self.buffer.truncate(0)
def test_04debug(self): """ Create Debug log and test it """ gLogger.debug("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFrameworkDEBUG:message\n", logstring1) self.buffer.truncate(0) self.log.debug("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFramework/logDEBUG:message\n", logstring1) self.buffer.truncate(0)
def test_01notice(self): """ Create Notice log and test it """ gLogger.notice("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFrameworkNOTICE:message\n", logstring1) self.buffer.truncate(0) self.log.notice("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFramework/logNOTICE:message\n", logstring1) self.buffer.truncate(0)
def test_02info(self): """ Create Info log and test it """ gLogger.info("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFrameworkINFO:message\n", logstring1) self.buffer.truncate(0) self.log.info("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFramework/logINFO:message\n", logstring1) self.buffer.truncate(0)
def test_06error(self): """ Create Error log and test it """ gLogger.error("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFrameworkERROR:message\n", logstring1) self.buffer.truncate(0) self.log.error("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFramework/logERROR:message\n", logstring1) self.buffer.truncate(0)
def test_00always(self): """ Create Always log and test it """ gLogger.always("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFrameworkALWAYS:message\n", logstring1) self.buffer.truncate(0) self.log.always("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFramework/logALWAYS:message\n", logstring1) self.buffer.truncate(0)
def test_05warn(self): """ Create Warn log and test it """ gLogger.warn("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFrameworkWARN:message\n", logstring1) self.buffer.truncate(0) self.log.warn("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFramework/logWARN:message\n", logstring1) self.buffer.truncate(0)
def test_11WithVarMsg(self): """ Create Always log with variable message and test it """ self.log.always("mess", "age") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual(logstring1, "UTCFramework/logALWAYS:message\n") self.buffer.truncate(0)
def test_10onMultipleLines(self): """ Create Always log on multiple lines and test it """ self.log.always('this\nis\na\nmessage\non\nmultiple\nlines.') logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual(logstring1, "UTCFramework/logALWAYS:this\nis\na\nmessage\non\nmultiple\nlines.\n") self.buffer.truncate(0)
def test_09WithExtrasArgs(self): """ Create Always log with extra arguments and test it """ self.log.always('%s.' % "message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual(logstring1, "UTCFramework/logALWAYS:message.\n") self.buffer.truncate(0)
def test_03verbose(self): """ Create Verbose log and test it Differences between the two systems : - gLogger: VERBOSE """ gLogger.verbose("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFrameworkVERBOSE:message\n", logstring1) self.buffer.truncate(0) self.log.verbose("message") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFramework/logVERBOSE:message\n", logstring1) self.buffer.truncate(0)
def test_14showStack(self): """ Get the showStack """ gLogger.showStack() logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual(logstring1, "UTCFrameworkDEBUG:\n") self.buffer.truncate(0)
def test_01setShowThreadIDs(self): """ Set the thread ID """ gLogger.showThreadIDs(False) gLogger.notice('message') logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFrameworkNOTICE:message\n", logstring1) self.buffer.truncate(0) gLogger.showThreadIDs(True) gLogger.notice('message') logstring1 = cleaningLog(self.buffer.getvalue()) self.assertIn(str(thread.get_ident()), logstring1) self.buffer.truncate(0)
def test_00setShowHeaders(self): """ Set the headers """ gLogger.showHeaders(False) gLogger.notice('message', 'varmessage') self.assertEqual("message varmessage\n", self.buffer.getvalue()) self.buffer.truncate(0) gLogger.showHeaders(True) gLogger.notice('message') logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual("UTCFrameworkNOTICE:message\n", logstring1) self.buffer.truncate(0)
def test_03setSubLogShowHeaders(self): """ Create a sublogger and set it its own Header option. """ sublog = gLogger.getSubLogger('sublog') sublog.setLevel('notice') sublog.showHeaders(False) sublog.registerBackend('file', {'FileName': self.filename}) # Empty the buffer to remove the Object Loader log message "trying to load..." self.buffer.truncate(0) sublog.notice("message") with open(self.filename) as file: message = file.read() self.assertEqual(message, "message\n") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual(logstring1, "UTCFramework/sublogNOTICE:message\n")
def test_06setSubLoggLoggerShowHeadersInverse(self): """ Create a sublogger, set the Header option of the gLogger and its Header option. Show that the gLogger Header option do not follow the change of its child Header option. """ sublog = gLogger.getSubLogger('sublog4') sublog.setLevel('notice') sublog.registerBackend('file', {'FileName': self.filename}) # Empty the buffer to remove the Object Loader log message "trying to load..." self.buffer.truncate(0) gLogger.showHeaders(True) sublog.showHeaders(False) sublog.notice("message") with open(self.filename) as file: message = file.read() self.assertEqual(message, "message\n") logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual(logstring1, "UTCFramework/sublog4NOTICE:message\n")
def test_09subLogShowHeadersChangeSetSubLogger(self): """ Create a subsublogger and set its Header option and show that its Header option do not follow the change of its parent Header option. """ sublog = gLogger.getSubLogger('sublog7') sublog.setLevel('notice') sublog.registerBackend('file', {'FileName': self.filename}) # Empty the buffer to remove the Object Loader log message "trying to load..." self.buffer.truncate(0) subsublog = sublog.getSubLogger('subsublog') subsublog.registerBackends(['file'], {'FileName': self.filename}) # Empty the buffer to remove the Object Loader log message "trying to load..." self.buffer.truncate(0) sublog.showHeaders(False) subsublog.showHeaders(True) subsublog.notice("message") with open(self.filename) as file: message = file.read() self.assertIn("UTC Framework/sublog7/subsublog NOTICE: message\nmessage\n", message) logstring1 = cleaningLog(self.buffer.getvalue()) self.assertEqual(logstring1, "UTCFramework/sublog7/subsublogNOTICE:message\n")