import logging
from logging.handlers import TimedRotatingFileHandler

class MyLog():
    def __init__(self, name, filename):
        self.logger = logging.getLogger(name)
        if not self.logger.handlers:
            self.logger.setLevel(logging.INFO)
            ch = TimedRotatingFileHandler(filename=filename, when='midnight', encoding="utf-8")
            ch.setLevel(logging.DEBUG)
            formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
            ch.setFormatter(formatter)
            self.logger.addHandler(ch)


'''
logger = MyLog("test","log\\text.txt")
logger.logger.debug('debug message')
logger.logger.info('info message')
logger.logger.warning('warn message')
logger.logger.error('error message')
logger.logger.critical('critical message')
'''



[((147, 170), 'logging.getLogger', 'logging.getLogger', (['name'], {}), '(name)\n', (164, 170), False, 'import logging\n'), ((272, 350), 'logging.handlers.TimedRotatingFileHandler', 'TimedRotatingFileHandler', ([], {'filename': 'filename', 'when': '"""midnight"""', 'encoding': '"""utf-8"""'}), "(filename=filename, when='midnight', encoding='utf-8')\n", (296, 350), False, 'from logging.handlers import TimedRotatingFileHandler\n'), ((414, 487), 'logging.Formatter', 'logging.Formatter', (['"""%(asctime)s - %(name)s - %(levelname)s - %(message)s"""'], {}), "('%(asctime)s - %(name)s - %(levelname)s - %(message)s')\n", (431, 487), False, 'import logging\n')]