Commits

jordilin committed ae18790

cornermark for targets with an on cyan emphasizing 5 char string

  • Participants
  • Parent commits 0f622ec

Comments (0)

Files changed (3)

File log4tailer/TermColorCodes.py

             setattr(self, k, SUFFIX_CODE % COLORS[k])
         self.backgroundemph = SUFFIX_CODE % HIGHLIGHTS['on_red']
         self.onyellowemph = SUFFIX_CODE % HIGHLIGHTS['on_yellow']
+        self.oncyanemph = SUFFIX_CODE % HIGHLIGHTS['on_cyan']
         self.reset = RESET
 
     def buildCode(self, color):

File log4tailer/notifications.py

     markable = {'FATAL' : 'backgroundemph', 
             'ERROR' : 'backgroundemph', 
             'WARN' : 'onyellowemph', 
-            'WARNING' : 'onyellowemph'}
+            'WARNING' : 'onyellowemph',
+            'TARGET' : 'oncyanemph'}
 
     def __init__(self, gaptime):
         self.corner_time = float(gaptime)
         :param log: the log associated with the current message
         """ 
         level = message.getMessageLevel().upper()
-        if level in self.markable:
+        isTarget = message.isATarget()
+        # target has priority over markable levels
+        if isTarget:
+            self.flagged = True
+            self.emphcolor = self.markable.get("TARGET")
+        elif level in self.markable:
             self.flagged = True
             self.emphcolor = self.markable.get(level)
-
         if self.flagged:
             if self.count == 0:
                 self.timer.startTimer()

File test/test_cornermark.py

 from log4tailer.LogColors import LogColors
 from log4tailer import notifications
 from log4tailer.TermColorCodes import TermColorCodes
+from log4tailer.Properties import Property
 
 
 CONFIG = 'aconfig.txt'
         self.assertEquals(output, sys.stdout.captured[2])
 
     def testMarkedTARGET(self):
-        #TODO
-        pass
-        #trace = "FATAL this is a fatal trace"
-        #sys.stdout = Writer()
-        #logcolors = LogColors()
-        #termcolors = TermColorCodes()
-        #message = Message(logcolors)
-        #notifier = notifications.CornerMark(0.02)
-        #anylog = Log('out.log')
-        #message.parse(trace, anylog)
-        #notifier.notify(message, anylog)
-        #self.assertTrue(sys.stdout.captured)
-        #termcols = os.popen("tput cols")
-        #ttcols = termcols.readline()
-        #termcols.close()
-        #ttcols = int(ttcols)
-        #padding = 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])
+        configfile = "aconfig.txt"
+        logfile = "/any/path/out.log"
+        trace = "this is a targeted log trace"
+        fh = open(configfile, 'w')
+        fh.write("targets "+logfile+"=targeted\n")
+        fh.close()
+        properties = Property(configfile)
+        properties.parseProperties()
+        sys.stdout = Writer()
+        logcolors = LogColors()
+        termcolors = TermColorCodes()
+        notifier = notifications.CornerMark(0.02)
+        anylog = Log(logfile, properties)
+        message = Message(logcolors, properties = properties)
+        termcols = os.popen("tput cols")
+        ttcols = termcols.readline()
+        termcols.close()
+        ttcols = int(ttcols)
+        padding = 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])
 
+    def testMarkedTARGETOverMarkableLevel(self):
+        configfile = "aconfig.txt"
+        logfile = "/any/path/out.log"
+        trace = "this is a FATAL targeted log trace"
+        fh = open(configfile, 'w')
+        fh.write("targets "+logfile+"=targeted\n")
+        fh.close()
+        properties = Property(configfile)
+        properties.parseProperties()
+        sys.stdout = Writer()
+        logcolors = LogColors()
+        termcolors = TermColorCodes()
+        notifier = notifications.CornerMark(0.02)
+        anylog = Log(logfile, properties)
+        message = Message(logcolors, properties = properties)
+        termcols = os.popen("tput cols")
+        ttcols = termcols.readline()
+        termcols.close()
+        ttcols = int(ttcols)
+        padding = 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])
+    
     def tearDown(self):
         sys.stdout = self.sysback