| Total Complexity | 5 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from pyprint.Printer import Printer |
||
| 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 |