log.py 702 B

123456789101112131415161718192021222324
  1. import logging
  2. import traceback
  3. class Mylog:
  4. def __init__(self,log_name,log_level):
  5. self.name=log_name
  6. self.level=log_level
  7. def logcfg(self):
  8. if len(self.level) > 0:
  9. if self.level == 'debug':
  10. Level=logging.DEBUG
  11. elif self.level == 'info':
  12. Level=logging.INFO
  13. elif self.level == 'warning':
  14. Level=logging.WARNING
  15. else:
  16. Level=logging.ERROR
  17. logging.basicConfig(filename=self.name, level=Level,format='%(asctime)s - %(levelname)s - %(message)s')
  18. def logopt(self,*info):
  19. logging.error(info)
  20. logging.error(traceback.format_exc())