Explorar el Código

Add color statements to the log class

ogert hace 4 años
padre
commit
2bf292390c
Se han modificado 3 ficheros con 56 adiciones y 1 borrados
  1. 33 0
      cdplib/log.py
  2. 1 1
      cdplib/unit_tests/TestFlattenData.py
  3. 22 0
      cdplib/unit_tests/TestLog.py

+ 33 - 0
cdplib/log.py

@@ -60,6 +60,39 @@ class Log():
 
         # self._logger.setLevel(log_level)
 
+    @property
+    def header(self):
+        return '\033[95m'
+
+    @property
+    def blue(self):
+        return '\033[94m'
+
+    @property
+    def green(self):
+        return '\033[92m'
+
+    @property
+    def yellow(self):
+        return '\033[93m'
+
+    @property
+    def fail(self):
+        return '\033[91m'
+
+    @property
+    def reset(self):
+        return '\033[0m'
+
+    @property
+    def bold(self):
+        return '\033[1m'
+
+    @property
+    def underline(self):
+        return '\033[4m'
+
+
     def info(self, message: str):
         self._logger.info(message)
 

+ 1 - 1
cdplib/unit_tests/TestFlattenData.py

@@ -7,7 +7,7 @@ sys.path.append(os.getcwd())
 from cdplib.log import Log
 from cdplib.FlattenData import FlattenData
 
-class TestMongodbHandler(unittest.TestCase):
+class TestFlattenData(unittest.TestCase):
 
     def setUp(self):
         self.flattener = FlattenData()

+ 22 - 0
cdplib/unit_tests/TestLog.py

@@ -0,0 +1,22 @@
+import unittest
+import sys
+import os
+from pprint import pprint
+sys.path.append(os.getcwd())
+from cdplib.log import Log
+
+
+class TestLog(unittest.TestCase):
+
+    def setUp(self):
+       self._log = Log('Log Test')
+
+    def test_A_Log_Colors(self):
+        self._log.info(self._log.header + "Header")
+        self._log.info(self._log.blue + "Blue")
+        self._log.info( self._log.green + "Green")
+        self._log.info(self._log.yellow + "yellow")
+        self._log.info(self._log.fail + "Fail")
+        self._log.info(self._log.reset + "reset")
+        self._log.info(self._log.bold + "bold" )
+        self._log.info(self._log.underline + "underline" )