I have created a simple project which uses Abseil and is built and run inside of Qt Creator.
When I use any abseil logging, I see the output twice in the Qt Creator "Application Output" pane. Once in red and once again in white (I'm using dark theme). Using std::cout, I see the output once as white, as expected. Using std::cerr, I see the output once as red, as expected. I cannot figure out how to stop Abseil logging from printing twice. If I run the same process from the command line, the Abseil logs are only printed to stderr, as expected.
- OS: Windows 10
- Qt Creator versions tested: 11 & 12
- Qt version: 6.2.4 MSVC2019 64bit
Abseil is recently cloned locally as a subdirectory. The commit is 2a636651729cec997a433ce8e363c6344130944e, though it happens with older versions too.
Here is the directory structure:
.
|-- CMakeLists.txt
|-- CMakeLists.txt.user
|-- abseil-cpp
`-- main.cpp
Here is my main:
#include <absl/log/globals.h>
#include <absl/log/initialize.h>
#include <absl/log/log.h>
#include <iostream>
int main() {
absl::InitializeLog();
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
std::cout << "Cout test" << std::endl;
std::cerr << "Cerr test" << std::endl;
LOG(INFO) << "test";
return 0;
}
This program will print something like:
Cout test
Cerr test
I0104 17:58:48.312991 20796 main.cpp:12] test
I0104 17:58:48.312991 20796 main.cpp:12] test
("Cerr test" and one of the "main.cpp:12] test" lines are red)
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.26.4)
project(main LANGUAGES CXX)
add_executable(${PROJECT_NAME}
main.cpp
)
set(ABSL_PROPAGATE_CXX_STD ON)
add_subdirectory(abseil-cpp)
target_link_libraries(${PROJECT_NAME}
PUBLIC
absl::log
absl::log_initialize
)
This has been determined to be a bug in Qt Creator. I have come up with a workaround. I've created my own "Log Sink" and registered it with abseil.
Additionally, the
LogSeveritylevel ought to be set to a maximum to disable the usual absl logging.