Commits

jordilin committed 639bc2b

Add TRACE log level. TRACE log level is specified as a log4j log trace level.

Closes #15

Comments (0)

Files changed (4)

log4client/src/log4tailer/logcolors.py

 from log4tailer.termcolorcodes import TermColorCodes
 from log4tailer import loglevels
 
+
 class LogColors(object):
     '''Provides the colors that will
     be used when printing Log4J levels'''
     def __init__(self):
         self.color = TermColorCodes()
         # defaults
-        # color instance has dinamically assigned attributes 
+        # color instance has dinamically assigned attributes
         # so pylint complaints.
         # pylint: disable-msg=E1101
         self.warning = self.color.yellow
         self.warn = self.color.yellow
         self.error = self.color.magenta
         self.info = self.color.green
+        self.trace = self.color.black
         self.debug = self.color.black
         self.fatal = self.color.red
         self.critical = self.color.red
             if not code:
                 continue
             setattr(self, key, code)
-            
+
     def getLogColor(self, color):
         return self.color.getCode(color)
-    
+
     def getLevelColor(self, level):
         level = level.lower()
         if level in loglevels.logLevels:
             return getattr(self, level)
-

log4client/src/log4tailer/loglevels.py

 # along with Log4Tailer.  If not, see <http://www.gnu.org/licenses/>.
 
 
-logLevels = ('debug',
+logLevels = ('trace',
+             'debug',
              'info',
              'warn',
              'warning',
              'error',
              'fatal',
              'critical')
-
-
-

log4client/src/log4tailer/modes.py

     not miss a level'''
 
     def __init__(self):
-        self.defaultLevelPauses = {'debug':0,'info':0, 'warn':0, 
-                'warning':0, 
-                'error':0, 
-                'fatal':0, 
-                'critical':0,
-                'target':0}
+        self.defaultLevelPauses = {'trace': 0,
+                                   'debug': 0,
+                                   'info': 0,
+                                   'warn': 0,
+                                   'warning': 0,
+                                   'error': 0,
+                                   'fatal': 0,
+                                   'critical': 0,
+                                   'target': 0}
 
-    def getPause(self,level):
+    def getPause(self, level):
         return self.defaultLevelPauses[level]
 
-    def parse_config(self,properties):
-        pauseKeys = ['pausedebug','pauseinfo','pausewarn','pauseerror','pausefatal',
-                     'pausecritical','pausetarget']
+    def parse_config(self, properties):
+        pauseKeys = ['pausetrace',
+                     'pausedebug',
+                     'pauseinfo',
+                     'pausewarn',
+                     'pauseerror',
+                     'pausefatal',
+                     'pausecritical',
+                     'pausetarget']
         for pauseKey in pauseKeys:
             try:
                 level = pauseKey.split('pause')[1]
                 self.defaultLevelPauses[level] = pauseLevel
             except:
                 pass
-

log4client/tests/test_colors.py

 # along with Log4Tailer.  If not, see <http://www.gnu.org/licenses/>.
 
 import unittest
-import os, sys
+import os
+import sys
 from log4tailer.logfile import Log
 from log4tailer.message import Message
 from log4tailer.logcolors import LogColors
         else:
             return 'joe'
 
+
 class PropertiesBackGround(PropertiesMock):
     """docstring for PropertiesBackGround"""
     def get_keys(self):
 
     def get_value(self, key):
         return "yellow, on_cyan"
-        
+
 
 class TestColors(unittest.TestCase):
     def setUp(self):
         self.logfile = 'out.log'
-        fh = open(self.logfile,'w')
+        fh = open(self.logfile, 'w')
         # levels in upper case
         # should be very weird an app
         # logging levels in lowercase
                               'DEBUG> looking behind the scenes',
                               'INFO> the app is running']
         for line in self.someLogTraces:
-            fh.write(line+'\n')
+            fh.write(line + '\n')
         fh.close()
 
     def testMessage(self):
-        logcolors = LogColors() #using default colors
+        logcolors = LogColors()  # using default colors
         termcolors = TermColorCodes()
         target = None
         notifier = notifications.Print()
-        message = Message(logcolors,target)
+        message = Message(logcolors, target)
         log = Log(self.logfile)
         log.openLog()
         sys.stdout = MemoryWriter()
             line = line.rstrip()
             level = line.split('>')
             message.parse(line, log)
-            output = logcolors.getLevelColor(level[0])+line+termcolors.reset
-            notifier.notify(message,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)
+        self.assertEqual('', line)
         message.parse(line, log)
-        self.assertFalse(notifier.notify(message,log))
-    
+        self.assertFalse(notifier.notify(message, log))
+
     def testshouldColorizefirstLevelFoundignoringSecondinSameTrace(self):
         # Test for fix 5
         # Should give priority to FATAL in next trace
         notifier = notifications.Print()
         anylog = Log('out.log')
         message.parse(trace, anylog)
-        output = logcolors.getLevelColor(level)+trace+termcolors.reset
-        notifier.notify(message,anylog)
+        output = (logcolors.getLevelColor(level) + trace + termcolors.reset)
+        notifier.notify(message, anylog)
         self.assertEqual(output, sys.stdout.captured[0])
 
     def testshouldNotColorizeifLevelKeyInaWord(self):
-        # Testing boundary regex as for suggestion of 
+        # Testing boundary regex as for suggestion of
         # Carlo Bertoldi
         trace = "this is a logtrace where someinfoword could be found"
         sys.stdout = MemoryWriter()
         notifier = notifications.Print()
         anylog = Log('out.log')
         message.parse(trace, anylog)
-        notifier.notify(message,anylog)
+        notifier.notify(message, anylog)
         self.assertEqual(trace, sys.stdout.captured[0])
-        self.assertEqual('', message.messageLevel)        
-    
+        self.assertEqual('', message.messageLevel)
+
     def testLogColorsParseConfig(self):
         logcolors = LogColors()
         logcolors.parse_config(PropertiesMock())
-        self.assertFalse(hasattr(logcolors,'one'))
-        self.assertFalse(hasattr(logcolors,'two'))
+        self.assertFalse(hasattr(logcolors, 'one'))
+        self.assertFalse(hasattr(logcolors, 'two'))
 
     def testshouldColorizeMultilineLogTraces(self):
         trace = 'FATAL> something went wrong\nin here as well'
         message.parse(trace0, anylog)
         notifier.notify(message, anylog)
         self.assertEqual(expectedLogTrace0, sys.stdout.captured[0])
-        self.assertEqual('FATAL', message.messageLevel)        
+        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)        
+        self.assertEqual('FATAL', message.messageLevel)
 
     def testshouldColorizeWithBackground(self):
         trace = "FATAL there could be an error in the application"
         notifier = notifications.Print()
         anylog = Log('out.log')
         message.parse(trace, anylog)
-        output = logcolors.getLevelColor(level)+trace+termcolors.reset
-        notifier.notify(message,anylog)
+        output = logcolors.getLevelColor(level) + trace + termcolors.reset
+        notifier.notify(message, anylog)
         self.assertEqual(output, sys.stdout.captured[0])
-    
+
     def testshouldFailColorizeWithBackground(self):
         trace = "FATAL there could be an error in the application"
         level = 'WARN'
         notifier = notifications.Print()
         anylog = Log('out.log')
         message.parse(trace, anylog)
-        output = logcolors.getLevelColor(level)+trace+termcolors.reset
-        notifier.notify(message,anylog)
+        output = logcolors.getLevelColor(level) + trace + termcolors.reset
+        notifier.notify(message, anylog)
         self.assertNotEqual(output, sys.stdout.captured[0])
 
     def testShouldColorizeWarningLevelAsWell(self):
         notifier = notifications.Print()
         anylog = Log('out.log')
         message.parse(trace, anylog)
-        output = logcolors.getLevelColor(level)+trace+termcolors.reset
-        notifier.notify(message,anylog)
+        output = logcolors.getLevelColor(level) + trace + termcolors.reset
+        notifier.notify(message, anylog)
+        self.assertEqual(output, sys.stdout.captured[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])
 
     def tearDown(self):
 
 if __name__ == '__main__':
     unittest.main()
-
-
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.