py.lib.aw_log

Yohn Y. 2024-10-31 Parent:9155a66edb31

7:5db1541311ef Go to Latest

py.lib.aw_log/src/aw_log/console.py

. Исправлена ссылка на документацию. Сделал её прямой

History
1 # coding: utf-8
3 from typing import Any
4 from time import ctime
5 from sys import stderr, stdout
6 from typing import TextIO, Optional
8 from . import AbstractLogBase
11 class AbstractConsoleLog(AbstractLogBase):
12 def __init__(self, prefix: str = 'main'):
13 super().__init__(prefix)
14 self.fd: Optional[TextIO] = None
16 def _write(self, mark: str, msg: Any):
17 if self.fd is None:
18 raise ValueError(f'Не определён канал логирования')
20 tm = ctime()
21 for l in super()._write_helper(mark, msg):
22 self.fd.write(f'{tm} | {l}')
25 class StdoutLog(AbstractConsoleLog):
26 def __init__(self, prefix: str = 'main'):
27 super().__init__(prefix)
28 self.fd = stdout
31 class StderrLog(AbstractConsoleLog):
32 def __init__(self, prefix: str = 'main'):
33 super().__init__(prefix)
34 self.fd = stderr