refactor: logger::PrintLine use less streams and use the one we need directly
This commit is contained in:
parent
43989dc964
commit
8066ac8e2f
1 changed files with 5 additions and 10 deletions
|
|
@ -23,22 +23,18 @@ const auto kForceDebugMessages = QStringList{
|
||||||
QStringLiteral("Retrying to obtain clipboard."), QStringLiteral("Unable to obtain clipboard.")
|
QStringLiteral("Retrying to obtain clipboard."), QStringLiteral("Unable to obtain clipboard.")
|
||||||
};
|
};
|
||||||
|
|
||||||
QString printLine(FILE *out, const QString &type, const QString &message, const QString &fileLine = "")
|
QString printLine(FILE *out, const QString &type, const QString &message, const QString &fileLine = {})
|
||||||
{
|
{
|
||||||
|
const auto datetime = QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-ddTHH:mm:ss"));
|
||||||
auto datetime = QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-ddTHH:mm:ss"));
|
|
||||||
auto logLine = QStringLiteral("[%1] %2: %3").arg(datetime, type, message);
|
auto logLine = QStringLiteral("[%1] %2: %3").arg(datetime, type, message);
|
||||||
|
|
||||||
QTextStream stream(&logLine);
|
|
||||||
if (!fileLine.isEmpty()) {
|
if (!fileLine.isEmpty()) {
|
||||||
stream << QStringLiteral("\n\t%1").arg(fileLine);
|
logLine.append(QStringLiteral("\n\t%1").arg(fileLine));
|
||||||
}
|
}
|
||||||
|
|
||||||
// We must return a non-terminated log line, but before returning,
|
// We must return a non-terminated log line, but before returning,
|
||||||
// stdout/stderr and Windows debug output all expect a terminated line.
|
// stdout/stderr and Windows debug output all expect a terminated line.
|
||||||
QString terminatedLogLine = logLine;
|
const auto terminatedLogLine = QStringLiteral("%1\n").arg(logLine);
|
||||||
QTextStream terminatedStream(&terminatedLogLine);
|
|
||||||
terminatedStream << Qt::endl;
|
|
||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
// Debug output is viewable using either VS Code, Visual Studio, DebugView, or
|
// Debug output is viewable using either VS Code, Visual Studio, DebugView, or
|
||||||
|
|
@ -47,8 +43,7 @@ QString printLine(FILE *out, const QString &type, const QString &message, const
|
||||||
// a Windows GUI app.
|
// a Windows GUI app.
|
||||||
OutputDebugStringA(terminatedLogLine.toLocal8Bit().constData());
|
OutputDebugStringA(terminatedLogLine.toLocal8Bit().constData());
|
||||||
#else
|
#else
|
||||||
QTextStream outStream(out);
|
QTextStream(out) << terminatedLogLine;
|
||||||
outStream << terminatedLogLine;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return logLine;
|
return logLine;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue