logger.py 675 B

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