简体   繁体   English

Flask不打印sys.stdout.write消息

[英]Flask is not printing sys.stdout.write messages

I am running the flask app from this link using the command python app.py . 我正在使用命令python app.py从此链接运行烧瓶应用程序。

More logs printed using, sys.stdout.write are not printed on the console. 使用sys.stdout.write打印的更多日志不会打印在控制台上。 However using logging.StreamHandler works for redirecting messages to stdout. 但是,使用logging.StreamHandler可以将消息重定向到stdout。

It works, 有用,

import logging
import logging.handlers
logger = logging.getLogger('kumologging')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
logger.addHandler(ch)
logger.info("hey, i am from logger obj")

It doesn't work 它不起作用

import sys
sys.stdout.write("hey, i am from stdout")

Does flask override sys.stdout file descriptor, redirecting the logs elsewhere? flask会覆盖sys.stdout文件描述符,将日志重定向到其他地方吗?

afaik flasks app.run() uses the gunicorn web package afaik app.run()使用gunicorn web包

I believe gunicorn is the one that is actually redirecting your output 我相信gunicorn实际上是重定向输出的那个

the output might be in /var/log/gunicorn/error.log (not sure where it would be on windows :/) 输出可能在/var/log/gunicorn/error.log (不确定它在windows上的位置:/)

or its possible sys.stdout is just not flushing its buffer, try sys.stdout.flush() after writting to it 或者它可能的sys.stdout只是没有刷新它的缓冲区,在写入后尝试sys.stdout.flush()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM