python记录到git bash中的stdout [英] python logging to stdout in git bash

查看:106
本文介绍了python记录到git bash中的stdout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带输出到stdout的日志的python脚本

I have a python script with logging that outputs to stdout

logger = logging.getLogger()
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(v_level)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)

当我在linux机器上运行脚本时,效果很好,但是当我在Windows上的git-bash中运行脚本时,没有输出到控制台.

It works just fine when I run my script on my linux box, but when I run the script in git-bash on windows, there is no output to the console.

有什么想法吗?

推荐答案

查看

Going by the information in this question, it looks like this could well be an issue with output buffering. You can skip buffering by running your script with python -u.

这篇关于python记录到git bash中的stdout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆