我有一个带有日志记录的 python 脚本,该脚本输出到 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 中运行脚本时,控制台没有输出。
有什么想法吗?
最佳答案
查看 this question 中的信息,看起来这很可能是输出缓冲的问题。您可以通过使用 python -u
运行脚本来跳过缓冲。
关于python 在 git bash 中记录到 stdout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35657355/