标题已经说明了一切。
我正在运行一个 C++ 应用程序,它使用 SpdLog 来格式化我的所有日志。它根据日志的级别类型添加颜色。
它使用在 macOS 终端中运行良好的 ansicolor_stdout_sink_mt,如果我指定whithin QtCreator 在
terminal
中运行应用程序。
如果我让 QtCreator 运行应用程序(没有
terminal
),则 Application Output
选项卡中的输出不会着色。
我需要将日志放在
Application Output
中,因为我想使用自定义输出解析器,因为它不适用于terminal
输出。
关于如何设法让颜色具有
Application Output
的任何想法吗?
谢谢:)
set_color_mode
:
SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::set_color_mode(color_mode mode) {
switch (mode) {
case color_mode::always:
should_do_colors_ = true;
return;
case color_mode::automatic:
should_do_colors_ =
details::os::in_terminal(target_file_) && details::os::is_color_terminal();
return;
case color_mode::never:
should_do_colors_ = false;
return;
default:
should_do_colors_ = false;
}
}
如您所见,它明确询问目标文件句柄是否是终端。将
color_mode::always
传递给构造函数应该可以解决问题。