9#include <QProcessEnvironment>
17#if defined(QT_DEBUG) || defined(_DEBUG) || !defined(NDEBUG)
24bool envAllowsTrace() {
25 const auto env = QProcessEnvironment::systemEnvironment();
26 const QString value = env.value(QStringLiteral(
"FOSSREDDER_UI_TRACE"));
27 if (value.isEmpty()) {
31 const bool explicitlyDisabled =
32 value.compare(QStringLiteral(
"0"), Qt::CaseInsensitive) == 0 ||
33 value.compare(QStringLiteral(
"false"), Qt::CaseInsensitive) == 0 ||
34 value.compare(QStringLiteral(
"off"), Qt::CaseInsensitive) == 0;
35 if (explicitlyDisabled) {
39 return value.compare(QStringLiteral(
"1"), Qt::CaseInsensitive) == 0 ||
40 value.compare(QStringLiteral(
"true"), Qt::CaseInsensitive) == 0 ||
41 value.compare(QStringLiteral(
"on"), Qt::CaseInsensitive) == 0;
46 parts.reserve(
static_cast<int>(
context.size()));
47 for (
const auto& [key, value] :
context) {
48 parts.push_back(QStringLiteral(
"%1=%2").arg(QString::fromStdString(key),
49 QString::fromStdString(value)));
51 return parts.join(QStringLiteral(
" "));
57 return debugBuild() && envAllowsTrace();
60void trace(
const char*
layer,
const char* origin, std::string message,
66 const QString layerText = QString::fromUtf8(
layer ?
layer :
"ui");
67 const QString originText = QString::fromUtf8(origin ? origin :
"unknown");
68 QString line = QStringLiteral(
"[ui.trace] %1 %2: %3")
69 .arg(layerText, originText,
70 QString::fromStdString(std::move(message)));
71 const QString details = contextText(
context);
72 if (!details.isEmpty()) {
73 line += QStringLiteral(
" | %1").arg(details);
75 qInfo().noquote() << line;
Declarations for the UI Trace component.
std::vector< std::pair< std::string, std::string > > ErrorContext
Key/value context attached to an error event.
bool isTraceEnabled()
Reports whether UI trace emission is enabled.
void trace(const char *layer, const char *origin, std::string message, core::errors::ErrorContext context={})
Emits a UI trace event.