From f059f122148ad238daeaed93d6fbb1d8f2f1790c Mon Sep 17 00:00:00 2001 From: houchengqiu Date: Wed, 11 Oct 2023 17:55:48 +0800 Subject: [PATCH] feat: add app log category MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit replace qDebug()、qInfo()、qWarning()、qCritical() width qCDebug()、qCInfo()、qCWarning()、qCCritical() Log: add app log category --- application/DebugTimeManager.cpp | 11 +- application/cliapplicationhelper.cpp | 2 +- application/dbusmanager.cpp | 19 ++-- application/dbusproxy/dldbushandler.cpp | 17 +++- application/displaycontent.cpp | 61 ++++++----- application/journalappwork.cpp | 10 +- application/journalbootwork.cpp | 77 ++++---------- application/journalwork.cpp | 65 +++--------- application/logallexportthread.cpp | 11 +- application/logapplicationhelper.cpp | 17 +++- application/logapplicationparsethread.cpp | 60 ++--------- application/logbackend.cpp | 13 ++- application/logexportthread.cpp | 119 ++++++++++++---------- application/logfileparser.cpp | 11 +- application/logoocfileparsethread.cpp | 11 +- application/main.cpp | 12 ++- application/sharedmemorymanager.cpp | 20 ++-- application/utils.cpp | 11 +- logViewerAuth/viewapplication.cpp | 11 +- logViewerService/logviewerservice.cpp | 27 +++-- logViewerService/main.cpp | 11 +- 21 files changed, 295 insertions(+), 301 deletions(-) diff --git a/application/DebugTimeManager.cpp b/application/DebugTimeManager.cpp index 8cc18a78..97606498 100644 --- a/application/DebugTimeManager.cpp +++ b/application/DebugTimeManager.cpp @@ -1,14 +1,21 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later #include "DebugTimeManager.h" #include #include +#include #include #include +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logDebugTime, "log.viewer.debug.timemanager") +#else +Q_LOGGING_CATEGORY(logDebugTime, "log.viewer.debug.timemanager", QtInfoMsg) +#endif + DebugTimeManager::DebugTimeManager() { @@ -43,7 +50,7 @@ void DebugTimeManager::endPointLinux(const QString &point, const QString &status return; } timespec diffTime = diff(m_MapLinuxPoint[point].time, endTime); - qInfo() << QString("[GRABPOINT] %1 %2 %3 time=%4s").arg(point).arg(m_MapLinuxPoint[point].desc).arg(status).arg(QString::number((diffTime.tv_sec * 1000 + (diffTime.tv_nsec) / 1000000) / 1000.0, 'g', 4)); + qCInfo(logDebugTime) << QString("[GRABPOINT] %1 %2 %3 time=%4s").arg(point).arg(m_MapLinuxPoint[point].desc).arg(status).arg(QString::number((diffTime.tv_sec * 1000 + (diffTime.tv_nsec) / 1000000) / 1000.0, 'g', 4)); m_MapLinuxPoint.remove(point); } } diff --git a/application/cliapplicationhelper.cpp b/application/cliapplicationhelper.cpp index c12ae342..4207d443 100644 --- a/application/cliapplicationhelper.cpp +++ b/application/cliapplicationhelper.cpp @@ -16,7 +16,7 @@ using HelperCreator = CliApplicationHelper::HelperCreator; #ifdef QT_DEBUG -Q_LOGGING_CATEGORY(dgAppHelper, "deepin-logger") +Q_LOGGING_CATEGORY(dgAppHelper, "deepin.logger") #else Q_LOGGING_CATEGORY(dgAppHelper, "deepin.logger", QtInfoMsg) #endif diff --git a/application/dbusmanager.cpp b/application/dbusmanager.cpp index 6e2bb72f..6c0993c5 100644 --- a/application/dbusmanager.cpp +++ b/application/dbusmanager.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -10,6 +10,13 @@ #include #include #include +#include + +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logDBusManager, "log.viewer.dbus.manager") +#else +Q_LOGGING_CATEGORY(logDBusManager, "log.viewer.dbus.manager", QtInfoMsg) +#endif bool DBusManager::isGetedKlu = false; QString DBusManager::isklusystemName = ""; @@ -41,7 +48,7 @@ QString DBusManager::getSystemInfo() .property("ProductName") .toString(); } else { - qWarning() << "Unknown OS version:" << osVersion; + qCWarning(logDBusManager) << "Unknown OS version:" << osVersion; } isGetedKlu = true; } @@ -55,14 +62,14 @@ bool DBusManager::isSEOepn() if (interfaceSE.isValid()) { QDBusReply reply = interfaceSE.call(QStringLiteral("Status")); if (!reply.error().message().isEmpty()) - qWarning() << qPrintable(QString("com.deepin.daemon.SecurityEnhance.Status DBus error: %1").arg(reply.error().message())); + qCWarning(logDBusManager) << qPrintable(QString("com.deepin.daemon.SecurityEnhance.Status DBus error: %1").arg(reply.error().message())); if (reply.value() == "close") bIsSEOpen = false; else bIsSEOpen = true; } else { - qWarning() << qPrintable(QString("isSEOpen failed! interface error: %1").arg(interfaceSE.lastError().message())); + qCWarning(logDBusManager) << qPrintable(QString("isSEOpen failed! interface error: %1").arg(interfaceSE.lastError().message())); } return bIsSEOpen; @@ -81,12 +88,12 @@ bool DBusManager::isAuditAdmin() if (interfaceSE.isValid()) { QDBusReply reply = interfaceSE.call(QStringLiteral("GetSEUserByName"), currentUserName); if (!reply.error().message().isEmpty()) - qWarning() << qPrintable(QString("com.deepin.daemon.SecurityEnhance.GetSEUserByName DBus error: %1").arg(reply.error().message())); + qCWarning(logDBusManager) << qPrintable(QString("com.deepin.daemon.SecurityEnhance.GetSEUserByName DBus error: %1").arg(reply.error().message())); if (reply.value() == "audadm_u" || reply.value() == "auditadm_u") bIsAuditAdmin = true; } else { - qWarning() << qPrintable(QString("isAuditAdmin failed! interface error: %1").arg(interfaceSE.lastError().message())); + qCWarning(logDBusManager) << qPrintable(QString("isAuditAdmin failed! interface error: %1").arg(interfaceSE.lastError().message())); } return bIsAuditAdmin; diff --git a/application/dbusproxy/dldbushandler.cpp b/application/dbusproxy/dldbushandler.cpp index dde8dda8..1bfadeb7 100644 --- a/application/dbusproxy/dldbushandler.cpp +++ b/application/dbusproxy/dldbushandler.cpp @@ -1,10 +1,17 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later #include "dldbushandler.h" #include #include +#include + +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logDBusHandler, "log.viewer.dbus.handler") +#else +Q_LOGGING_CATEGORY(logDBusHandler, "log.viewer.dbus.handler", QtInfoMsg) +#endif DLDBusHandler *DLDBusHandler::m_statichandeler = nullptr; @@ -30,9 +37,9 @@ DLDBusHandler::DLDBusHandler(QObject *parent) this); //Note: when dealing with remote objects, it is not always possible to determine if it exists when creating a QDBusInterface. if (!m_dbus->isValid() && !m_dbus->lastError().message().isEmpty()) { - qCritical() << "dbus com.deepin.logviewer isValid false error:" << m_dbus->lastError() << m_dbus->lastError().message(); + qCCritical(logDBusHandler) << "dbus com.deepin.logviewer isValid false error:" << m_dbus->lastError() << m_dbus->lastError().message(); } - qInfo() << "dbus com.deepin.logviewer isValid true"; + qCInfo(logDBusHandler) << "dbus com.deepin.logviewer isValid true"; } /*! @@ -77,7 +84,7 @@ QStringList DLDBusHandler::getFileInfo(const QString &flag, bool unzip) QDBusPendingReply reply = m_dbus->getFileInfo(flag, unzip); reply.waitForFinished(); if (reply.isError()) { - qWarning() << "call dbus iterface 'getFileInfo()' failed. error info:" << reply.error().message(); + qCWarning(logDBusHandler) << "call dbus iterface 'getFileInfo()' failed. error info:" << reply.error().message(); } else { filePath = reply.value(); } @@ -90,7 +97,7 @@ QStringList DLDBusHandler::getOtherFileInfo(const QString &flag, bool unzip) reply.waitForFinished(); QStringList filePathList; if (reply.isError()) { - qWarning() << "call dbus iterface 'getOtherFileInfo()' failed. error info:" << reply.error().message(); + qCWarning(logDBusHandler) << "call dbus iterface 'getOtherFileInfo()' failed. error info:" << reply.error().message(); } else { filePathList = reply.value(); } diff --git a/application/displaycontent.cpp b/application/displaycontent.cpp index 32d64771..11aeab9f 100644 --- a/application/displaycontent.cpp +++ b/application/displaycontent.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -37,11 +37,18 @@ #include #include #include +#include #include #include "malloc.h" DWIDGET_USE_NAMESPACE +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logDisplaycontent, "log.viewer.display.content") +#else +Q_LOGGING_CATEGORY(logDisplaycontent, "log.viewer.display.content", QtInfoMsg) +#endif + #define SINGLE_LOAD 300 #define NAME_WIDTH 470 @@ -305,7 +312,7 @@ void DisplayContent::generateJournalFile(int id, int lId, const QString &iSearch Q_UNUSED(iSearchStr) //系统日志上次获取的时间,和筛选条件一起判断,防止获取过于频繁 if (m_lastJournalGetTime.msecsTo(QDateTime::currentDateTime()) < 500 && m_journalFilter.timeFilter == id && m_journalFilter.eventTypeFilter == lId) { - qWarning() << "load journal log: repeat refrsh journal too fast!"; + qCWarning(logDisplaycontent) << "load journal log: repeat refrsh journal too fast!"; QItemSelectionModel *p = m_treeView->selectionModel(); if (p) p->select(m_pModel->index(0, 0), QItemSelectionModel::Rows | QItemSelectionModel::Select); @@ -1664,7 +1671,7 @@ void DisplayContent::slot_exportClicked() if (!fi.isWritable()) { exportThread->sigResult(false); delete exportThread; - qCritical() << QString("outdir:%1 is not writable.").arg(fi.absoluteFilePath()); + qCCritical(logDisplaycontent) << QString("outdir:%1 is not writable.").arg(fi.absoluteFilePath()); return; } @@ -2716,11 +2723,11 @@ void DisplayContent::slot_getAuditType(int tcbx) void DisplayContent::parseListToModel(const QList &iList, QStandardItemModel *oPModel) { if (!oPModel) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } if (iList.isEmpty()) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } QList list = iList; @@ -2753,12 +2760,12 @@ void DisplayContent::parseListToModel(const QList &iList, QStandar void DisplayContent::parseListToModel(const QList &iList, QStandardItemModel *oPModel) { if (!oPModel) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } if (iList.isEmpty()) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } QList list = iList; @@ -2786,12 +2793,12 @@ void DisplayContent::parseListToModel(const QList &iList, QStandar void DisplayContent::parseListToModel(QList iList, QStandardItemModel *oPModel) { if (!oPModel) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } if (iList.isEmpty()) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } QList items; @@ -2835,12 +2842,12 @@ void DisplayContent::parseListToModel(QList iList, QStandar void DisplayContent::parseListToModel(QList iList, QStandardItemModel *oPModel) { if (!oPModel) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } if (iList.isEmpty()) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } DStandardItem *item = nullptr; @@ -2868,12 +2875,12 @@ void DisplayContent::parseListToModel(QList iList, QStandardItemMo void DisplayContent::parseListToModel(QList iList, QStandardItemModel *oPModel) { if (!oPModel) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } if (iList.isEmpty()) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } DStandardItem *item = nullptr; @@ -2909,12 +2916,12 @@ void DisplayContent::parseListToModel(QList iList, QStandardItem void DisplayContent::parseListToModel(QList iList, QStandardItemModel *oPModel) { if (!oPModel) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } if (iList.isEmpty()) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } DStandardItem *item = nullptr; @@ -2933,12 +2940,12 @@ void DisplayContent::parseListToModel(QList iList, QStandardItemMo void DisplayContent::parseListToModel(QList iList, QStandardItemModel *oPModel) { if (!oPModel) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } if (iList.isEmpty()) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } QList items; @@ -2969,12 +2976,12 @@ void DisplayContent::parseListToModel(QList iList, QStandardItemMod void DisplayContent::parseListToModel(QList iList, QStandardItemModel *oPModel) { if (!oPModel) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } if (iList.isEmpty()) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } QList items; @@ -3004,12 +3011,12 @@ void DisplayContent::parseListToModel(QList iList, QStandardItemM void DisplayContent::parseListToModel(QList iList, QStandardItemModel *oPModel) { if (!oPModel) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } if (iList.isEmpty()) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } QList items; @@ -3031,12 +3038,12 @@ void DisplayContent::parseListToModel(QList iList, QStan void DisplayContent::parseListToModel(QList iList, QStandardItemModel *oPModel) { if (!oPModel) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } if (iList.isEmpty()) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } QList items; @@ -3072,12 +3079,12 @@ void DisplayContent::parseListToModel(QList iList, QStandardItemM void DisplayContent::parseListToModel(QList iList, QStandardItemModel *oPModel) { if (!oPModel) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } if (iList.isEmpty()) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } QList items; @@ -3528,12 +3535,12 @@ void DisplayContent::onExportProgress(int nCur, int nTotal) void DisplayContent::parseListToModel(QList iList, QStandardItemModel *oPModel) { if (!oPModel) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } if (iList.isEmpty()) { - qWarning() << "parse model is Empty" << __LINE__; + qCWarning(logDisplaycontent) << "parse model is Empty" << __LINE__; return; } DStandardItem *item = nullptr; diff --git a/application/journalappwork.cpp b/application/journalappwork.cpp index 09817da9..a1b831c1 100644 --- a/application/journalappwork.cpp +++ b/application/journalappwork.cpp @@ -11,6 +11,12 @@ #include #include +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logJournalApp, "log.viewer.journal.app.work") +#else +Q_LOGGING_CATEGORY(logJournalApp, "log.viewer.journal.app.work", QtInfoMsg) +#endif + DWIDGET_USE_NAMESPACE int JournalAppWork::thread_index; @@ -70,7 +76,7 @@ JournalAppWork::~JournalAppWork() */ void JournalAppWork::stopWork() { - qDebug() << "stopWork"; + qCDebug(logJournalApp) << "stopWork"; m_canRun = false; } @@ -109,7 +115,7 @@ void JournalAppWork::setArg(QStringList arg) */ void JournalAppWork::run() { - qDebug() << "threadrun"; + qCDebug(logJournalApp) << "threadrun"; doWork(); } diff --git a/application/journalbootwork.cpp b/application/journalbootwork.cpp index 3c212fb2..624a1ba7 100644 --- a/application/journalbootwork.cpp +++ b/application/journalbootwork.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -13,6 +13,13 @@ #include #include #include +#include + +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logJournalboot, "log.viewer.journal.boot.work") +#else +Q_LOGGING_CATEGORY(logJournalboot, "log.viewer.journal.boot.work", QtInfoMsg) +#endif DWIDGET_USE_NAMESPACE @@ -73,7 +80,7 @@ JournalBootWork::~JournalBootWork() void JournalBootWork::stopWork() { m_canRun = false; - qDebug() << "stopWork"; + qCDebug(logJournalboot) << "stopWork"; } /** @@ -110,7 +117,7 @@ void JournalBootWork::setArg(QStringList arg) */ void JournalBootWork::run() { - qDebug() << "threadrun"; + qCDebug(logJournalboot) << "threadrun"; doWork(); } @@ -131,7 +138,7 @@ void JournalBootWork::doWork() mutex.unlock(); return; } -#if 1 + int r; sd_journal *j ; if ((!m_canRun)) { @@ -148,7 +155,7 @@ void JournalBootWork::doWork() //r为系统借口返回值,小于0则表示失败,直接返回 if (r < 0) { QString errostr = QString("Failed to open journal: %1").arg(r); - qWarning() << errostr; + qCWarning(logJournalboot) << errostr; emit journalBootError(errostr); return; } @@ -157,7 +164,7 @@ void JournalBootWork::doWork() if (r < 0) { QString errostr = QString("Failed to seek tail journal: %1").arg(r); - qWarning() << errostr; + qCWarning(logJournalboot) << errostr; emit journalBootError(errostr); return; } @@ -174,7 +181,7 @@ void JournalBootWork::doWork() r = sd_journal_add_match(j, m_arg.at(0).toStdString().c_str(), 0); if (r < 0) { QString errostr = QString("Failed to add match journal: %1").arg(r); - qWarning() << errostr; + qCWarning(logJournalboot) << errostr; emit journalBootError(errostr); return; } @@ -201,12 +208,12 @@ void JournalBootWork::doWork() sd_journal_close(j); return; } - qDebug() << "journal match condition:" << match; + qCDebug(logJournalboot) << "journal match condition:" << match; //增加筛选条件 r = sd_journal_add_match(j, match, sizeof(match) - 1); if (r < 0) { QString errostr = QString("Failed to add match journal: %1").arg(r); - qWarning() << errostr; + qCWarning(logJournalboot) << errostr; emit journalBootError(errostr); return; } @@ -214,7 +221,7 @@ void JournalBootWork::doWork() r = sd_journal_add_conjunction(j); if (r < 0) { QString errostr = QString("Failed to add conjunction journal: %1").arg(r); - qWarning() << errostr; + qCWarning(logJournalboot) << errostr; emit journalBootError(errostr); return; } @@ -276,7 +283,7 @@ void JournalBootWork::doWork() r = sd_journal_get_data(j, "_COMM", reinterpret_cast(&d), &l); if (r < 0) { logMsg.daemonName = "unknown"; - qWarning() << logMsg.daemonId << "error code" << r; + qCWarning(logJournalboot) << logMsg.daemonId << "error code" << r; } else { QStringList strList = getReplaceColorStr(d).split("="); strList.removeFirst(); @@ -325,54 +332,6 @@ void JournalBootWork::doWork() emit journalBootFinished(m_threadIndex); //第一次加载时这个之后的代码都不执行?故放到最后 sd_journal_close(j); - -#else - proc = new QProcess; - //! by time: --since="xxxx-xx-xx" --until="xxxx-xx-xx" exclude U - //! by priority: journalctl PRIORITY=x - proc->start("journalctl", m_arg); - proc->waitForFinished(-1); - - QByteArray output = proc->readAllStandardOutput(); - proc->close(); - - // reverse by time - QList arrayList = output.split('\n'); - for (auto i = arrayList.count() - 1; i >= 0; i--) { - QByteArray data = arrayList.at(i); - // for (QByteArray data : output.split('\n')) { - if (data.isEmpty()) - continue; - - LOG_MSG_JOURNAL logMsg; - - cnt++; - - QJsonParseError erro; - QJsonDocument jsonDoc(QJsonDocument::fromJson(data, &erro)); - - if (erro.error != QJsonParseError::NoError) { - qDebug() << "erro" << erro.error << erro.errorString(); - continue; - } - QJsonObject jsonObj = jsonDoc.object(); - // fill field - QString dt = jsonObj.value("_SOURCE_REALTIME_TIMESTAMP").toString(); - if (dt.isEmpty()) - dt = jsonObj.value("__REALTIME_TIMESTAMP").toString(); - logMsg.dateTime = getDateTimeFromStamp(dt); - logMsg.hostName = jsonObj.value("_HOSTNAME").toString(); - logMsg.daemonName = jsonObj.value("_COMM").toString(); - logMsg.daemonId = jsonObj.value("_PID").toString(); - logMsg.msg = jsonObj.value("MESSAGE").toString(); - logMsg.level = i2str(jsonObj.value("PRIORITY").toString().toInt()); - logList.append(logMsg); - if (cnt == 500) - break; - } - - emit journalFinished(logList); -#endif } /** diff --git a/application/journalwork.cpp b/application/journalwork.cpp index 65011ebe..bbee65db 100644 --- a/application/journalwork.cpp +++ b/application/journalwork.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -13,6 +13,13 @@ #include #include #include +#include + +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logJournal, "log.viewer.journal.work") +#else +Q_LOGGING_CATEGORY(logJournal, "log.viewer.journal.work", QtInfoMsg) +#endif DWIDGET_USE_NAMESPACE @@ -75,7 +82,7 @@ journalWork::~journalWork() */ void journalWork::stopWork() { - qDebug() << "stopWork"; + qCDebug(logJournal) << "stopWork"; m_canRun = false; } @@ -114,7 +121,7 @@ void journalWork::setArg(QStringList arg) */ void journalWork::run() { - qDebug() << "threadrun"; + qCDebug(logJournal) << "threadrun"; doWork(); } @@ -133,7 +140,7 @@ void journalWork::doWork() mutex.unlock(); return; } -#if 1 + int r; sd_journal *j ; @@ -225,7 +232,7 @@ void journalWork::doWork() r = sd_journal_get_data(j, "SYSLOG_IDENTIFIER", reinterpret_cast(&d), &l); if (r < 0) { logMsg.daemonName = "unknown"; - qWarning() << logMsg.daemonId << "error code" << r; + qCWarning(logJournal) << logMsg.daemonId << "error code" << r; } else { QStringList strList = getReplaceColorStr(d).split("="); strList.removeFirst(); @@ -274,54 +281,6 @@ void journalWork::doWork() emit journalFinished(m_threadIndex); //第一次加载时这个之后的代码都不执行?故放到最后 sd_journal_close(j); - -#else - proc = new QProcess; - //! by time: --since="xxxx-xx-xx" --until="xxxx-xx-xx" exclude U - //! by priority: journalctl PRIORITY=x - proc->start("journalctl", m_arg); - proc->waitForFinished(-1); - - QByteArray output = proc->readAllStandardOutput(); - proc->close(); - - // reverse by time - QList arrayList = output.split('\n'); - for (auto i = arrayList.count() - 1; i >= 0; i--) { - QByteArray data = arrayList.at(i); - // for (QByteArray data : output.split('\n')) { - if (data.isEmpty()) - continue; - - LOG_MSG_JOURNAL logMsg; - - cnt++; - - QJsonParseError erro; - QJsonDocument jsonDoc(QJsonDocument::fromJson(data, &erro)); - - if (erro.error != QJsonParseError::NoError) { - qDebug() << "erro" << erro.error << erro.errorString(); - continue; - } - QJsonObject jsonObj = jsonDoc.object(); - // fill field - QString dt = jsonObj.value("_SOURCE_REALTIME_TIMESTAMP").toString(); - if (dt.isEmpty()) - dt = jsonObj.value("__REALTIME_TIMESTAMP").toString(); - logMsg.dateTime = getDateTimeFromStamp(dt); - logMsg.hostName = jsonObj.value("_HOSTNAME").toString(); - logMsg.daemonName = jsonObj.value("_COMM").toString(); - logMsg.daemonId = jsonObj.value("_PID").toString(); - logMsg.msg = jsonObj.value("MESSAGE").toString(); - logMsg.level = i2str(jsonObj.value("PRIORITY").toString().toInt()); - logList.append(logMsg); - if (cnt == 500) - break; - } - - emit journalFinished(logList); -#endif } /** diff --git a/application/logallexportthread.cpp b/application/logallexportthread.cpp index 701aed04..a92703d6 100644 --- a/application/logallexportthread.cpp +++ b/application/logallexportthread.cpp @@ -7,6 +7,13 @@ #include "logapplicationhelper.h" #include "utils.h" +#include +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logExportAll, "log.viewer.exportall.work") +#else +Q_LOGGING_CATEGORY(logExportAll, "log.viewer.exportall.work", QtInfoMsg) +#endif + LogAllExportThread::LogAllExportThread(const QStringList &types, const QString &outfile, QObject *parent) : QObject(parent) , m_types(types) @@ -17,10 +24,10 @@ LogAllExportThread::LogAllExportThread(const QStringList &types, const QString & void LogAllExportThread::run() { //判断权限 - qInfo() << "outFile: " << m_outfile; + qCInfo(logExportAll) << "outFile: " << m_outfile; QFileInfo info(m_outfile); if (!QFileInfo(info.path()).isWritable()) { - qCritical() << QString("outdir:%1 it not writable or is not exist.").arg(info.absolutePath()); + qCCritical(logExportAll) << QString("outdir:%1 it not writable or is not exist.").arg(info.absolutePath()); emit exportFinsh(false); return; } diff --git a/application/logapplicationhelper.cpp b/application/logapplicationhelper.cpp index b6341a04..e46d50e3 100644 --- a/application/logapplicationhelper.cpp +++ b/application/logapplicationhelper.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -11,6 +11,13 @@ #include #include #include +#include + +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logAppHelper, "log.viewer.application.helper") +#else +Q_LOGGING_CATEGORY(logAppHelper, "log.viewer.application.helper", QtInfoMsg) +#endif std::atomic LogApplicationHelper::m_instance; std::mutex LogApplicationHelper::m_mutex; @@ -151,7 +158,7 @@ void LogApplicationHelper::initCustomLog() // 判断配置是否有效 if (!m_pDConfig->isValid()) { - qWarning() << QString("DConfig is invalide, name:[%1], subpath[%2].").arg(m_pDConfig->name(), m_pDConfig->subpath()); + qCWarning(logAppHelper) << QString("DConfig is invalide, name:[%1], subpath[%2].").arg(m_pDConfig->name(), m_pDConfig->subpath()); m_pDConfig->deleteLater(); m_pDConfig = nullptr; return; @@ -205,7 +212,7 @@ void LogApplicationHelper::initCustomLog() m_custom_log_list.append(QStringList() << QFileInfo(iter).fileName() << path); } } else { - qWarning() << "cannot find gsettings config file"; + qCWarning(logAppHelper) << "cannot find gsettings config file"; } } } @@ -454,7 +461,7 @@ void LogApplicationHelper::loadAppLogConfigs() QDir dir(APP_LOG_CONFIG_PATH); if (!dir.exists()) { - qWarning() << QString("%1 does not exist.").arg(APP_LOG_CONFIG_PATH); + qCWarning(logAppHelper) << QString("%1 does not exist.").arg(APP_LOG_CONFIG_PATH); return; } @@ -485,7 +492,7 @@ void LogApplicationHelper::loadAppLogConfigs() logConfig.logType = object.value("logType").toString(); } - qInfo() << QString("name:%1 exec:%2 logType:%3 logPath:%4 visible:%5").arg(logConfig.name).arg(logConfig.execPath).arg(logConfig.logType).arg(logConfig.logPath).arg(logConfig.visible); + qCInfo(logAppHelper) << QString("name:%1 exec:%2 logType:%3 logPath:%4 visible:%5").arg(logConfig.name).arg(logConfig.execPath).arg(logConfig.logType).arg(logConfig.logPath).arg(logConfig.visible); m_appLogConfigs.push_back(logConfig); } diff --git a/application/logapplicationparsethread.cpp b/application/logapplicationparsethread.cpp index 81849ad8..0d7738c3 100644 --- a/application/logapplicationparsethread.cpp +++ b/application/logapplicationparsethread.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -12,6 +12,14 @@ #include #include +#include + +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logFileApp, "log.viewer.file.app.work") +#else +Q_LOGGING_CATEGORY(logFileApp, "log.viewer.file.app.work", QtInfoMsg) +#endif + DWIDGET_USE_NAMESPACE //std::atomic LogApplicationParseThread::m_instance; @@ -101,12 +109,11 @@ void LogApplicationParseThread::doWork() return; } LOG_MSG_APPLICATOIN msg; - QString str =strList[j]; + QString str = strList[j]; QRegularExpressionMatch match = re.match(str); bool matchRes = match.hasMatch(); if(!matchRes){ - qWarning()<<"not match ,Format problem"; continue; } @@ -158,51 +165,6 @@ void LogApplicationParseThread::doWork() void LogApplicationParseThread::onProcFinished(int ret) { Q_UNUSED(ret) -#if 0 - QProcess *proc = dynamic_cast(sender()); - QString output = proc->readAllStandardOutput(); - proc->deleteLater(); - - for (QString str : output.split('\n')) { - LOG_MSG_APPLICATOIN msg; - - str.replace(QRegExp("\\s{2,}"), ""); - - QStringList list = str.split("]", QString::SkipEmptyParts); - if (list.count() < 3) - continue; - - QString dateTime = list[0].split("[", QString::SkipEmptyParts)[0].trimmed(); - if (dateTime.contains(",")) { - dateTime.replace(",", ""); - } - // if (dateTime.split(".").count() == 2) { - // dateTime = dateTime.split(".")[0]; - // } - qint64 dt = QDateTime::fromString(dateTime, "yyyy-MM-dd hh:mm:ss.zzz").toMSecsSinceEpoch(); - if (dt < m_periorTime) - continue; - msg.dateTime = dateTime; - msg.level = list[0].split("[", QString::SkipEmptyParts)[1]; - - if (m_level != LVALL) { - if (m_levelDict.value(msg.level) != m_level) - continue; - } - - msg.src = list[1].split("[", QString::SkipEmptyParts)[1]; - - if (list.count() >= 4) { - msg.msg = list.mid(2).join("]"); - } else { - msg.msg = list[2]; - } - - m_appList.insert(0, msg); - } - - emit appCmdFinished(m_appList); -#endif } /** @@ -231,6 +193,6 @@ void LogApplicationParseThread::initProccess() */ void LogApplicationParseThread::run() { - qDebug() << "threadrun"; + qCDebug(logFileApp) << "threadrun"; doWork(); } diff --git a/application/logbackend.cpp b/application/logbackend.cpp index 4908328b..747b44fa 100644 --- a/application/logbackend.cpp +++ b/application/logbackend.cpp @@ -17,6 +17,13 @@ #include #include #include +#include + +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logBackend, "log.viewer.backend") +#else +Q_LOGGING_CATEGORY(logBackend, "log.viewer.backend", QtInfoMsg) +#endif LogBackend *LogBackend::m_staticbackend = nullptr; @@ -47,7 +54,7 @@ void LogBackend::setCmdWorkDir(const QString &dir) void LogBackend::exportAllLogs(const QString &outDir) { PERF_PRINT_BEGIN("POINT-05", "export all logs"); - qInfo() << "exporting all logs begin."; + qCInfo(logBackend) << "exporting all logs begin."; // 时间 QString dateTime = QDateTime::currentDateTime().toString("yyyyMMddHHmmss"); @@ -84,11 +91,11 @@ void LogBackend::exportAllLogs(const QString &outDir) thread->setAutoDelete(true); connect(thread, &LogAllExportThread::exportFinsh, this, [ = ](bool ret) { if (ret) { - qInfo() << "exporting all logs done."; + qCInfo(logBackend) << "exporting all logs done."; PERF_PRINT_END("POINT-05", "cost"); qApp->quit(); } else { - qWarning() << "exporting all logs stoped."; + qCWarning(logBackend) << "exporting all logs stoped."; // 导出失败,若为用户指定的新目录,应清除 if (m_newDir) { QDir odir(outPath); diff --git a/application/logexportthread.cpp b/application/logexportthread.cpp index de9418d0..90b49e8c 100644 --- a/application/logexportthread.cpp +++ b/application/logexportthread.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -20,10 +20,17 @@ #include #include #include +#include #include DWIDGET_USE_NAMESPACE +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logExport, "log.viewer.export.work") +#else +Q_LOGGING_CATEGORY(logExport, "log.viewer.export.work", QtInfoMsg) +#endif + /** * @brief LogExportThread::LogExportThread 导出日志线程类构造函数 * @param parent 父对象 @@ -736,7 +743,7 @@ bool LogExportThread::exportToTxt(const QString &fileName, QStandardItemModel *p } } catch (const QString &ErrorStr) { //捕获到异常,导出失败,发出失败信号 - qWarning() << "Export Stop" << ErrorStr; + qCWarning(logExport) << "Export Stop" << ErrorStr; fi.close(); emit sigResult(false); if (ErrorStr != stopStr) { @@ -825,7 +832,7 @@ bool LogExportThread::exportToTxt(const QString &fileName, const QList\n"); } catch (const QString &ErrorStr) { //捕获到异常,导出失败,发出失败信号 - qWarning() << "Export Stop" << ErrorStr; + qCWarning(logExport) << "Export Stop" << ErrorStr; html.close(); emit sigResult(false); if (ErrorStr != stopStr) { @@ -2220,7 +2227,7 @@ bool LogExportThread::exportToHtml(const QString &fileName, const QList\n"); } catch (const QString &ErrorStr) { //捕获到异常,导出失败,发出失败信号 - qWarning() << "Export Stop" << ErrorStr; + qCWarning(logExport) << "Export Stop" << ErrorStr; html.close(); emit sigResult(false); if (ErrorStr != stopStr) { @@ -2293,7 +2300,7 @@ bool LogExportThread::exportToHtml(const QString &fileName, const QList\n"); } catch (const QString &ErrorStr) { //捕获到异常,导出失败,发出失败信号 - qWarning() << "Export Stop" << ErrorStr; + qCWarning(logExport) << "Export Stop" << ErrorStr; html.close(); emit sigResult(false); if (ErrorStr != stopStr) { @@ -2363,7 +2370,7 @@ bool LogExportThread::exportToHtml(const QString &fileName, const QList\n"); } catch (const QString &ErrorStr) { //捕获到异常,导出失败,发出失败信号 - qWarning() << "Export Stop" << ErrorStr; + qCWarning(logExport) << "Export Stop" << ErrorStr; html.close(); emit sigResult(false); if (ErrorStr != stopStr) { @@ -2431,7 +2438,7 @@ bool LogExportThread::exportToHtml(const QString &fileName, const QList\n"); } catch (const QString &ErrorStr) { //捕获到异常,导出失败,发出失败信号 - qWarning() << "Export Stop" << ErrorStr; + qCWarning(logExport) << "Export Stop" << ErrorStr; html.close(); emit sigResult(false); if (ErrorStr != stopStr) { @@ -2499,7 +2506,7 @@ bool LogExportThread::exportToHtml(const QString &fileName, const QList\n"); } catch (const QString &ErrorStr) { //捕获到异常,导出失败,发出失败信号 - qWarning() << "Export Stop" << ErrorStr; + qCWarning(logExport) << "Export Stop" << ErrorStr; html.close(); emit sigResult(false); if (ErrorStr != stopStr) { @@ -2571,7 +2578,7 @@ bool LogExportThread::exportToHtml(const QString &fileName, const QList\n"); } catch (const QString &ErrorStr) { //捕获到异常,导出失败,发出失败信号 - qWarning() << "Export Stop" << ErrorStr; + qCWarning(logExport) << "Export Stop" << ErrorStr; html.close(); emit sigResult(false); if (ErrorStr != stopStr) { @@ -2637,7 +2644,7 @@ bool LogExportThread::exportToHtml(const QString &fileName, const QList\n"); } catch (const QString &ErrorStr) { //捕获到异常,导出失败,发出失败信号 - qWarning() << "Export Stop" << ErrorStr; + qCWarning(logExport) << "Export Stop" << ErrorStr; html.close(); emit sigResult(false); if (ErrorStr != stopStr) { @@ -2701,7 +2708,7 @@ bool LogExportThread::exportToHtml(const QString &fileName, const QList\n"); } catch (const QString &ErrorStr) { //捕获到异常,导出失败,发出失败信号 - qWarning() << "Export Stop" << ErrorStr; + qCWarning(logExport) << "Export Stop" << ErrorStr; html.close(); emit sigResult(false); if (ErrorStr != stopStr) { @@ -2765,7 +2772,7 @@ bool LogExportThread::exportToHtml(const QString &fileName, const QList\n"); } catch (const QString &ErrorStr) { //捕获到异常,导出失败,发出失败信号 - qWarning() << "Export Stop" << ErrorStr; + qCWarning(logExport) << "Export Stop" << ErrorStr; html.close(); emit sigResult(false); if (ErrorStr != stopStr) { @@ -2832,7 +2839,7 @@ bool LogExportThread::exportToHtml(const QString &fileName, const QList\n"); } catch (const QString &ErrorStr) { //捕获到异常,导出失败,发出失败信号 - qWarning() << "Export Stop" << ErrorStr; + qCWarning(logExport) << "Export Stop" << ErrorStr; html.close(); emit sigResult(false); if (ErrorStr != stopStr) { @@ -2899,7 +2906,7 @@ bool LogExportThread::exportToXls(const QString &fileName, const QList #include #include +#include #include #include #include +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logFileParser, "log.viewer.file.parser") +#else +Q_LOGGING_CATEGORY(logFileParser, "log.viewer.file.parser", QtInfoMsg) +#endif + int journalWork::thread_index = 0; int JournalBootWork::thread_index = 0; DWIDGET_USE_NAMESPACE @@ -289,7 +296,7 @@ int LogFileParser::parseByApp(const APP_FILTERS &iAPPFilter) QString appName = Utils::appName(iAPPFilter.path); AppLogConfig appLogConfig = LogApplicationHelper::instance()->appLogConfig(appName); - qDebug() << QString("parsing app log, appName:%1 applogType:%2 path:%3").arg(appName).arg(appLogConfig.logType).arg(iAPPFilter.path); + qCDebug(logFileParser) << QString("parsing app log, appName:%1 applogType:%2 path:%3").arg(appName).arg(appLogConfig.logType).arg(iAPPFilter.path); // 确定解析方式 QString parseType = "file"; diff --git a/application/logoocfileparsethread.cpp b/application/logoocfileparsethread.cpp index aa2b6ae1..4169cf1d 100644 --- a/application/logoocfileparsethread.cpp +++ b/application/logoocfileparsethread.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -12,9 +12,16 @@ #include #include #include +#include DWIDGET_USE_NAMESPACE +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logOOCParse, "log.viewer.oocparse.work") +#else +Q_LOGGING_CATEGORY(logOOCParse, "log.viewer.oocparse.work", QtInfoMsg) +#endif + int LogOOCFileParseThread::thread_count = 0; /** * @brief LogOOCFileParseThread::LogOOCFileParseThread 构造函数 @@ -145,7 +152,7 @@ bool LogOOCFileParseThread::checkAuthentication(const QString &path) */ void LogOOCFileParseThread::run() { - qDebug() << "threadrun"; + qCDebug(logOOCParse) << "threadrun"; doWork(); } diff --git a/application/main.cpp b/application/main.cpp index f5ef9d53..88fa1867 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -23,9 +23,17 @@ #include #include #include +#include + DWIDGET_USE_NAMESPACE DCORE_USE_NAMESPACE +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logAppMain, "log.viewer.main") +#else +Q_LOGGING_CATEGORY(logAppMain, "log.viewer.main", QtInfoMsg) +#endif + int main(int argc, char *argv[]) { //在root下或者非deepin/uos环境下运行不会发生异常,需要加上XDG_CURRENT_DESKTOP=Deepin环境变量; @@ -136,7 +144,7 @@ int main(int argc, char *argv[]) if (!DGuiApplicationHelper::instance()->setSingleInstance(a.applicationName(), DGuiApplicationHelper::UserScope)) { - qCritical() << "DGuiApplicationHelper::instance()->setSingleInstance"; + qCCritical(logAppMain) << "DGuiApplicationHelper::instance()->setSingleInstance"; a.activeWindow(); return 0; } diff --git a/application/sharedmemorymanager.cpp b/application/sharedmemorymanager.cpp index 8105d0f2..fd635ea2 100644 --- a/application/sharedmemorymanager.cpp +++ b/application/sharedmemorymanager.cpp @@ -1,10 +1,18 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later #include "sharedmemorymanager.h" #include #include +#include + +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logSM, "log.viewer.share.memory.manager") +#else +Q_LOGGING_CATEGORY(logSM, "log.viewer.share.memory.manager", QtInfoMsg) +#endif + #define LOG_POLIKIT_STOP_TAG "LOGAUTHCONTROL" std::atomic SharedMemoryManager::m_instance; std::mutex SharedMemoryManager::m_mutex; @@ -17,12 +25,12 @@ SharedMemoryManager::SharedMemoryManager(QObject *parent) void SharedMemoryManager::setRunnableTag(ShareMemoryInfo iShareInfo) { m_commondM->lock(); - qDebug() << "ShareMemoryInfo.isStart:" << iShareInfo.isStart; + qCDebug(logSM) << "ShareMemoryInfo.isStart:" << iShareInfo.isStart; m_pShareMemoryInfo = static_cast(m_commondM->data()); if (m_pShareMemoryInfo) { m_pShareMemoryInfo->isStart = iShareInfo.isStart; } else { - qWarning() << "conntrol mem is Not Attech "; + qCWarning(logSM) << "conntrol mem is Not Attech "; } m_commondM->unlock(); @@ -42,10 +50,10 @@ void SharedMemoryManager::releaseMemory() { if (m_commondM) { // m_commondM->unlock(); - qDebug() << "shared memory error:" << m_commondM->error() << m_commondM->errorString(); + qCDebug(logSM) << "shared memory error:" << m_commondM->error() << m_commondM->errorString(); if (m_commondM->isAttached()) //检测程序当前是否关联共享内存 m_commondM->detach(); - qDebug() << "shared memory error:" << m_commondM->error() << m_commondM->errorString(); + qCDebug(logSM) << "shared memory error:" << m_commondM->error() << m_commondM->errorString(); } } @@ -60,7 +68,7 @@ void SharedMemoryManager::init() if (m_commondM->isAttached()) //检测程序当前是否关联共享内存 m_commondM->detach(); if (!m_commondM->create(sizeof(ShareMemoryInfo))) { //创建共享内存,大小为size - qWarning() << "ShareMemory create error" << m_commondM->key() << QSharedMemory::SharedMemoryError(m_commondM->error()) << m_commondM->errorString(); + qCWarning(logSM) << "ShareMemory create error" << m_commondM->key() << QSharedMemory::SharedMemoryError(m_commondM->error()) << m_commondM->errorString(); if (m_commondM->isAttached()) //检测程序当前是否关联共享内存 m_commondM->detach(); m_commondM->attach(); diff --git a/application/utils.cpp b/application/utils.cpp index c9e38d25..5e13a58b 100644 --- a/application/utils.cpp +++ b/application/utils.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -24,9 +24,16 @@ #include #include #include +#include #include using namespace PolkitQt1; +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logUtils, "log.viewer.utils") +#else +Q_LOGGING_CATEGORY(logUtils, "log.viewer.utils", QtInfoMsg) +#endif + QHash Utils::m_imgCacheHash; QHash Utils::m_fontNameCache; QMap Utils::m_mapAuditType2EventType; @@ -362,7 +369,7 @@ QString Utils::getHomePath(const QString &userName) auto output = unlock->readAllStandardOutput(); auto str = QString::fromUtf8(output); str = str.mid(str.indexOf("::") + 2).split(":").first(); - qInfo() << "userName: " << uName << "homePath:" << str; + qCInfo(logUtils) << "userName: " << uName << "homePath:" << str; return str; } diff --git a/logViewerAuth/viewapplication.cpp b/logViewerAuth/viewapplication.cpp index f64c90bc..e7deba99 100644 --- a/logViewerAuth/viewapplication.cpp +++ b/logViewerAuth/viewapplication.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -14,17 +14,24 @@ #include #include #include +#include #include #include +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logViewApp, "log.viewer.view.application") +#else +Q_LOGGING_CATEGORY(logViewApp, "log.viewer.view.application", QtInfoMsg) +#endif + ViewApplication::ViewApplication(int &argc, char **argv): QCoreApplication(argc, argv),m_commondM(new QSharedMemory()) { QCommandLineParser parser; parser.process(*this); const QStringList fileList = parser.positionalArguments(); if (fileList.count() < 2) { - qCritical() << "cmd param count less than 2"; + qCCritical(logViewApp) << "cmd param count less than 2"; return ; } bool useFinishedSignal = false; diff --git a/logViewerService/logviewerservice.cpp b/logViewerService/logviewerservice.cpp index ffd3f697..460de03b 100644 --- a/logViewerService/logviewerservice.cpp +++ b/logViewerService/logviewerservice.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -13,8 +13,13 @@ #include #include #include +#include -//const QStringList ValidInvokerExePathList1 = QStandardPaths::locateAll(QStandardPaths::ApplicationsLocation, "deepin-log-viewer"); +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logService, "log.viewer.service") +#else +Q_LOGGING_CATEGORY(logService, "log.viewer.service", QtInfoMsg) +#endif LogViewerService::LogViewerService(QObject *parent) : QObject(parent) @@ -63,7 +68,7 @@ QString LogViewerService::readLog(const QString &filePath) //QByteArray -> QString 如果遇到0x00,会导致转换终止 //replace("\x00", "")和replace("\u0000", "")无效 //使用remove操作,性能损耗过大,因此遇到0x00 替换为 0x20(空格符) - qInfo() << "replace 0x00 to 0x20 begin"; + qCInfo(logService) << "replace 0x00 to 0x20 begin"; int replaceTimes = 0; for (int i = 0; i != byte.size(); ++i) { if (byte.at(i) == 0x00) { @@ -71,7 +76,7 @@ QString LogViewerService::readLog(const QString &filePath) replaceTimes++; } } - qInfo() << "replace 0x00 to 0x20 end. replaceTimes:" << replaceTimes; + qCInfo(logService) << "replace 0x00 to 0x20 end. replaceTimes:" << replaceTimes; return QString::fromUtf8(byte); } @@ -162,7 +167,7 @@ int LogViewerService::exitCode() */ void LogViewerService::quit() { - qDebug() << "LogViewService::Quit called"; + qCDebug(logService) << "LogViewService::Quit called"; QCoreApplication::exit(0); } @@ -235,7 +240,7 @@ QStringList LogViewerService::getFileInfo(const QString &file, bool unzip) } //要判断路径是否存在 if (!dir.exists()) { - qWarning() << "it is not true path"; + qCWarning(logService) << "it is not true path"; return QStringList() << ""; } dir.setFilter(QDir::Files | QDir::NoSymLinks); //实现对文件的过滤 @@ -281,7 +286,7 @@ QStringList LogViewerService::getOtherFileInfo(const QString &file, bool unzip) QFileInfoList fileList; //判断路径是否存在 if (!appFileInfo.exists()) { - qWarning() << QString("path:[%1] it is not true path").arg(file); + qCWarning(logService) << QString("path:[%1] it is not true path").arg(file); return QStringList(); } //如果是文件 @@ -347,7 +352,7 @@ bool LogViewerService::exportLog(const QString &outDir, const QString &in, bool } QFileInfo filein(in); if (!filein.isFile()) { - qWarning() << "in not file:" << in; + qCWarning(logService) << "in not file:" << in; return false; } outFullPath = outDirInfo.absoluteFilePath() + filein.fileName(); @@ -356,7 +361,7 @@ bool LogViewerService::exportLog(const QString &outDir, const QString &in, bool } else { auto it = m_commands.find(in); if (it == m_commands.end()) { - qWarning() << "unknown command:" << in; + qCWarning(logService) << "unknown command:" << in; return false; } @@ -367,7 +372,7 @@ bool LogViewerService::exportLog(const QString &outDir, const QString &in, bool outFullPath = outDirInfo.absoluteFilePath() + appName + ".log"; cmd += QString(" SYSLOG_IDENTIFIER=%1").arg(appName); - qDebug() << "journalctl app export cmd:" << cmd; + qCDebug(logService) << "journalctl app export cmd:" << cmd; } //结果重定向到文件 @@ -378,7 +383,7 @@ bool LogViewerService::exportLog(const QString &outDir, const QString &in, bool QProcess process; process.start("/bin/bash", arg); if (!process.waitForFinished()) { - qWarning() << "command error:" << arg; + qCWarning(logService) << "command error:" << arg; return false; } return true; diff --git a/logViewerService/main.cpp b/logViewerService/main.cpp index 1c02bbdc..63ecf1ac 100644 --- a/logViewerService/main.cpp +++ b/logViewerService/main.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -11,6 +11,9 @@ #include #include #include +#include + +Q_DECLARE_LOGGING_CATEGORY(logService) //service name const QString LogViewrServiceName = "com.deepin.logviewer"; @@ -29,7 +32,7 @@ int main(int argc, char *argv[]) PATH += ":/sbin"; qputenv("PATH", PATH.toLatin1()); - qDebug() << "log-viewer-service start, PATH" << PATH; + qCDebug(logService) << "log-viewer-service start, PATH" << PATH; QCoreApplication a(argc, argv); a.setOrganizationName("deepin"); @@ -56,7 +59,7 @@ int main(int argc, char *argv[]) #endif QDBusConnection systemBus = QDBusConnection::systemBus(); if (!systemBus.registerService(LogViewrServiceName)) { - qCritical() << "registerService failed:" << systemBus.lastError(); + qCCritical(logService) << "registerService failed:" << systemBus.lastError(); exit(0x0001); } LogViewerWatcher watcher; @@ -64,7 +67,7 @@ int main(int argc, char *argv[]) if (!systemBus.registerObject(LogViewrPath, &service, QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals)) { - qCritical() << "registerObject failed:" << systemBus.lastError(); + qCCritical(logService) << "registerObject failed:" << systemBus.lastError(); exit(0x0002); } return a.exec();