折腾:
【记录】参考Flask教程去通过Flask-RESTful设计的Restful的API接口
期间,发现代码中的:
gLog = app.logger class TaskListAPI(Resource): decorators = [auth.login_required] def get(self): gLog.debug("get for TaskListAPI") return {‘tasks’: [marshal(task, task_fields) for task in tasks]} |
结果:
gunicorn去启动app时:
(RunningFast) ➜ RunningFast gunicorn -w 4 -b 0.0.0.0:21084 run:app & [1] 13541 (RunningFast) ➜ RunningFast [2016-09-30 17:40:13 +0000] [13541] [INFO] Starting gunicorn 19.6.0 [2016-09-30 17:40:13 +0000] [13541] [INFO] Listening at: http://0.0.0.0:21084 (13541) [2016-09-30 17:40:13 +0000] [13541] [INFO] Using worker: sync [2016-09-30 17:40:13 +0000] [13550] [INFO] Booting worker with pid: 13550 [2016-09-30 17:40:13 +0000] [13551] [INFO] Booting worker with pid: 13551 [2016-09-30 17:40:13 +0000] [13554] [INFO] Booting worker with pid: 13554 [2016-09-30 17:40:13 +0000] [13555] [INFO] Booting worker with pid: 13555 |
然后去测试访问接口:
即可看到shell中输出了log信息:
但是去换用supervisor管理任务时:
(RunningFast) ➜ RunningFast netstat -tulpn | grep 21084 tcp 0 0 0.0.0.0:21084 0.0.0.0:* LISTEN 13541/python (RunningFast) ➜ RunningFast kill -9 13541 [1] + 13541 killed gunicorn -w 4 -b 0.0.0.0:21084 run:app (RunningFast) ➜ RunningFast [2016-09-30 17:42:56 +0000] [13551] [INFO] Parent changed, shutting down: <Worker 13551> [2016-09-30 17:42:56 +0000] [13551] [INFO] Worker exiting (pid: 13551) [2016-09-30 17:42:56 +0000] [13554] [INFO] Parent changed, shutting down: <Worker 13554> [2016-09-30 17:42:56 +0000] [13554] [INFO] Worker exiting (pid: 13554) [2016-09-30 17:42:59 +0000] [13550] [INFO] Parent changed, shutting down: <Worker 13550> [2016-09-30 17:42:59 +0000] [13550] [INFO] Worker exiting (pid: 13550) [2016-09-30 17:42:59 +0000] [13555] [INFO] Parent changed, shutting down: <Worker 13555> [2016-09-30 17:42:59 +0000] [13555] [INFO] Worker exiting (pid: 13555) (RunningFast) ➜ RunningFast (RunningFast) ➜ RunningFast supervisorctl -c supervisor.conf restart runningfast runningfast: ERROR (not running) runningfast: started (RunningFast) ➜ RunningFast supervisorctl -c supervisor.conf status runningfast RUNNING pid 13616, uptime 0:00:08 |
去访问后:
以为没有log呢,实际上是有的:
(RunningFast) ➜ RunningFast tail logs/RunningFast.log [2016-09-29 16:14:01,051 DEBUG __init__.py:49 index] got into test root endpoint: / [2016-09-29 16:19:12,254 DEBUG __init__.py:49 index] got into test root endpoint: / [2016-09-29 16:19:18,428 DEBUG __init__.py:49 index] got into test root endpoint: / [2016-09-29 16:20:00,590 DEBUG __init__.py:49 index] got into test root endpoint: / [2016-09-29 16:21:06,838 DEBUG __init__.py:49 index] got into test root endpoint: / [2016-09-29 16:24:50,871 DEBUG __init__.py:49 index] got into test root endpoint: / [2016-09-29 16:44:17,852 DEBUG __init__.py:49 index] got into test root endpoint: / [2016-09-30 17:40:41,088 DEBUG __init__.py:110 get] get for TaskListAPI [2016-09-30 17:43:42,507 DEBUG __init__.py:110 get] get for TaskListAPI [2016-09-30 17:43:43,413 DEBUG __init__.py:110 get] get for TaskListAPI (RunningFast) ➜ RunningFast tail logs/gunicorn.log (RunningFast) ➜ RunningFast tail logs/gunicorn.err [2016-09-30 17:43:13 +0000] [13627] [INFO] Booting worker with pid: 13627 [2016-09-30 17:43:13 +0000] [13628] [INFO] Booting worker with pid: 13628 <div–<—————————————————————————— DEBUG in __init__ [/root/RunningFast/runningfast/__init__.py:110]: get for TaskListAPI <div–<—————————————————————————— <div–<—————————————————————————— DEBUG in __init__ [/root/RunningFast/runningfast/__init__.py:110]: get for TaskListAPI <div–<—————————————————————————— |
【总结】
之前是搞错了,是因为代码中没有去输出log,以为supervisor管理任务后就不输出log了。
实际上是有输出log的。
转载请注明:在路上 » 【已解决】supervisor去管理gunicorn的Flask后找不到debug输出的log信息