mirror of
https://gitlab.com/spaceti-app/integrations/common/server-sdk.git
synced 2026-07-12 19:20:42 +02:00
WIP: better logger output
This commit is contained in:
parent
9dd13d2970
commit
5025a68891
@ -3,10 +3,12 @@
|
|||||||
|
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
Q_LOGGING_CATEGORY(sdkcore, "sdk.core");
|
Q_LOGGING_CATEGORY(sdkcore, "sdk.core");
|
||||||
Q_LOGGING_CATEGORY(sdknetwork, "sdk.network");
|
Q_LOGGING_CATEGORY(sdknetwork, "sdk.network");
|
||||||
Q_LOGGING_CATEGORY(sdkutils, "sdk.utils");
|
Q_LOGGING_CATEGORY(sdkutils, "sdk.utils");
|
||||||
|
Q_LOGGING_CATEGORY(sdkutilsdb, "sdk.utils.db");
|
||||||
Q_LOGGING_CATEGORY(sdkdb, "sdk.db");
|
Q_LOGGING_CATEGORY(sdkdb, "sdk.db");
|
||||||
|
|
||||||
namespace serversdk {
|
namespace serversdk {
|
||||||
@ -43,6 +45,11 @@ QList<LoggerMessage> Logger::getNewMessages(int currentCount)
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Logger::toColor(const QString &color, const QString &text)
|
||||||
|
{
|
||||||
|
return color + text + "\033[0m";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Logger::outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
void Logger::outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||||
{
|
{
|
||||||
@ -50,23 +57,29 @@ void Logger::outputMessage(QtMsgType type, const QMessageLogContext &context, co
|
|||||||
|
|
||||||
QString text;
|
QString text;
|
||||||
QString textType;
|
QString textType;
|
||||||
|
QString colorTextType;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case QtDebugMsg:
|
case QtDebugMsg:
|
||||||
textType = QStringLiteral("debug");
|
textType = QStringLiteral("DEBUG");
|
||||||
|
colorTextType = Logger::toColor("\033[0;31m", textType);
|
||||||
break;
|
break;
|
||||||
case QtWarningMsg:
|
case QtWarningMsg:
|
||||||
textType = QStringLiteral("warning");
|
textType = QStringLiteral("WARN");
|
||||||
|
colorTextType = Logger::toColor("\033[0;33m", textType);
|
||||||
break;
|
break;
|
||||||
case QtCriticalMsg:
|
case QtCriticalMsg:
|
||||||
textType = QStringLiteral("critical");
|
textType = QStringLiteral("CRITICAL");
|
||||||
|
colorTextType = Logger::toColor("\033[0;31m", textType);
|
||||||
break;
|
break;
|
||||||
case QtFatalMsg:
|
case QtFatalMsg:
|
||||||
textType = QStringLiteral("fatal");
|
textType = QStringLiteral("FATAL");
|
||||||
|
colorTextType = Logger::toColor("\033[0;31m", textType);
|
||||||
break;
|
break;
|
||||||
#if QT_VERSION >= 0x050500
|
#if QT_VERSION >= 0x050500
|
||||||
case QtInfoMsg:
|
case QtInfoMsg:
|
||||||
textType = QStringLiteral("info");
|
textType = QStringLiteral("INFO");
|
||||||
|
colorTextType = Logger::toColor("\033[0;34m", textType);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -78,14 +91,17 @@ void Logger::outputMessage(QtMsgType type, const QMessageLogContext &context, co
|
|||||||
// Output message
|
// Output message
|
||||||
//text += QString("%1 %2:%3 %4").arg(context.category).arg(shortFile).arg(context.line).arg(msg);
|
//text += QString("%1 %2:%3 %4").arg(context.category).arg(shortFile).arg(context.line).arg(msg);
|
||||||
// New output syntax
|
// New output syntax
|
||||||
text = QStringLiteral("[%1] %2 [ %3:%4 | %5 | %6 ]")
|
|
||||||
.arg(textType, msg, shortFile)
|
QDateTime now = QDateTime::currentDateTime();
|
||||||
.arg(context.line)
|
|
||||||
.arg(context.function, context.category);
|
text = QStringLiteral("[%1 %2 %3] %4") // [ %3:%4 | %5 | %6 ]")
|
||||||
|
.arg(now.toString("dd-MM-yyyy hh:mm:ss.z"))
|
||||||
|
.arg(colorTextType)
|
||||||
|
.arg(context.category)
|
||||||
|
.arg(msg);
|
||||||
|
|
||||||
QTextStream out(stderr);
|
QTextStream out(stderr);
|
||||||
out << text << "\n"; //.toLocal8Bit() + "\n";
|
out << text << "\n"; //.toLocal8Bit() + "\n";
|
||||||
//out.flush(); // INVSDK-37 ORK-102 crash on windows when flush() -> possible threading problem
|
|
||||||
|
|
||||||
if (type == QtFatalMsg)
|
if (type == QtFatalMsg)
|
||||||
abort();
|
abort();
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
Q_DECLARE_LOGGING_CATEGORY(sdkcore)
|
Q_DECLARE_LOGGING_CATEGORY(sdkcore)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(sdknetwork)
|
Q_DECLARE_LOGGING_CATEGORY(sdknetwork)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(sdkutils)
|
Q_DECLARE_LOGGING_CATEGORY(sdkutils)
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(sdkutilsdb)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(sdkdb)
|
Q_DECLARE_LOGGING_CATEGORY(sdkdb)
|
||||||
|
|
||||||
namespace serversdk {
|
namespace serversdk {
|
||||||
@ -94,6 +95,8 @@ public:
|
|||||||
virtual void pushMessage(const LoggerMessage& logmsg);
|
virtual void pushMessage(const LoggerMessage& logmsg);
|
||||||
QList<serversdk::LoggerMessage> getNewMessages(int currentCount);
|
QList<serversdk::LoggerMessage> getNewMessages(int currentCount);
|
||||||
|
|
||||||
|
static QString toColor(const QString &color, const QString &text);
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void messageReceived(const serversdk::LoggerMessage &message);
|
void messageReceived(const serversdk::LoggerMessage &message);
|
||||||
|
|||||||
@ -3,15 +3,13 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
serversdk::initAppLogger();
|
serversdk::initAppLogger();
|
||||||
|
|
||||||
qCDebug(sdkcore) << "test message";
|
qCDebug(sdkcore) << "Application starting";
|
||||||
|
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
QCoreApplication::setApplicationName("example-app");
|
QCoreApplication::setApplicationName("example-app");
|
||||||
QCoreApplication::setApplicationVersion("0.1.0");
|
QCoreApplication::setApplicationVersion("0.1.0");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user