py.lib.aw_log

Yohn Y. 2024-02-11 Parent:41b53fd5637e Child:9155a66edb31

2:69904de0e695 Go to Latest

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

. Скрипт для сборки пакета

History
1 # coding: utf-8
2 # devel.a0fs.ru -- aw_log.console -- v0.r202402.1
4 from typing import Any
5 from time import ctime
6 from sys import stderr, stdout
7 from typing import TextIO, Optional
9 from . import AbstractLogBase
12 class NullLog(AbstractLogBase):
13 def _write(self, mark: str, msg: Any):
14 pass
17 class AbstractConsoleLog(AbstractLogBase):
18 def __init__(self, prefix: str = 'main'):
19 super().__init__(prefix)
20 self.fd: Optional[TextIO] = None
22 def _write(self, mark: str, msg: Any):
23 if self.fd is None:
24 raise ValueError(f'Не определён канал логирования')
26 tm = ctime()
27 for l in super()._write_helper(mark, msg):
28 self.fd.write(f'{tm} | {l}')
31 class StdoutLog(AbstractConsoleLog):
32 def __init__(self, prefix: str = 'main'):
33 super().__init__(prefix)
34 self.fd = stdout
37 class StderrLog(AbstractConsoleLog):
38 def __init__(self, prefix: str = 'main'):
39 super().__init__(prefix)
40 self.fd = stderr