Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Debug mode log adaptation #324

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ find_package(Qt5Widgets REQUIRED)
find_package(Qt5LinguistTools REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5X11Extras REQUIRED)
#find_package(DtkWidget REQUIRED)
find_package(DtkWidget REQUIRED)
#find_package(DtkCore REQUIRED)
#find_package(DtkGui REQUIRED)

Expand Down Expand Up @@ -276,9 +276,6 @@ install(FILES src/deepin-terminal.desktop
install(FILES src/assets/logo/deepin-terminal.svg
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps/)

install(FILES src/assets/logconfig/deepin-terminal.json
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/deepin-log-viewer/deepin-log.conf.d/)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/deepin-terminal
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
PERMISSIONS OWNER_READ OWNER_EXECUTE
Expand All @@ -289,6 +286,25 @@ install(FILES ${DTNG_QM_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/deepin-

install(DIRECTORY src/assets/deepin-terminal
DESTINATION /usr/share/deepin-manual/manual-assets/application/)
message("CMAKE_INSTALL_PREFIX: " ${CMAKE_INSTALL_PREFIX})
#安装日志调试模式配置文件
install(FILES src/assets/config/debugconfig/org.deepin.terminal.json
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/deepin-debug-config/deepin-debug-config.d/)
#install(FILES src/assets/config/debugconfig/deepin-terminal_debug.sh
# DESTINATION ${CMAKE_INSTALL_PREFIX}/share/deepin-debug-config/shell/)
#安装DConfig配置
set(APPID org.deepin.terminal)
set(configFile ${PROJECT_SOURCE_DIR}/src/assets/config/dconfig/org.deepin.terminal.json)
if (DEFINED DSG_DATA_DIR)
message("-- DConfig is supported by DTK")
dconfig_meta_files(APPID ${APPID} FILES ${configFile})
else()
message("-- DConfig is not supported by DTK")
install(FILES ${configFile} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/dsg/config/org.deepin.terminal/)
endif()
#安装日志收集工具配置文件
install(FILES src/assets/config/logconfig/org.deepin.terminal.json
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/deepin-log-viewer/deepin-log.conf.d/)

# Unit Test
if (CMAKE_BUILD_TYPE MATCHES Debug)
Expand Down
19 changes: 19 additions & 0 deletions src/assets/config/dconfig/org.deepin.terminal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"magic": "dsg.config.meta",
"version": "1.0",
"contents": {
"log_rules": {
"value": "*terminal*.debug=false;*terminal*.info=false;*terminal*.warning=true",
"serial": 0,
"flags": [
"global"
],
"name": "log rules",
"name[zh_CN]": "日志规则",
"description": "log rules",
"description[zh_CN]": "日志规则",
"permissions": "readwrite",
"visibility": "public"
}
}
}
12 changes: 12 additions & 0 deletions src/assets/config/debugconfig/org.deepin.terminal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "deepin-terminal",
"group": "",
"submodules": [
{
"name": "deepin-terminal",
"exec": "/usr/share/deepin-debug-config/shell/deepin-terminal_debug.sh"
}
],
"reboot": 1,
"version": "V1.0"
}
57 changes: 57 additions & 0 deletions src/assets/config/logconfig/org.deepin.terminal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "deepin-terminal",
"group": "",
"submodules": [
{
"name": "main",
"filter": "org.deepin.terminal",
"exec": "/usr/bin/deepin-terminal",
"logType": "journal",
"logPath": "~/.cache/deepin/deepin-terminal/deepin-terminal.log"
},
{
"name": "common",
"filter": "org.deepin.terminal.common",
"exec": "/usr/bin/deepin-terminal",
"logType": "journal",
"logPath": "~/.cache/deepin/deepin-terminal/deepin-terminal.log"
},
{
"name": "customcom",
"filter": "org.deepin.terminal.customcommand",
"exec": "/usr/bin/deepin-terminal",
"logType": "journal",
"logPath": "~/.cache/deepin/deepin-terminal/deepin-terminal.log"
},
{
"name": "remotemanage",
"filter": "org.deepin.terminal.remotemanage",
"exec": "/usr/bin/deepin-terminal",
"logType": "journal",
"logPath": "~/.cache/deepin/deepin-terminal/deepin-terminal.log"
},
{
"name": "tsettings",
"filter": "org.deepin.terminal.tsettings",
"exec": "/usr/bin/deepin-terminal",
"logType": "journal",
"logPath": "~/.cache/deepin/deepin-terminal/deepin-terminal.log"
},
{
"name": "views",
"filter": "org.deepin.terminal.views",
"exec": "/usr/bin/deepin-terminal",
"logType": "journal",
"logPath": "~/.cache/deepin/deepin-terminal/deepin-terminal.log"
},
{
"name": "encodeplugin",
"filter": "org.deepin.terminal.encodeplugin",
"exec": "/usr/bin/deepin-terminal",
"logType": "journal",
"logPath": "~/.cache/deepin/deepin-terminal/deepin-terminal.log"
}
],
"visible": 1,
"version": "V1.0"
}
8 changes: 0 additions & 8 deletions src/assets/logconfig/deepin-terminal.json

This file was deleted.

95 changes: 75 additions & 20 deletions src/common/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ Utils::~Utils()
}

#ifdef QT_DEBUG
Q_LOGGING_CATEGORY(LogCommon,"log.terminal.common.work")
Q_LOGGING_CATEGORY(common,"org.deepin.terminal.common")
#else
Q_LOGGING_CATEGORY(LogCommon,"log.terminal.common.work",QtInfoMsg)
Q_LOGGING_CATEGORY(common,"org.deepin.terminal.common",QtInfoMsg)
#endif

QString Utils::getQssContent(const QString &filePath)
Expand Down Expand Up @@ -336,7 +336,7 @@ void Utils::parseCommandLine(QStringList arguments, TermProperties &Properties,
// 解析参数
Properties[KeepOpen] = false;
if (!parser.parse(arguments))
qCInfo(LogCommon) << "parser error:" << parser.errorText();
qCInfo(common) << "parser error:" << parser.errorText();

if (parser.isSet(optExecute)) {
/************************ Add by sunchengxi 2020-09-15:Bug#42864 无法同时打开多个终端 Begin************************/
Expand Down Expand Up @@ -377,11 +377,11 @@ void Utils::parseCommandLine(QStringList arguments, TermProperties &Properties,
// 处理相应参数,当遇到-v -h参数的时候,这里进程会退出。
parser.process(arguments);
} else {
qCInfo(LogCommon) << "Command line input args:" << qPrintable(arguments.join(" "));
qCInfo(LogCommon) << "The work directory :" << parser.value(optWorkDirectory);
qCInfo(LogCommon) << QString("Execute %1 command in the terminal").arg(Properties[Execute].toStringList().join(" "));
qCInfo(LogCommon) << "Run in quake mode :" << parser.isSet(optQuakeMode);
qCInfo(LogCommon) << "Set the window mode on starting :" << parser.isSet(optWindowState);
qCInfo(common) << "Command line input args:" << qPrintable(arguments.join(" "));
qCInfo(common) << "The work directory :" << parser.value(optWorkDirectory);
qCInfo(common) << QString("Execute %1 command in the terminal").arg(Properties[Execute].toStringList().join(" "));
qCInfo(common) << "Run in quake mode :" << parser.isSet(optQuakeMode);
qCInfo(common) << "Set the window mode on starting :" << parser.isSet(optWindowState);
// 这个位置参数解析出来是无法匹配的,可是不带前面标识符,无法准确使用。
}
return;
Expand Down Expand Up @@ -437,7 +437,7 @@ QStringList Utils::parseExecutePara(QStringList &arguments)
}
arguments.removeOne("-e");
arguments.removeOne("--execute");
qCInfo(LogCommon) << "Remove the arguments after '-e',the arguments :" << arguments;
qCInfo(common) << "Remove the arguments after '-e',the arguments :" << arguments;
}

return paraList;
Expand All @@ -461,7 +461,7 @@ QStringList Utils::parseNestedQString(QString str)
//对路径带空格的脚本,右键执行时不进行拆分处理, //./deepin-terminal "-e" "/home/lx777/Desktop/a b/PerfTools_1.9.sh"
QFileInfo fi(str);
if (fi.isFile()) {
qCWarning(LogCommon) << "this is file,not split.";
qCWarning(common) << "this is file,not split.";
paraList.append(str);
return paraList;
}
Expand Down Expand Up @@ -528,7 +528,7 @@ QList<QByteArray> Utils::encodeList()
}
}
if (!bFind)
qCWarning(LogCommon) << "encode (name :" << name << ") not find!";
qCWarning(common) << "encode (name :" << name << ") not find!";
else
encodeList << encodename;

Expand Down Expand Up @@ -599,12 +599,12 @@ bool Utils::isLoongarch()
if(m_Arch.isEmpty()) {
utsname utsbuf;
if (uname(&utsbuf) == -1) {
qCWarning(LogCommon) << "get Arch error";
qCWarning(common) << "get Arch error";
return false;
}
m_Arch = QString::fromLocal8Bit(utsbuf.machine);
}
qCInfo(LogCommon) << "Current system architecture:" << m_Arch;
qCInfo(common) << "Current system architecture:" << m_Arch;
return "mips64" == m_Arch || "loongarch64" == m_Arch;
}

Expand Down Expand Up @@ -633,7 +633,7 @@ void Utils::insertToDefaultConfigJson(QVariant &jsonVar, const QString &groups_k
obj = objArrayFind(obj, "groups", "key", groups_key2);
obj = objArrayFind(obj, "options", "key", options_key);
if(!obj) {
qCWarning(LogCommon) << QString("cannot find path %1/%2/%3").arg(groups_key).arg(groups_key2).arg(options_key);
qCWarning(common) << QString("cannot find path %1/%2/%3").arg(groups_key).arg(groups_key2).arg(options_key);
return;
}
obj->insert(key, value);
Expand All @@ -649,7 +649,7 @@ QVariant Utils::getValueInDefaultConfigJson(QVariant &jsonVar, const QString &gr
obj = objArrayFind(obj, "groups", "key", groups_key2);
obj = objArrayFind(obj, "options", "key", options_key);
if(!obj) {
qCWarning(LogCommon) << QString("cannot find path %1/%2/%3").arg(groups_key).arg(groups_key2).arg(options_key);
qCWarning(common) << QString("cannot find path %1/%2/%3").arg(groups_key).arg(groups_key2).arg(options_key);
return QVariant();
}
return obj->value(key);
Expand Down Expand Up @@ -678,9 +678,9 @@ MainWindow *Utils::getMainWindow(QWidget *currWidget)
MainWindow *main = nullptr;
QWidget *pWidget = currWidget->parentWidget();
while (pWidget != nullptr) {
qCInfo(LogCommon) << "Current Window Class Name :" << pWidget->metaObject()->className();
qCInfo(common) << "Current Window Class Name :" << pWidget->metaObject()->className();
if (("NormalWindow" == pWidget->objectName()) || ("QuakeWindow" == pWidget->objectName())) {
qCInfo(LogCommon) << "has find MainWindow";
qCInfo(common) << "has find MainWindow";
main = static_cast<MainWindow *>(pWidget);
break;
}
Expand Down Expand Up @@ -723,7 +723,7 @@ void FontFilter::handleWidthFont()
m_thread->start();
return;
}
//qCInfo(LogCommon) << "m_thread is Running";
//qCInfo(common) << "m_thread is Running";
}

void FontFilter::setStop(bool stop)
Expand Down Expand Up @@ -810,7 +810,62 @@ void FontFilter::compareWhiteList()
else
Blacklist.append(sfont);
}
qCInfo(LogCommon) << "Font whitelist obtained through the dbus interface :" << DBUSWhitelist;
qCInfo(LogCommon) << "Whitelist of real available fonts :" << Whitelist;
qCInfo(common) << "Font whitelist obtained through the dbus interface :" << DBUSWhitelist;
qCInfo(common) << "Whitelist of real available fonts :" << Whitelist;
}
/******** Add by ut001000 renfeixiang 2020-06-15:增加 处理等宽字体的类 End***************/

#ifdef DTKCORE_CLASS_DConfigFile
LoggerRules::LoggerRules(QObject *parent)
: QObject(parent), m_rules(""), m_config(nullptr) {
}

LoggerRules::~LoggerRules() { m_config->deleteLater(); }

void LoggerRules::initLoggerRules()
{
QByteArray logRules = qgetenv("QT_LOGGING_RULES");
qunsetenv("QT_LOGGING_RULES");

// set env
m_rules = logRules;
qCDebug(common) << "Current system env log rules:" << logRules;

// set dconfig
m_config = DConfig::create("org.deepin.terminal", "org.deepin.terminal");
qCDebug(common) << "Current DConfig file is :" << m_config->name();
logRules = m_config->value("log_rules").toByteArray();
qCDebug(common) << "Current app log rules :" << logRules;
appendRules(logRules);
setRules(m_rules);

// watch dconfig
connect(m_config, &DConfig::valueChanged, this, [this](const QString &key) {
if (key == "log_rules") {
qCDebug(common) << "value changed:" << key;
setRules(m_config->value(key).toByteArray());
}
});
}

void LoggerRules::setRules(const QString &rules) {
auto tmpRules = rules;
m_rules = tmpRules.replace(";", "\n");
QLoggingCategory::setFilterRules(m_rules);
}

void LoggerRules::appendRules(const QString &rules) {
QString tmpRules = rules;
tmpRules = tmpRules.replace(";", "\n");
auto tmplist = tmpRules.split('\n');
for (int i = 0; i < tmplist.count(); i++)
if (m_rules.contains(tmplist.at(i))) {
tmplist.removeAt(i);
i--;
}
if (tmplist.isEmpty())
return;
m_rules.isEmpty() ? m_rules = tmplist.join("\n")
: m_rules += "\n" + tmplist.join("\n");
}
#endif
23 changes: 23 additions & 0 deletions src/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

#include <DPushButton>
#include <DApplication>
#ifdef DTKCORE_CLASS_DConfig
#include <DConfig>
#endif

#include <QObject>
#include <QHash>
Expand Down Expand Up @@ -456,4 +459,24 @@ class FontFilter : public QObject
};
/******** Add by ut001000 renfeixiang 2020-06-15:增加 处理等宽字体的类 End***************/

#ifdef DTKCORE_CLASS_DConfigFile
class LoggerRules : public QObject {
Q_OBJECT
public:
explicit LoggerRules(QObject *parent = nullptr);
~LoggerRules();

void initLoggerRules();
inline QString rules() const { return m_rules; }
void setRules(const QString &rules);

private:
void appendRules(const QString &rules);

private:
QString m_rules;
Dtk::Core::DConfig *m_config;
};
#endif

#endif
Loading
Loading