-
Notifications
You must be signed in to change notification settings - Fork 3
/
gunicorn.conf.py
55 lines (45 loc) · 1.85 KB
/
gunicorn.conf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# gunicorn.conf.py
import os
import multiprocessing
import logging.handlers
import logging
try:
import gevent.monkey
gevent.monkey.patch_all()
except ImportError:
pass
bind = '127.0.0.1:5000'
timeout = 30 # 超时
worker_class = 'gevent'
workers = multiprocessing.cpu_count() * 2 + 1 # 进程数
threads = 2 # 指定每个进程开启的线程数
hblog_path = os.path.join(os.environ['HOME'], "hblog")
os.makedirs(hblog_path, exist_ok=True, mode=0o775)
# 设置访问日志和错误信息日志路径
log_format = ("[%(levelname)s]:%(name)s:%(asctime)s "
"(%(filename)s:%(lineno)d %(funcName)s) "
"%(process)d %(thread)d "
"%(message)s")
log_formatter = logging.Formatter(log_format)
# 错误日志
gunicorn_error_logger = logging.getLogger("gunicorn.error")
gunicorn_error_logger.setLevel(logging.WARNING)
errorlog = os.path.join(hblog_path, "gunicorn_error.log")
time_handle = logging.handlers.TimedRotatingFileHandler(errorlog, when="d", backupCount=30, encoding='utf-8')
gunicorn_error_logger.addHandler(time_handle)
time_handle.setFormatter(log_formatter)
# 一般日志
gunicorn_access_logger = logging.getLogger("gunicorn.access")
gunicorn_access_logger.setLevel(logging.INFO)
accesslog = os.path.join(hblog_path, "gunicorn_access.log")
time_handle = logging.handlers.TimedRotatingFileHandler(accesslog, when="d", backupCount=10, encoding='utf-8')
gunicorn_access_logger.addHandler(time_handle)
time_handle.setFormatter(log_formatter)
# 输出日志
gunicorn_access_logger.info("Load gunicorn conf success")
gunicorn_access_logger.info(f"bind: {bind}")
gunicorn_access_logger.info(f"timeout: {timeout}")
gunicorn_access_logger.info(f"worker_class: {worker_class}")
gunicorn_access_logger.info(f"workers: {workers}")
gunicorn_access_logger.info(f"threads: {threads}")
gunicorn_access_logger.info(f"hblog_path: {hblog_path}")