Detailed log configuration of gunicorn of python

Gunicorn's log configuration

There are four common parameters related to gunicorn's log configuration, namely accesslog, access_log_format, errorlog, and loglevel.

  • accesslog: The directory of the user's access log, similar to nginx's access_log, which records the information of users who access the server;
accesslog = '/var/logs/gunicorn.access.log'
accesslog = '-' # 记录到标准输出
  • access_log_format: Set the format of the log that records access information;
access_log_format = '%(h)s %(l)s %(u)s %(t)s'
access_log_format = '%(h) -  %(t)s - %(u)s - %(s)s %(H)s'

gunicorn has several built-in parameters to configure:

h   远程地址
l   “-“
u   用户名
t   时间
r   状态行,如:GET /test HTTP/1.1
m   请求方法
U   没有查询字符串的URL
q   查询字符串
H   协议
s   状态码
B   response长度
b   response长度(CLF格式)
f   参考
a   用户代理
T   请求时间,单位为s
D   请求时间,单位为ms
p   进程id
{Header}i   请求头
{Header}o   相应头
{Variable}e 环境变量
  • errorlog: record the log of the server running;
errorlog = '/var/logs/gunicorn.error.log'
errorlog = '-' # 记录到标准输出
  • loglevel: set the output level of the error log; there is a level to choose from;
loglevel = 'error'  # 后面需要用引号包裹
debug:调试级别,记录的信息最多;
info:普通级别;
warning:警告消息;
error:错误消息;
critical:严重错误消息;
  • Other parameters
logger_class :选择处理日志的方法
logger_class = 'STRING'

supervisor manages gunicorn

Since gunicorn is managed by supervisor, supervisor can record standard output and error output, so log information can be set to standard output, so that it can share log files with flask applications, reduce the number of log files, and facilitate management. .

errorlog = '-'
accesslog = '-'

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324777049&siteId=291194637