eive-tmtc/eive_tmtc/pus_tm/defs.py

30 lines
782 B
Python
Raw Normal View History

2023-02-01 20:11:47 +01:00
import logging
2023-05-23 09:54:51 +02:00
from typing import Optional
2023-02-01 20:11:47 +01:00
2023-05-25 11:31:06 +02:00
from tmtccmd.fsfw.tmtc_printer import FsfwTmTcPrinter
2022-05-10 18:00:56 +02:00
class PrintWrapper:
2023-05-23 09:54:51 +02:00
def __init__(self, file_logger: Optional[logging.Logger]):
self.file_logger = file_logger
2022-05-10 18:00:56 +02:00
def dlog(self, string: str):
print(string)
2023-05-23 09:54:51 +02:00
if self.file_logger:
self.file_logger.info(string)
def wlog(self, logger: logging.Logger, string: str):
logger.warning(string)
if self.file_logger:
self.file_logger.warning(string)
2022-05-10 18:00:56 +02:00
2023-02-01 20:11:47 +01:00
def ilog(self, logger: logging.Logger, string: str):
logger.info(string)
2023-05-23 09:54:51 +02:00
if self.file_logger:
self.file_logger.info(string)
2023-02-01 20:11:47 +01:00
2022-05-10 18:00:56 +02:00
def log_to_both(printer: FsfwTmTcPrinter, string: str):
print(string)
printer.file_logger.info(string)