コード例 #1
0
 def test_hostnameinconfig(self):
     logfile = 'out.log'
     fh = open(logfile, 'w')
     someLogTraces = ['FATAL> something went wrong',
                           'ERROR> not so wrong',
                           'WARN> be careful',
                           'DEBUG> looking behind the scenes',
                           'INFO> the app is running']
     for line in someLogTraces:
         fh.write(line + '\n')
     fh.close()
     logcolors = LogColors()  # using default colors
     termcolors = TermColorCodes()
     target = None
     notifier = notifications.Print(PropertiesMock())
     message = Message(logcolors, target)
     log = Log(logfile)
     log.openLog()
     sys.stdout = MemoryWriter()
     hostname = socket.gethostname()
     for _ in range(len(someLogTraces)):
         line = log.readLine()
         line = line.rstrip()
         level = line.split('>')
         message.parse(line, log)
         output = (hostname + ': ' +
                 logcolors.getLevelColor(level[0]) +
                 line +
                 termcolors.reset)
         notifier.notify(message, log)
         self.assertTrue(output in sys.stdout.captured)
     line = log.readLine()
     self.assertEqual('', line)
     message.parse(line, log)
     self.assertFalse(notifier.notify(message, log))
コード例 #2
0
 def testshouldHaveItsOwnColor(self):
     fh = open('config','w')
     fh.write(self.logname+'='+'green\n')
     fh.close()
     properties = Property('config')
     properties.parse_properties()
     log = Log(self.logname,properties)
     log.openLog()
     self.assertTrue(log.ownOutputColor)
     log.closeLog()
     os.remove(self.config)
コード例 #3
0
 def testReportResumeForTwoDifferentLogs(self):
     log = Log('out.log')
     log2 = Log('out2.log')
     arrayLogs = [log, log2]
     fh = log.openLog()
     logcolors = LogColors()
     message = Message(logcolors)
     resume = reporting.Resume(arrayLogs)
     for anylog in arrayLogs:
         self.readAndUpdateLines(anylog, message, resume)
     outlogReport = resume.logsReport[log.path]
     expectedOutLogErrorReport = 'error> not so wrong'
     gotLogTrace = outlogReport['ERROR'][0].split('=>> ')[1]
     self.assertEquals(expectedOutLogErrorReport, gotLogTrace)
コード例 #4
0
ファイル: test_resume.py プロジェクト: qrees/log4tailer
 def testReportResumeForTwoDifferentLogs(self):
     log = Log('out.log')
     log2 = Log('out2.log')
     arrayLogs = [log, log2]
     fh = log.openLog()
     logcolors = LogColors()
     message = Message(logcolors)
     resume = reporting.Resume(arrayLogs)
     for anylog in arrayLogs:
         self.readAndUpdateLines(anylog, message, resume)
     outlogReport = resume.logsReport[log.path]
     expectedOutLogErrorReport = 'error> not so wrong'
     gotLogTrace = outlogReport['ERROR'][0].split('=>> ')[1]
     self.assertEquals(expectedOutLogErrorReport,
             gotLogTrace)
コード例 #5
0
    def testMessage(self):
        logcolors = LogColors()  # using default colors
        termcolors = TermColorCodes()
        target = None
        notifier = notifications.Print()
        message = Message(logcolors, target)
        log = Log(self.logfile)
        log.openLog()
        sys.stdout = MemoryWriter()
        #testing Colors with default pauseModes
        for count in range(len(self.someLogTraces)):
            line = log.readLine()
            line = line.rstrip()
            level = line.split('>')
            message.parse(line, log)
            output = (logcolors.getLevelColor(level[0]) + line +
                    termcolors.reset)
            notifier.notify(message, log)
            self.assertTrue(output in sys.stdout.captured)

        line = log.readLine()
        self.assertEqual('', line)
        message.parse(line, log)
        self.assertFalse(notifier.notify(message, log))
コード例 #6
0
 def openLog(self):
     log = Log(self.logname)
     log.openLog()
     return log