Qt 上默认的 qDebug qWarning qCritical 和 qFatal 日志在哪里? [英] Where is located the qDebug qWarning qCritical and qFatal log by default on Qt?

查看:339
本文介绍了Qt 上默认的 qDebug qWarning qCritical 和 qFatal 日志在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Linux 上运行我的 Qt5 应用程序时,我没有看到来自 qDebug、qWarning、qCritical 或 qFatal 的任何输出.我知道我可以使用 qInstallMsgHandler 来安装消息处理程序并查看它们,但这是相当重量级的.

When running my Qt5 application on linux, I don't see any output from qDebug, qWarning, qCritical or qFatal. I know that I can use qInstallMsgHandler to install a message handler and see them, but this is rather heavyweight.

我只是想检查 qWarning 日志,看看是否有任何错误连接的信号.有没有办法查看这个日志?一个特殊的命令行选项,一个环境变量?

I just want to check the qWarning log to see if there is any signal that mis-connected. Is there a way to look at this log? A special command-line option, an environment variable?

我想我记得过去,所有东西都打印到stderr,也许这是Qt5的变化?

I think I remember that in the past, everything was printed to stderr, perhaps that's a Qt5 change?

推荐答案

请不要误以为 qDebug、qWarning、qCritical 和 qFatal 总是登录标准错误. 那绝对不是案例.

实际目标因 Qt 配置和目标操作系统而异.另外,5.4 和 5.11 引入了一些行为变化.请参阅此处此处讨论.

The actual destination varies depending on the Qt configuration and the targeting OS. Plus, 5.4 and then 5.11 introduced some behavioural changes. See here and here for discussions.

TL;博士:

在 Qt >= 5.11

  • 如果进程的 stderr 附加了一个控制台,那么调试日志就会出现在那里.
  • 如果您想始终登录标准错误,请将QT_FORCE_STDERR_LOGGING设置为1.
  • 或者,将 QT_ASSUME_STDERR_HAS_CONSOLE 设置为 1.我怀疑这是由父进程使用的,该进程读取子进程的 stderr 并以某种方式将其显示给用户.
  • QT_LOGGING_TO_CONSOLE1 仍然有效,但 Qt 会抱怨.
  • If the process' stderr has a console attached, that's where the debug log will go.
  • If you want to always log on stderr, set QT_FORCE_STDERR_LOGGING to 1.
  • In alternative, set QT_ASSUME_STDERR_HAS_CONSOLE to 1. I suspect this one is meant to be used by a parent process that reads a child's stderr and shows it to the user somehow.
  • QT_LOGGING_TO_CONSOLE to 1 still works, but Qt will complain.

在 Qt >= 5.4 和 <5.11

  • 如果您想始终登录 stderr,请将 QT_LOGGING_TO_CONSOLE 环境变量设置为 1.
  • 如果您不想登录 stderr,请将 QT_LOGGING_TO_CONSOLE 环境变量设置为 0(这将强制通过本机系统记录器进行日志记录).
  • 如果QT_LOGGING_TO_CONSOLE 环境变量未设置,那么是否登录到控制台取决于应用程序是在 TTY 中运行(在 UNIX 上)还是有一个控制台窗口(在 Windows 上).
  • If you want to always log on stderr, set the QT_LOGGING_TO_CONSOLE environment variable to 1.
  • If you do not want to log on stderr, the QT_LOGGING_TO_CONSOLE environment variable to 0 (this will force logging through the native system logger).
  • If the QT_LOGGING_TO_CONSOLE environment variable is not set, then whether logging to the console or not depends on whether the application is running in a TTY (on UNIX) or whether there's a console window (on Windows).

在 Qt 上5.4,情况比较混乱.

  • 如果 Qt 的构建支持特定的日志框架(例如 SLOG2、journald、Android 日志等),那么日志记录总是转到该框架
  • 否则在 UNIX 上它会转到 stderr
  • 否则在 Windows 上使用 OutputDebugString 或 stderr 取决于应用是否为控制台应用.

5.4 之前的方法的问题是,如果 Qt 是使用日志支持构建的,则在 Unix IDE 下将无法捕获应用程序的调试输出.那是因为输出到日志,而不是到 IDE.在 5.4 中,该方法在不同操作系统之间变得更加灵活和统一.

The problem with the pre-5.4 approach was that, f.i., under Unix IDEs would not capture an application's debug output if Qt had been built with journald support. That's because the output went to journald, not to the IDE. In 5.4 the approach has been made more flexible and uniform across OSes.

这篇关于Qt 上默认的 qDebug qWarning qCritical 和 qFatal 日志在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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