简体   繁体   English

在Python中使用curses登录

[英]Using curses with logging in Python

I am using curses alongside the logging module and I'm having a problem with logging when curses is started. 我在日志记录模块旁边使用curses,并且在curses启动时遇到日志记录问题。

Logging is working and prints some text to console (depending on the level) until curses.initscr() is called. 日志正在运行,并将一些文本打印到控制台(取决于级别),直到curses.initscr()为止。

Any idea on how to fix it? 关于如何解决它的任何想法?

Once curses is initialized, you should perform all output through it - otherwise it'll look goofy (as you're seeing). curses初始化后,您应该通过它执行所有输出-否则,它看起来会很愚蠢(如您所见)。

You can't just use print/sys.(stdout|stderr).write, as it'll interfere with ncurses output. 您不能只使用print / sys。(stdout | stderr).write,因为它会干扰ncurses的输出。

Best solution would be, make an ncurses pad to use for logging, redirect all log messages to it. 最好的解决方案是,制作一个ncurses垫用于记录,将所有日志消息重定向到该垫。 You can customize your logging handler to do this (take a look at logging.handlers for some inspiration). 您可以自定义日志记录处理程序以执行此操作(请参阅logging.handlers以获得一些启发)。

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

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