from abc import ABC, abstractmethod class logger(ABC): def __init__(self): pass @abstractmethod def info(self, content): pass @abstractmethod def warning(self, content): pass @abstractmethod def error(self, content): pass class stdio_logger(logger): def info(self, content): print("[INFO]: " + str(content)) def warning(self, content): print("[WARNING]: " + str(content)) def error(self, content): print("[ERROR]: " + str(content)) class dummy_logger(logger): def info(self, content): pass def warning(self, content): pass def error(self, content): pass class file_logger(logger): def __init__(self, file): try: self.file = open(file, "w") except: print("Can not open log file: \"" + file + "\"") exit(-1) def __del__(self): self.file.close() def info(self, content): try: self.file.write("[INFO]: " + str(content) + "\n") except: print("Can not write to log file!") exit(-1) def warning(self, content): try: self.file.write("[WARNING]: " + str(content) + "\n") except: print("Can not write to log file!") exit(-1) def error(self, content): try: self.file.write("[ERROR]: " + str(content) + "\n") except: print("Can not write to log file!") exit(-1) class loader: _logger = None def get(): if loader._logger is None: Exception("Logger bust be set in loader first.") return loader._logger def set(new_logger): if type(new_logger) is not logger: Exception("New loader must be instance of logger.") loader._logger = new_logger def __init__(self): Exception("Loader is static class.")