logger.py 661 B

12345678910111213141516171819202122
  1. import logging
  2. # import logging.config
  3. import os
  4. from datetime import datetime
  5. def create_logger():
  6. path_dir_log = os.path.join(os.path.dirname(__file__), 'logs')
  7. if not os.path.exists(path_dir_log):
  8. os.mkdir(path_dir_log)
  9. now = datetime.now()
  10. file_log = os.path.join(path_dir_log, F'logs_{now.year}{now.month}{now.day}.log')
  11. logging.basicConfig(filename=file_log,
  12. encoding='utf-8',
  13. level=logging.DEBUG,
  14. format='%(asctime)s %(name)s %(levelname)s %(message)s')
  15. # logging.config.fileConfig('logger.conf')
  16. logger = logging.getLogger('PropuskLogger')