From 87e4f4d02fc8e4debe180dc0fa44903f7cbb7bfb Mon Sep 17 00:00:00 2001 From: andrew-wuhan-huawei-990-pc Date: Mon, 19 Apr 2021 20:48:41 +0800 Subject: [PATCH 1/2] Use ukui-log4qt instead of message handler module --- debian/control | 3 ++- src/main.cpp | 6 +++++- src/src.pro | 1 + ukuisearch-systemdbus/main.cpp | 5 ++++- ukuisearch-systemdbus/ukuisearch-systemdbus.pro | 2 ++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/debian/control b/debian/control index 411e22f..3a03d6d 100644 --- a/debian/control +++ b/debian/control @@ -17,7 +17,8 @@ Build-Depends: debhelper (>=9.0.0), libgsettings-qt-dev, libqt5x11extras5-dev, libuchardet-dev, - libpoppler-qt5-dev + libpoppler-qt5-dev, + libukui-log4qt-dev Standards-Version: 4.5.0 Homepage: https://www.ukui.org/ Vcs-Git: https://github.com/ukui/ukui-search.git diff --git a/src/main.cpp b/src/main.cpp index eb76c89..91c0eb9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include "qt-single-application.h" #include "qt-local-peer.h" @@ -120,6 +121,9 @@ void centerToScreen(QWidget* widget) { int main(int argc, char *argv[]) { + //Init log module + initUkuiLog4qt("ukui-search"); + // Determine whether the home directory has been created, and if not, keep waiting. char *p_home = NULL; @@ -146,7 +150,7 @@ int main(int argc, char *argv[]) } // Output log to file - qInstallMessageHandler(messageOutput); +// qInstallMessageHandler(messageOutput); // Register meta type qDebug() << "ukui-search main start"; diff --git a/src/src.pro b/src/src.pro index 35eff8a..4dec415 100644 --- a/src/src.pro +++ b/src/src.pro @@ -9,6 +9,7 @@ TEMPLATE = app PKGCONFIG += gio-2.0 glib-2.0 gio-unix-2.0 CONFIG += c++11 link_pkgconfig no_keywords lrelease LIBS += -lxapian -lgsettings-qt -lquazip5 -lX11 +LIBS += -lukui-log4qt # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the diff --git a/ukuisearch-systemdbus/main.cpp b/ukuisearch-systemdbus/main.cpp index effc06b..c9cd69f 100644 --- a/ukuisearch-systemdbus/main.cpp +++ b/ukuisearch-systemdbus/main.cpp @@ -20,13 +20,16 @@ #include #include #include - +#include #include #include "sysdbusregister.h" int main(int argc, char *argv[]){ + //init log module + initUkuiLog4qt("ukui-search-service"); + QCoreApplication app(argc, argv); app.setOrganizationName("Kylin Team"); app.setApplicationName("ukui-search-service"); diff --git a/ukuisearch-systemdbus/ukuisearch-systemdbus.pro b/ukuisearch-systemdbus/ukuisearch-systemdbus.pro index 8ceb141..68a47df 100644 --- a/ukuisearch-systemdbus/ukuisearch-systemdbus.pro +++ b/ukuisearch-systemdbus/ukuisearch-systemdbus.pro @@ -9,6 +9,8 @@ TEMPLATE = app CONFIG += console c++11 link_pkgconfig CONFIG -= app_bundle +LIBS += -lukui-log4qt + DESTDIR = . INCLUDEPATH += . From 2cd79a850c18d1ecf7521a5f5f52e25b278034d5 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Wed, 21 Apr 2021 15:30:46 +0800 Subject: [PATCH 2/2] Add uniform log api. --- src/main.cpp | 80 +++++++++---------- ukuisearch-systemdbus/main.cpp | 5 -- .../ukuisearch-systemdbus.pro | 2 - 3 files changed, 40 insertions(+), 47 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ff499ea..276c4dc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -62,50 +62,50 @@ //} -void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) -{ - QByteArray localMsg = msg.toLocal8Bit(); - QByteArray currentTime = QTime::currentTime().toString().toLocal8Bit(); +//void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) +//{ +// QByteArray localMsg = msg.toLocal8Bit(); +// QByteArray currentTime = QTime::currentTime().toString().toLocal8Bit(); - bool showDebug = true; -// QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/ukui-search.log"; -// QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/org.ukui/ukui-search/ukui-search.log"; - QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/org.ukui/ukui-search.log"; - if (!QFile::exists(logFilePath)) { - showDebug = false; - } - FILE *log_file = nullptr; +// bool showDebug = true; +//// QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/ukui-search.log"; +//// QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/org.ukui/ukui-search/ukui-search.log"; +// QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/org.ukui/ukui-search.log"; +// if (!QFile::exists(logFilePath)) { +// showDebug = false; +// } +// FILE *log_file = nullptr; - if (showDebug) { - log_file = fopen(logFilePath.toLocal8Bit().constData(), "a+"); - } +// if (showDebug) { +// log_file = fopen(logFilePath.toLocal8Bit().constData(), "a+"); +// } - const char *file = context.file ? context.file : ""; - const char *function = context.function ? context.function : ""; - switch (type) { - case QtDebugMsg: - if (!log_file) { - break; - } - fprintf(log_file, "Debug: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); - break; - case QtInfoMsg: - fprintf(log_file? log_file: stdout, "Info: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); - break; - case QtWarningMsg: - fprintf(log_file? log_file: stderr, "Warning: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); - break; - case QtCriticalMsg: - fprintf(log_file? log_file: stderr, "Critical: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); - break; - case QtFatalMsg: - fprintf(log_file? log_file: stderr, "Fatal: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); - break; - } +// const char *file = context.file ? context.file : ""; +// const char *function = context.function ? context.function : ""; +// switch (type) { +// case QtDebugMsg: +// if (!log_file) { +// break; +// } +// fprintf(log_file, "Debug: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); +// break; +// case QtInfoMsg: +// fprintf(log_file? log_file: stdout, "Info: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); +// break; +// case QtWarningMsg: +// fprintf(log_file? log_file: stderr, "Warning: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); +// break; +// case QtCriticalMsg: +// fprintf(log_file? log_file: stderr, "Critical: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); +// break; +// case QtFatalMsg: +// fprintf(log_file? log_file: stderr, "Fatal: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); +// break; +// } - if (log_file) - fclose(log_file); -} +// if (log_file) +// fclose(log_file); +//} void centerToScreen(QWidget* widget) { if (!widget) diff --git a/ukuisearch-systemdbus/main.cpp b/ukuisearch-systemdbus/main.cpp index c9cd69f..e30180b 100644 --- a/ukuisearch-systemdbus/main.cpp +++ b/ukuisearch-systemdbus/main.cpp @@ -20,16 +20,11 @@ #include #include #include -#include #include #include "sysdbusregister.h" int main(int argc, char *argv[]){ - - //init log module - initUkuiLog4qt("ukui-search-service"); - QCoreApplication app(argc, argv); app.setOrganizationName("Kylin Team"); app.setApplicationName("ukui-search-service"); diff --git a/ukuisearch-systemdbus/ukuisearch-systemdbus.pro b/ukuisearch-systemdbus/ukuisearch-systemdbus.pro index 68a47df..8ceb141 100644 --- a/ukuisearch-systemdbus/ukuisearch-systemdbus.pro +++ b/ukuisearch-systemdbus/ukuisearch-systemdbus.pro @@ -9,8 +9,6 @@ TEMPLATE = app CONFIG += console c++11 link_pkgconfig CONFIG -= app_bundle -LIBS += -lukui-log4qt - DESTDIR = . INCLUDEPATH += .