コード例 #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
ファイル: test_postnotifier.py プロジェクト: qrees/log4tailer
 def test_shouldPost_if_alertable(self):
     logcolors = LogColors()
     logtrace = 'this is an error log trace'
     log = Log('anylog')
     message = Message(logcolors)
     message.parse(logtrace, log)
     poster = notifications.Poster(PropertiesStub(), http_conn=HttpConnStub)
     body = poster.notify(message, log)
     self.assertTrue(body)
コード例 #3
0
ファイル: test_postnotifier.py プロジェクト: qrees/log4tailer
 def test_execute_if_targetMessage(self):
     logcolors = LogColors()
     logtrace = 'this is a target log trace'
     log = Log('anylog')
     message = Message(logcolors, target='trace')
     message.parse(logtrace, log)
     poster = notifications.Poster(PropertiesStub(), http_conn=HttpConnStub)
     poster.registered_logs[log] = {'id': 1, 'logserver': "anything"}
     body = poster.notify(message, log)
     self.assertTrue(body)
コード例 #4
0
ファイル: test_postnotifier.py プロジェクト: qrees/log4tailer
 def test_shouldPost_if_alertable(self):
     logcolors = LogColors()
     logtrace = 'this is an error log trace'
     log = Log('anylog')
     message = Message(logcolors)
     message.parse(logtrace, log)
     poster = notifications.Poster(PropertiesStub(), 
             http_conn=HttpConnStub)
     body = poster.notify(message, log)
     self.assertTrue(body)
コード例 #5
0
ファイル: test_printshot.py プロジェクト: qrees/log4tailer
 def test_printandshoot_notalertable(self):
     log_trace = 'this is an info log trace'
     log = Log('anylog')
     logcolors = LogColors()
     caller = SubProcessStubPopen()
     printandshoot = notifications.PrintShot(PropertiesStub(),
             caller=caller)
     message = Message(logcolors)
     message.parse(log_trace, log)
     printandshoot.notify(message, log)
     self.assertFalse(sys.stdout.contains(SubProcessStubPopen.msg))
コード例 #6
0
 def test_printandshoot_notalertable(self):
     log_trace = 'this is an info log trace'
     log = Log('anylog')
     logcolors = LogColors()
     caller = SubProcessStubPopen()
     printandshoot = notifications.PrintShot(PropertiesStub(),
                                             caller=caller)
     message = Message(logcolors)
     message.parse(log_trace, log)
     printandshoot.notify(message, log)
     self.assertFalse(sys.stdout.contains(SubProcessStubPopen.msg))
コード例 #7
0
ファイル: test_postnotifier.py プロジェクト: qrees/log4tailer
 def test_execute_if_targetMessage(self):
     logcolors = LogColors()
     logtrace = 'this is a target log trace'
     log = Log('anylog')
     message = Message(logcolors, target='trace')
     message.parse(logtrace, log)
     poster = notifications.Poster(PropertiesStub(),
             http_conn=HttpConnStub)
     poster.registered_logs[log] = {'id' : 1, 'logserver' :
             "anything"}
     body = poster.notify(message, log)
     self.assertTrue(body)
コード例 #8
0
 def testnoNotification(self):
     pattern = re.compile(r'hi, this line to be notified')
     trace = "info this is just a log trace"
     notifier = notifications.Filter(pattern)
     sys.stdout = MemoryWriter()
     logcolors = LogColors()
     message = Message(logcolors)
     anylog = Log('out.log')
     message.parse(trace, anylog)
     notifier.notify(message, anylog)
     # assert is empty
     self.assertFalse(sys.stdout.captured)
コード例 #9
0
 def testnoNotification(self):
     pattern = re.compile(r'hi, this line to be notified')
     trace = "info this is just a log trace"
     notifier = notifications.Filter(pattern)
     sys.stdout = MemoryWriter()
     logcolors = LogColors()
     message = Message(logcolors)
     anylog = Log('out.log')
     message.parse(trace, anylog)
     notifier.notify(message, anylog)
     # assert is empty
     self.assertFalse(sys.stdout.captured)
コード例 #10
0
 def test_trace_level(self):
     level = 'TRACE'
     trace = "TRACE level for finer informational log traces than DEBUG"
     sys.stdout = MemoryWriter()
     logcolors = LogColors()
     termcolors = TermColorCodes()
     message = Message(logcolors)
     notifier = notifications.Print()
     anylog = Log('out.log')
     message.parse(trace, anylog)
     output = logcolors.getLevelColor(level) + trace + termcolors.reset
     notifier.notify(message, anylog)
     self.assertEqual(output, sys.stdout.captured[0])
コード例 #11
0
ファイル: test_executor.py プロジェクト: qrees/log4tailer
 def testShouldNotExecuteIfLevelNotInPullers(self):
     logcolor = LogColors()
     message = Message(logcolor)
     log = Log('anylog')
     command = 'anything %s %s'
     trace = "this is an info log trace"
     properties = PropertiesStub(command)
     executor = notifications.Executor(properties,
                                       trigger_executor=TriggerExecutorStub)
     message.parse(trace, log)
     executor.notify(message, log)
     len_captured_lines = len(sys.stdout.captured)
     self.assertEqual(len_captured_lines, 0)
コード例 #12
0
 def testshouldNotColorizeifLevelKeyInaWord(self):
     # Testing boundary regex as for suggestion of
     # Carlo Bertoldi
     trace = "this is a logtrace where someinfoword could be found"
     sys.stdout = MemoryWriter()
     logcolors = LogColors()
     message = Message(logcolors)
     notifier = notifications.Print()
     anylog = Log('out.log')
     message.parse(trace, anylog)
     notifier.notify(message, anylog)
     self.assertEqual(trace, sys.stdout.captured[0])
     self.assertEqual('', message.messageLevel)
コード例 #13
0
ファイル: test_executor.py プロジェクト: qrees/log4tailer
 def testShouldNotExecuteIfLevelNotInPullers(self):
     logcolor = LogColors()
     message = Message(logcolor)
     log = Log('anylog')
     command = 'anything %s %s'
     trace = "this is an info log trace"
     properties = PropertiesStub(command)
     executor = notifications.Executor(properties,
             trigger_executor=TriggerExecutorStub)
     message.parse(trace, log)
     executor.notify(message, log)
     len_captured_lines = len(sys.stdout.captured)
     self.assertEqual(len_captured_lines, 0)
コード例 #14
0
 def test_printandshoot(self):
     log_trace = 'this is a fatal log trace'
     log = Log('anylog')
     logcolors = LogColors()
     caller = SubProcessStubPopen()
     printandshoot = notifications.PrintShot(PropertiesStub(),
                                             caller=caller)
     message = Message(logcolors)
     message.parse(log_trace, log)
     printandshoot.notify(message, log)
     colorized_logtrace = '\x1b[31mthis is a fatal log trace\x1b[0m'
     self.assertEqual(colorized_logtrace, sys.stdout.captured[0])
     # in [1] has '\n', and [2] should have the result
     self.assertEqual(SubProcessStub.msg, sys.stdout.captured[2])
コード例 #15
0
 def testshouldFailColorizeWithBackground(self):
     trace = "FATAL there could be an error in the application"
     level = 'WARN'
     sys.stdout = MemoryWriter()
     logcolors = LogColors()
     termcolors = TermColorCodes()
     logcolors.parse_config(PropertiesBackGround())
     message = Message(logcolors)
     notifier = notifications.Print()
     anylog = Log('out.log')
     message.parse(trace, anylog)
     output = logcolors.getLevelColor(level) + trace + termcolors.reset
     notifier.notify(message, anylog)
     self.assertNotEqual(output, sys.stdout.captured[0])
コード例 #16
0
ファイル: test_printshot.py プロジェクト: qrees/log4tailer
 def test_printandshoot_throws(self):
     log_trace = 'this is a very fatal log trace'
     log = Log('anylog')
     logcolors = LogColors()
     caller = SubProcessStubRaise()
     printandshoot = notifications.PrintShot(PropertiesStub(),
             caller=caller)
     message = Message(logcolors)
     message.parse(log_trace, log)
     try:
         printandshoot.notify(message, log)
         self.fail()
     except Exception, err:
         self.assertEqual(str(err), SubProcessStubRaise.msg)
コード例 #17
0
 def testShouldColorizeWarningLevelAsWell(self):
     '''test that *warning* keyword gets colorized as well'''
     level = 'WARNING'
     trace = "WARNING there could be an error in the application"
     sys.stdout = MemoryWriter()
     logcolors = LogColors()
     termcolors = TermColorCodes()
     message = Message(logcolors)
     notifier = notifications.Print()
     anylog = Log('out.log')
     message.parse(trace, anylog)
     output = logcolors.getLevelColor(level) + trace + termcolors.reset
     notifier.notify(message, anylog)
     self.assertEqual(output, sys.stdout.captured[0])
コード例 #18
0
 def test_printandshoot_throws(self):
     log_trace = 'this is a very fatal log trace'
     log = Log('anylog')
     logcolors = LogColors()
     caller = SubProcessStubRaise()
     printandshoot = notifications.PrintShot(PropertiesStub(),
                                             caller=caller)
     message = Message(logcolors)
     message.parse(log_trace, log)
     try:
         printandshoot.notify(message, log)
         self.fail()
     except Exception, err:
         self.assertEqual(str(err), SubProcessStubRaise.msg)
コード例 #19
0
ファイル: test_ignoretraces.py プロジェクト: qrees/log4tailer
 def test_notification(self):
     pattern = re.compile(r'this line will not be notified')
     trace = "info hi, but this line will be"
     level = "INFO"
     notifier = notifications.IgnoreAction(pattern)
     sys.stdout = MemoryWriter()
     logcolors = LogColors()
     termcolors = TermColorCodes()
     message = Message(logcolors)
     anylog = Log('out.log')
     message.parse(trace, anylog)
     notifier.notify(message, anylog)
     output = logcolors.getLevelColor(level)+trace+termcolors.reset
     self.assertEqual(output, sys.stdout.captured[0])
コード例 #20
0
ファイル: test_printshot.py プロジェクト: qrees/log4tailer
 def test_printandshoot(self):
     log_trace = 'this is a fatal log trace'
     log = Log('anylog')
     logcolors = LogColors()
     caller = SubProcessStubPopen()
     printandshoot = notifications.PrintShot(PropertiesStub(),
             caller=caller)
     message = Message(logcolors)
     message.parse(log_trace, log)
     printandshoot.notify(message, log)
     colorized_logtrace = '\x1b[31mthis is a fatal log trace\x1b[0m'
     self.assertEqual(colorized_logtrace, sys.stdout.captured[0])
     # in [1] has '\n', and [2] should have the result
     self.assertEqual(SubProcessStub.msg, sys.stdout.captured[2])
コード例 #21
0
ファイル: test_cornermark.py プロジェクト: qrees/log4tailer
 def testWillMarkForSpecifiedTime(self):
     trace = "FATAL there could be an error in the application"
     sys.stdout = MemoryWriter()
     logcolors = LogColors()
     termcolors = TermColorCodes()
     message = Message(logcolors)
     notifier = notifications.CornerMark(10)
     anylog = Log('out.log')
     message.parse(trace, anylog)
     padding = self.ttcols - len(notifier.MARK)
     output = padding * " " + termcolors.backgroundemph + notifier.MARK +\
             termcolors.reset
     notifier.notify(message, anylog)
     self.assertEqual(output, sys.stdout.captured[0])
コード例 #22
0
 def testnotify(self):
     pattern = re.compile(r'hi, this line to be notified')
     trace = "info hi, this line to be notified"
     level = "INFO"
     notifier = notifications.Filter(pattern)
     sys.stdout = MemoryWriter()
     logcolors = LogColors()
     termcolors = TermColorCodes()
     message = Message(logcolors)
     anylog = Log('out.log')
     message.parse(trace, anylog)
     notifier.notify(message, anylog)
     output = logcolors.getLevelColor(level) + trace + termcolors.reset
     self.assertEqual(output, sys.stdout.captured[0])
コード例 #23
0
 def testshouldColorizefirstLevelFoundignoringSecondinSameTrace(self):
     # Test for fix 5
     # Should give priority to FATAL in next trace
     level = 'FATAL'
     trace = "FATAL there could be an error in the application"
     sys.stdout = MemoryWriter()
     logcolors = LogColors()
     termcolors = TermColorCodes()
     message = Message(logcolors)
     notifier = notifications.Print()
     anylog = Log('out.log')
     message.parse(trace, anylog)
     output = (logcolors.getLevelColor(level) + trace + termcolors.reset)
     notifier.notify(message, anylog)
     self.assertEqual(output, sys.stdout.captured[0])
コード例 #24
0
ファイル: test_executor.py プロジェクト: qrees/log4tailer
 def testShouldExecuteIfTargetMessage(self):
     logcolor = LogColors()
     logfile = 'anylog'
     log = Log(logfile)
     command = "echo %s %s"
     trace = "this is an info log trace"
     trigger = ['echo', trace, logfile]
     properties = PropertiesStub(command)
     message = Message(logcolor, target='trace')
     message.parse(trace, log)
     executor = notifications.Executor(properties,
             trigger_executor=TriggerExecutorStub)
     executor.notify(message, log)
     self.assertEqual(TriggerExecutorStub.execute_msg,
             sys.stdout.captured[0])
コード例 #25
0
ファイル: test_executor.py プロジェクト: qrees/log4tailer
 def testShouldExecuteIfTargetMessage(self):
     logcolor = LogColors()
     logfile = 'anylog'
     log = Log(logfile)
     command = "echo %s %s"
     trace = "this is an info log trace"
     trigger = ['echo', trace, logfile]
     properties = PropertiesStub(command)
     message = Message(logcolor, target='trace')
     message.parse(trace, log)
     executor = notifications.Executor(properties,
                                       trigger_executor=TriggerExecutorStub)
     executor.notify(message, log)
     self.assertEqual(TriggerExecutorStub.execute_msg,
                      sys.stdout.captured[0])
コード例 #26
0
ファイル: test_cornermark.py プロジェクト: qrees/log4tailer
 def testMarkedTARGETOverMarkableLevel(self):
     logfile = "/any/path/out.log"
     trace = "this is a FATAL targeted log trace"
     sys.stdout = MemoryWriter()
     logcolors = LogColors()
     termcolors = TermColorCodes()
     notifier = notifications.CornerMark(0.02)
     anylog = Log(logfile, PropertiesStub())
     message = Message(logcolors, properties=PropertiesStub)
     padding = self.ttcols - len(notifier.MARK)
     output = padding * " " + termcolors.oncyanemph + notifier.MARK +\
             termcolors.reset
     message.parse(trace, anylog)
     notifier.notify(message, anylog)
     self.assertEqual(output, sys.stdout.captured[0])
コード例 #27
0
ファイル: sshlogtailer.py プロジェクト: qrees/log4tailer
 def tailer(self):
     '''Stdout multicolor tailer'''
     message = Message(self.logcolors, self.target, self.properties)
     anylog = Log('anylog')
     for hostname in self.hostnames.keys():
         command = self.hostnames[hostname]['command']
         self.logger.debug("command [%s] to be executed in host [%s]" %
                           (command, hostname))
         self.hostnameChannels[hostname]['channel'].exec_command(command)
     try:
         lasthostnameChanged = ""
         while True:
             for hostname in self.hostnames.keys():
                 sshChannel = self.hostnameChannels[hostname]['channel']
                 rr, _, _ = select.select([sshChannel], [], [], 0.0)
                 if len(rr) > 0:
                     lines = sshChannel.recv(4096).split('\n')
                     if hostname != lasthostnameChanged:
                         self.__hostnameChangedHeader(hostname)
                     for line in lines:
                         message.parse(line, anylog)
                         self.actions.notify(message, anylog)
                     lasthostnameChanged = hostname
             self._wait_for(1)
     except:
         print "\nfinishing ..."
         for hostname in self.hostnames.keys():
             sshChannel = self.hostnameChannels[hostname]['channel']
             sshclient = self.hostnameChannels[hostname]['client']
             command = self.hostnames[hostname]['command']
             procidCommand = 'pgrep -f -x ' + '\"' + command + '\"'
             self.logger.debug("procid command [%s]" % procidCommand)
             sshChannel.close()
             stdin, stdout, stderr = sshclient.exec_command(procidCommand)
             res = stdout.readlines()
             if res:
                 procid = res[0].rstrip()
                 self.logger.debug("procid [%s]" % procid)
                 # is process still alive after closing channel?
                 if procid:
                     # kill it
                     killprocid = 'kill -9 ' + procid
                     stdin, stdout, stderr = sshclient.exec_command(
                         killprocid)
             #sshChannel.shutdown(2)
             sshclient.close()
         print "Ended log4tailer, because colors are fun"
         sys.exit()
コード例 #28
0
ファイル: sshlogtailer.py プロジェクト: qrees/log4tailer
 def tailer(self):
     '''Stdout multicolor tailer'''
     message = Message(self.logcolors,self.target,self.properties)
     anylog = Log('anylog')
     for hostname in self.hostnames.keys():
         command = self.hostnames[hostname]['command']
         self.logger.debug("command [%s] to be executed in host [%s]" % (
                           command,hostname))
         self.hostnameChannels[hostname]['channel'].exec_command(command)
     try:
         lasthostnameChanged = ""
         while True:
             for hostname in self.hostnames.keys():
                 sshChannel = self.hostnameChannels[hostname]['channel']
                 rr, _, _ = select.select([sshChannel],[],[],0.0)
                 if len(rr)>0:
                     lines = sshChannel.recv(4096).split('\n')
                     if hostname != lasthostnameChanged:
                         self.__hostnameChangedHeader(hostname)
                     for line in lines:
                         message.parse(line, anylog)
                         self.actions.notify(message, anylog)
                     lasthostnameChanged = hostname
             self._wait_for(1)
     except:
         print "\nfinishing ..."
         for hostname in self.hostnames.keys():
             sshChannel = self.hostnameChannels[hostname]['channel']
             sshclient = self.hostnameChannels[hostname]['client']
             command = self.hostnames[hostname]['command']
             procidCommand = 'pgrep -f -x '+'\"'+command+'\"'
             self.logger.debug("procid command [%s]" % procidCommand)
             sshChannel.close()
             stdin,stdout,stderr = sshclient.exec_command(procidCommand)
             res = stdout.readlines()
             if res:
                 procid = res[0].rstrip()
                 self.logger.debug("procid [%s]" % procid)
                 # is process still alive after closing channel?
                 if procid:
                     # kill it
                     killprocid = 'kill -9 '+procid
                     stdin,stdout,stderr = sshclient.exec_command(killprocid)
             #sshChannel.shutdown(2)
             sshclient.close()
         print "Ended log4tailer, because colors are fun"
         sys.exit()
コード例 #29
0
ファイル: test_cornermark.py プロジェクト: qrees/log4tailer
 def testMarkedFATALMarkedWARNING(self):
     trace = "FATAL this is a fatal trace"
     sys.stdout = MemoryWriter()
     logcolors = LogColors()
     termcolors = TermColorCodes()
     message = Message(logcolors)
     notifier = notifications.CornerMark(0.02)
     anylog = Log('out.log')
     message.parse(trace, anylog)
     notifier.notify(message, anylog)
     padding = self.ttcols - len(notifier.MARK)
     output = padding * " " + termcolors.onyellowemph + notifier.MARK +\
             termcolors.reset
     trace = "WARN this is just a warn"
     message.parse(trace, anylog)
     notifier.notify(message, anylog)
     self.assertEquals(output, sys.stdout.captured[2])
コード例 #30
0
ファイル: test_cornermark.py プロジェクト: qrees/log4tailer
 def testWillMarkforSpecifiedTimeandNotAfterwards(self):
     trace = "FATAL there could be an error in the application"
     sys.stdout = MemoryWriter()
     logcolors = LogColors()
     termcolors = TermColorCodes()
     message = Message(logcolors)
     notifier = notifications.CornerMark(0.01)
     anylog = Log('out.log')
     message.parse(trace, anylog)
     padding = self.ttcols - len(notifier.MARK)
     output = padding * " " + termcolors.backgroundemph + notifier.MARK +\
             termcolors.reset
     notifier.notify(message, anylog)
     self.assertEqual(output, sys.stdout.captured[0])
     trace = "INFO this is an info trace"
     sys.stdout.flush()
     notifier.timer.corner_mark_ellapsed = overgap
     message.parse(trace, anylog)
     notifier.notify(message, anylog)
     self.assertFalse(sys.stdout.captured)
コード例 #31
0
 def test_not_execute_if_not_alertable_Level(self):
     properties = self.mocker.mock()
     properties.get_value('server_url')
     self.mocker.result('localhost')
     properties.get_value('server_port')
     self.mocker.result(8000)
     properties.get_value('server_service_uri')
     self.mocker.result('/')
     properties.get_value('server_service_register_uri')
     self.mocker.result('/register')
     properties.get_value('server_service_unregister_uri')
     self.mocker.result('/unregister')
     logcolors = LogColors()
     logtrace = 'this is an info log trace'
     log = Log('anylog')
     message = Message(logcolors, target='anything')
     message.parse(logtrace, log)
     self.mocker.replay()
     poster = notifications.Poster(properties)
     poster.registered_logs[log] = True
     body = poster.notify(message, log)
     self.assertFalse(body)
コード例 #32
0
ファイル: test_resume.py プロジェクト: qrees/log4tailer
    def testReportToAFile(self):
        reportfileFullPath = "reportfile.txt"
        fh = open('aconfig', 'w')
        fh.write('analyticsnotification = ' + reportfileFullPath + '\n')
        fh.write('analyticsgaptime = 0.1\n')
        fh.close()
        properties = Property('aconfig')
        properties.parse_properties()
        self.assertTrue(properties.is_key('analyticsnotification'))
        log = Log('out.log')
        arrayLog = [log]
        resume = reporting.Resume(arrayLog)
        gaptime = 0.1
        resume.setAnalyticsGapNotification(gaptime)
        resume.notification_type(reportfileFullPath)
        fh = open('out.log')
        lines = fh.readlines()
        fh.close()
        logcolors = LogColors()
        msg = Message(logcolors)

        def overgap():
            return gaptime + 1

        def belowgap():
            return gaptime - 0.01

        resume.timer.inactivityEllapsed = overgap

        for line in lines:
            msg.parse(line, log)
            resume.update(msg, log)
            resume.timer.inactivityEllapsed = belowgap
        fh = open(reportfileFullPath)
        reportlength = len(fh.readlines())
        fh.close()
        os.remove(reportfileFullPath)
        self.assertEquals(24, reportlength)
        os.remove('aconfig')
コード例 #33
0
    def testReportToAFile(self):
        reportfileFullPath = "reportfile.txt"
        fh = open('aconfig', 'w')
        fh.write('analyticsnotification = ' + reportfileFullPath + '\n')
        fh.write('analyticsgaptime = 0.1\n')
        fh.close()
        properties = Property('aconfig')
        properties.parse_properties()
        self.assertTrue(properties.is_key('analyticsnotification'))
        log = Log('out.log')
        arrayLog = [log]
        resume = reporting.Resume(arrayLog)
        gaptime = 0.1
        resume.setAnalyticsGapNotification(gaptime)
        resume.notification_type(reportfileFullPath)
        fh = open('out.log')
        lines = fh.readlines()
        fh.close()
        logcolors = LogColors()
        msg = Message(logcolors)

        def overgap():
            return gaptime + 1

        def belowgap():
            return gaptime - 0.01

        resume.timer.inactivityEllapsed = overgap

        for line in lines:
            msg.parse(line, log)
            resume.update(msg, log)
            resume.timer.inactivityEllapsed = belowgap
        fh = open(reportfileFullPath)
        reportlength = len(fh.readlines())
        fh.close()
        os.remove(reportfileFullPath)
        self.assertEquals(24, reportlength)
        os.remove('aconfig')
コード例 #34
0
 def test_shouldPost_if_alertable(self):
     properties = self.mocker.mock()
     properties.get_value('server_url')
     self.mocker.result('localhost')
     properties.get_value('server_port')
     self.mocker.result(8000)
     properties.get_value('server_service_uri')
     self.mocker.result('/')
     properties.get_value('server_service_register_uri')
     self.mocker.result('/register')
     properties.get_value('server_service_unregister_uri')
     self.mocker.result('/unregister')
     logcolors = LogColors()
     logtrace = 'this is an error log trace'
     log = Log('anylog')
     message = Message(logcolors)
     message.parse(logtrace, log)
     self.mocker.replay()
     poster = notifications.Poster(properties)
     require_server()
     body = poster.notify(message, log)
     self.assertTrue(body)
コード例 #35
0
ファイル: test_postserver.py プロジェクト: qrees/log4tailer
 def test_shouldPost_if_alertable(self):
     properties = self.mocker.mock()
     properties.get_value('server_url')
     self.mocker.result('localhost')
     properties.get_value('server_port')
     self.mocker.result(8000)
     properties.get_value('server_service_uri')
     self.mocker.result('/')
     properties.get_value('server_service_register_uri')
     self.mocker.result('/register')
     properties.get_value('server_service_unregister_uri')
     self.mocker.result('/unregister')
     logcolors = LogColors()
     logtrace = 'this is an error log trace'
     log = Log('anylog')
     message = Message(logcolors)
     message.parse(logtrace, log)
     self.mocker.replay()
     poster = notifications.Poster(properties)
     require_server()
     body = poster.notify(message, log)
     self.assertTrue(body)
コード例 #36
0
ファイル: test_postnotifier.py プロジェクト: qrees/log4tailer
 def test_not_execute_if_not_alertable_Level(self):
     properties = self.mocker.mock()
     properties.get_value('server_url')
     self.mocker.result('localhost')
     properties.get_value('server_port')
     self.mocker.result(8000)
     properties.get_value('server_service_uri')
     self.mocker.result('/')
     properties.get_value('server_service_register_uri')
     self.mocker.result('/register')
     properties.get_value('server_service_unregister_uri')
     self.mocker.result('/unregister')
     logcolors = LogColors()
     logtrace = 'this is an info log trace'
     log = Log('anylog')
     message = Message(logcolors, target = 'anything')
     message.parse(logtrace, log)
     self.mocker.replay()
     poster = notifications.Poster(properties)
     poster.registered_logs[log] = True
     body = poster.notify(message, log)
     self.assertFalse(body)
コード例 #37
0
 def testshouldColorizeMultilineLogTraces(self):
     trace = 'FATAL> something went wrong\nin here as well'
     trace0, trace1 = trace.split('\n')
     level = 'FATAL'
     termcolors = TermColorCodes()
     # now assert trace0 and trace1 are in FATAL level
     sys.stdout = MemoryWriter()
     logcolors = LogColors()
     message = Message(logcolors)
     notifier = notifications.Print()
     anylog = Log('out.log')
     expectedLogTrace0 = logcolors.getLevelColor(level) + \
             trace0 + termcolors.reset
     expectedLogTrace1 = logcolors.getLevelColor(level) + \
             trace1 + termcolors.reset
     message.parse(trace0, anylog)
     notifier.notify(message, anylog)
     self.assertEqual(expectedLogTrace0, sys.stdout.captured[0])
     self.assertEqual('FATAL', message.messageLevel)
     message.parse(trace1, anylog)
     notifier.notify(message, anylog)
     self.assertEqual(expectedLogTrace1, sys.stdout.captured[2])
     self.assertEqual('FATAL', message.messageLevel)
コード例 #38
0
 def testShouldReportaLogOwnTarget(self):
     logfile = "/any/path/outtarget.log"
     configfile = "aconfig.txt"
     logcolors = LogColors()
     fh = open(configfile, 'w')
     fh.write("targets " + logfile + " = should\n")
     fh.close()
     properties = Property(configfile)
     properties.parse_properties()
     mylog = Log(logfile, properties)
     optional_params = (None, True, logfile)
     self.assertEqual(optional_params,
                      (mylog.ownOutputColor, mylog.patTarget, mylog.path))
     arraylogs = [mylog]
     resume = reporting.Resume(arraylogs)
     message = Message(logcolors, properties=properties)
     logtrace = "log trace info target should be reported"
     message.parse(logtrace, mylog)
     resume.update(message, mylog)
     outLogReport = resume.logsReport[mylog.path]
     numofTargets = 1
     gotnumTargets = outLogReport['TARGET']
     self.assertEquals(numofTargets, gotnumTargets)
コード例 #39
0
ファイル: test_resume.py プロジェクト: qrees/log4tailer
 def testShouldReportaLogOwnTarget(self):
     logfile = "/any/path/outtarget.log"
     configfile = "aconfig.txt"
     logcolors = LogColors()
     fh = open(configfile, 'w')
     fh.write("targets " + logfile + " = should\n")
     fh.close()
     properties = Property(configfile)
     properties.parse_properties()
     mylog = Log(logfile, properties)
     optional_params = (None, True, logfile)
     self.assertEqual(optional_params, (mylog.ownOutputColor,
         mylog.patTarget, mylog.path))
     arraylogs = [mylog]
     resume = reporting.Resume(arraylogs)
     message = Message(logcolors, properties=properties)
     logtrace = "log trace info target should be reported"
     message.parse(logtrace, mylog)
     resume.update(message, mylog)
     outLogReport = resume.logsReport[mylog.path]
     numofTargets = 1
     gotnumTargets = outLogReport['TARGET']
     self.assertEquals(numofTargets, gotnumTargets)
コード例 #40
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))