logger

class Logger:
def init(self, file_name):
self.file_name = file_name

def __write_log(self, level, msg):
    with open(self.file_name, 'a') as f:
        f.write('{0} {1}\n'.format(level, msg))

def critical(self, msg):
    self.__write_log('[CRITICAL]', msg)

def warn(self, msg):
    self.__write_log('[WARN]', msg)

def info(self, msg):
    self.__write_log('[INFO]', msg)

def debug(self, msg):
    self.__write_log('[DEBUG]', msg)

class NewLogger(Logger):
instance = None
def new(cls, file_name):
if cls.instance is None:
return super().new(cls)
else:
return cls.instance()

def __init__(self, file_name):
    super().__init__(file_name)
    if self.instance is None:
        import weakref
        NewLogger.instance = weakref.ref(self)
    else:
        pass

def __del__(self):
    if self.instance is not None:
        NewLogger.instance = None

sys_logger = NewLogger(r’C:\Users\lenovo\Desktop\1.txt’)
sys_logger2 = NewLogger(r’C:\Users\lenovo\Desktop\1.txt’)
del sys_logger
del sys_logger2
print(NewLogger.instance)