Cixo Develop 1 неделя назад
Родитель
Сommit
8b80d24530
5 измененных файлов с 120 добавлено и 3 удалено
  1. 36 2
      source/file_handler.py
  2. 47 1
      source/handler.py
  3. 11 0
      source/levels.py
  4. 13 0
      source/stderr_handler.py
  5. 13 0
      source/stdout_handler.py

+ 36 - 2
source/file_handler.py

@@ -4,13 +4,35 @@ import os
 from .handler import handler
 
 class file_handler(handler):    
+    """
+    That handler puts log to file given when object was created.
+    """
+
     def __init__(self, target: pathlib.Path) -> None:
+        """
+        That initialize new object with given file.
+
+        Parameters
+        ----------
+        target : pathlib.Path
+            File to use by handler.
+        """
+
         super().__init__()
 
         self.__target = target
         self.__handler = None
 
     def add(self, content: str) -> None:
+        """
+        That add new content to the file as new line.
+
+        Parameters
+        ----------
+        content : str
+            Content to add into the file as new line.
+        """
+
         if not self.is_ready:
             self.open()
         
@@ -18,14 +40,26 @@ class file_handler(handler):
 
     @property
     def is_ready(self) -> bool: 
+        """
+        That check that file handler is ready to use or not.
+        """
+
         return self.__handler is not None and not self.__handler.closed
 
     def open(self) -> None:
-        if self.__handler is None or self.__handler.closed:
+        """
+        That open file and save handler to use in the future.
+        """
+
+        if not self.is_ready:
             self.__handler = self.__target.open("a")
 
     def clean(self) -> None:
-        if self.__handler is None or self.__handler.closed:
+        """
+        That close file handler if it is open yet. 
+        """
+
+        if not self.is_ready:
             return
 
         self.__handler.close()

+ 47 - 1
source/handler.py

@@ -1,21 +1,67 @@
 import asyncio
 
 class handler:
+    """
+    That is class, which is used to implements new handlers. Handler is 
+    element, which directly store content to log. For example.
+    
+    To implement property handler, implement:
+     * add(str) <- Add new content to log,
+     * open() <- Optional function, create creatr handler for add,
+     * clean() <- Optional function, clean up resources user by handler.
+    """
+
     def __init__(self) -> None:
-        self.__lock = asyncio.Lock()
+        """
+        That prepare lock for the hndler.
+        """
 
+        self.__lock = asyncio.Lock()
+    
     def __del__(self) -> None:
+        """
+        That clean up handler when item is removed.
+        """
+
         self.clean()
 
     def open(self) -> None:
+        """
+        That register system resources for handler.
+        """
+
         pass
 
     async def adding(self, content: str) -> None:
+        """
+        That add new content to the the log as new line. It do that 
+        asynchronically.
+        
+        Parameters
+        ----------
+        content : str
+            Content which must be added to log.
+        """
+
         async with self.__lock:
             await asyncio.to_thread(self.add, content)
 
     def add(self, content: str) -> None:
+        """
+        That add new content to the log as new line . It is virtual 
+        function, and must being overwritten.
+
+        Parameters
+        ----------
+        content : str
+            Content which must be added to log.
+        """
+
         raise NotImplementedError()
 
     def clean(self) -> None:
+        """
+        That clean up resources used by handler.
+        """
+
         pass

+ 11 - 0
source/levels.py

@@ -1,9 +1,20 @@
 import enum
 
 class levels(enum.Enum):
+    """
+    That enum store log levels to use.
+    """
+
+    """ Info about any action. """
     info = 0
+    
+    """ Simple warning. """
     warning = 1
+
+    """ Not critical error. """
     error = 2
+
+    """ Critical error. """
     critical = 3
 
 

+ 13 - 0
source/stderr_handler.py

@@ -4,7 +4,20 @@ import os
 from .handler import handler
 
 class stderr_handler(handler):
+    """
+    That handler simple put logs into stderr.
+    """
+
     def add(self, content: str) -> None:
+        """
+        That put contewnt as new line in stderr.
+        
+        Parameters
+        ----------
+        content : str
+            Content to write as new line.
+        """
+
         sys.stderr.write(content + os.linesep)
 
 

+ 13 - 0
source/stdout_handler.py

@@ -4,7 +4,20 @@ import os
 from .handler import handler
 
 class stdout_handler(handler):
+    """
+    That handler simple put logs into stdout.
+    """
+
     def add(self, content: str) -> None:
+        """
+        That put content as new line into stdout.
+
+        Parameters
+        ----------
+        content : str
+            Content to write as new line.
+        """
+
         sys.stdout.write(content + os.linesep)