Completed
Push — master ( 46d065...9e80fb )
by
unknown
01:39
created

ListLogPrinter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 5
1
from pyprint.Printer import Printer
2
3
from coalib.output.printers.LOG_LEVEL import LOG_LEVEL
4
from coalib.output.printers.LogPrinter import LogPrinter
5
from coalib.processes.communication.LogMessage import LogMessage
6
7
8
class ListLogPrinter(Printer, LogPrinter):
9
    """
10
    A ListLogPrinter is a log printer which collects all LogMessages to a list
11
    so that the logs can be used at a later time.
12
    """
13
14
    def __init__(self,
15
                 log_level=LOG_LEVEL.WARNING,
16
                 timestamp_format="%X"):
17
        Printer.__init__(self)
18
        LogPrinter.__init__(self, self, log_level, timestamp_format)
19
20
        self.logs = []
21
22
    def log_message(self, log_message, **kwargs):
23
        if not isinstance(log_message, LogMessage):
24
            raise TypeError("log_message should be of type LogMessage.")
25
26
        if log_message.log_level < self.log_level:
27
            return
28
29
        self.logs.append(log_message)
30
31
    def _print(self, output, **kwargs):
32
        self.info(output, **kwargs)
33