12345678910111213141516171819 |
- import logging
- class Logger():
- def __init__(self, path="log.txt"):
- self.logger = logging.getLogger("Logger")
- self.file_handler = logging.FileHandler(path, "w")
- self.stdout_handler = logging.StreamHandler()
- self.logger.addHandler(self.file_handler)
- self.logger.addHandler(self.stdout_handler)
- self.stdout_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
- self.file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
- self.logger.setLevel(logging.INFO)
-
- def info(self, txt):
- self.logger.info(txt)
-
- def close(self):
- self.file_handler.close()
- self.stdout_handler.close()
|