Commit 6a66fd18 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): qml logger supports time and color level

parent 99f1a0e2
......@@ -35,6 +35,7 @@ set(SOURCES
src/components/settings/AccountSettingsListModel.cpp
src/components/settings/AccountSettingsModel.cpp
src/components/settings/SettingsModel.cpp
src/logger.cpp
src/main.cpp
)
......@@ -48,6 +49,7 @@ set(HEADERS
src/components/settings/AccountSettingsListModel.hpp
src/components/settings/AccountSettingsModel.hpp
src/components/settings/SettingsModel.hpp
src/logger.hpp
)
set(QRC_RESOURCES
......
#include <QDateTime>
#include "logger.hpp"
#ifdef __linux__
#define RED "\x1B[1;31m"
#define GREEN "\x1B[1;32m"
#define BLUE "\x1B[1;34m"
#define RESET "\x1B[0m"
#else
#define RED ""
#define GREEN ""
#define BLUE ""
#define RESET ""
#endif
// ===================================================================
void qmlLogger (QtMsgType type, const QMessageLogContext &context, const QString &msg) {
QByteArray local_msg = msg.toLocal8Bit();
QByteArray date_time = QDateTime::currentDateTime()
.toString("HH:mm:ss").toLocal8Bit();
switch (type) {
case QtDebugMsg:
fprintf(stderr, GREEN "[%s][Debug]" RESET "%s:%u: %s\n",
date_time.constData(), context.file, context.line, local_msg.constData());
break;
case QtInfoMsg:
fprintf(stderr, BLUE "[%s][Info]" RESET "%s:%u: %s\n",
date_time.constData(), context.file, context.line, local_msg.constData());
break;
case QtWarningMsg:
fprintf(stderr, RED "[%s][Warning]" RESET "%s:%u: %s\n",
date_time.constData(), context.file, context.line, local_msg.constData());
break;
case QtCriticalMsg:
fprintf(stderr, RED "[%s][Critical]" RESET "%s:%u: %s\n",
date_time.constData(), context.file, context.line, local_msg.constData());
break;
case QtFatalMsg:
fprintf(stderr, RED "[%s][Fatal]" RESET "%s:%u: %s\n",
date_time.constData(), context.file, context.line, local_msg.constData());
abort();
}
}
#ifndef LOGGER_H_
#define LOGGER_H_
#include <QtGlobal>
void qmlLogger (QtMsgType type, const QMessageLogContext &context, const QString &msg);
#endif // LOGGER_H_
......@@ -10,30 +10,7 @@
#include "app.hpp"
#include "components/contacts/ContactsListProxyModel.hpp"
#include "components/notification/Notification.hpp"
// ===================================================================
void qmlLogger (QtMsgType type, const QMessageLogContext &context, const QString &msg) {
QByteArray localMsg = msg.toLocal8Bit();
switch (type) {
case QtDebugMsg:
fprintf(stderr, "[Debug]%s:%u: %s\n", context.file, context.line, localMsg.constData());
break;
case QtInfoMsg:
fprintf(stderr, "[Info]%s:%u: %s\n", context.file, context.line, localMsg.constData());
break;
case QtWarningMsg:
fprintf(stderr, "[Warning]%s:%u: %s\n", context.file, context.line, localMsg.constData());
break;
case QtCriticalMsg:
fprintf(stderr, "[Critical]%s:%u: %s\n", context.file, context.line, localMsg.constData());
break;
case QtFatalMsg:
fprintf(stderr, "[Fatal]%s:%u: %s\n", context.file, context.line, localMsg.constData());
abort();
}
}
#include "logger.hpp"
// ===================================================================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment