gunicorn.conf.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # gunicorn.conf.py
  2. import os
  3. import multiprocessing
  4. import logging.handlers
  5. import logging
  6. bind = '127.0.0.1:5000'
  7. timeout = 30 # 超时
  8. worker_class = 'gevent'
  9. workers = multiprocessing.cpu_count() * 2 + 1 # 进程数
  10. threads = 2 # 指定每个进程开启的线程数
  11. hblog_path = os.path.join(os.environ['HOME'], "hblog")
  12. os.makedirs(hblog_path, exist_ok=True, mode=0o775)
  13. # 设置访问日志和错误信息日志路径
  14. log_format = ("[%(levelname)s]:%(name)s:%(asctime)s "
  15. "(%(filename)s:%(lineno)d %(funcName)s) "
  16. "%(process)d %(thread)d "
  17. "%(message)s")
  18. log_formatter = logging.Formatter(log_format)
  19. # 错误日志
  20. gunicorn_error_logger = logging.getLogger("gunicorn.error")
  21. gunicorn_error_logger.setLevel(logging.WARNING)
  22. errorlog = os.path.join(hblog_path, "gunicorn_error.log")
  23. time_handle = logging.handlers.TimedRotatingFileHandler(errorlog, when="d", backupCount=30, encoding='utf-8')
  24. gunicorn_error_logger.addHandler(time_handle)
  25. time_handle.setFormatter(log_formatter)
  26. # 一般日志
  27. gunicorn_access_logger = logging.getLogger("gunicorn.access")
  28. gunicorn_access_logger.setLevel(logging.INFO)
  29. accesslog = os.path.join(hblog_path, "gunicorn_access.log")
  30. time_handle = logging.handlers.TimedRotatingFileHandler(accesslog, when="d", backupCount=10, encoding='utf-8')
  31. gunicorn_access_logger.addHandler(time_handle)
  32. time_handle.setFormatter(log_formatter)
  33. # 输出日志
  34. gunicorn_access_logger.info("Load gunicorn conf success")
  35. gunicorn_access_logger.info(f"bind: {bind}")
  36. gunicorn_access_logger.info(f"timeout: {timeout}")
  37. gunicorn_access_logger.info(f"worker_class: {worker_class}")
  38. gunicorn_access_logger.info(f"workers: {workers}")
  39. gunicorn_access_logger.info(f"threads: {threads}")
  40. gunicorn_access_logger.info(f"hblog_path: {hblog_path}")