log.py 649 B

1234567891011121314151617181920212223242526
  1. import logging
  2. import logging.config
  3. import os
  4. path = 'log_config.yaml'
  5. # if os.path.exists(path):
  6. # with open(path, 'r', encoding='utf-8') as f:
  7. # config = yaml.load(f)
  8. # logging.config.dictConfig(config)
  9. # else:
  10. logging.basicConfig(
  11. filename='app-basic.log',
  12. level=logging.INFO,
  13. format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
  14. datefmt='%Y-%m-%d %H:%M:%S'
  15. )
  16. def my_log(type,name,msg):
  17. if type == "info":
  18. logger = logging.getLogger(name)
  19. logger.info(msg)
  20. elif type == "error":
  21. logger = logging.getLogger(name)
  22. logger.error(msg)