Skip to content
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
13 changes: 13 additions & 0 deletions src/assets/org.deepin.camera.encode.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
"magic": "dsg.config.meta",
"version": "1.0",
"contents": {
"rules": {
"value": "*.debug=false;*.info=false;*.warning=true",
"serial": 0,
"flags": [
"global"
],
"name": "rules",
"name[zh_CN]": "日志规则",
"description": "log rules",
"description[zh_CN]": "日志规则",
"permissions": "readwrite",
"visibility": "public"
},
"mp4EncodeMode": {
"value": -1,
"serial": 0,
Expand Down
11 changes: 9 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// Copyright (C) 2020 - 2026 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -29,14 +29,18 @@
#include <DWidgetUtil>
#include <DLog>
#if QT_VERSION_MAJOR <= 5
#include <DApplicationSettings>

Check warning on line 32 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DApplicationSettings> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 32 in src/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <DApplicationSettings> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#endif

#include "ddlog.h"

Check warning on line 35 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "ddlog.h" not found.

Check warning on line 35 in src/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "ddlog.h" not found.
#include "logconfigread.h"

Check warning on line 36 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "logconfigread.h" not found.

Check warning on line 36 in src/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "logconfigread.h" not found.

#include <QSharedMemory>

Check warning on line 38 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QSharedMemory> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 38 in src/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QSharedMemory> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTime>

Check warning on line 39 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTime> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 39 in src/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QTime> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QLoggingCategory>

Check warning on line 40 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLoggingCategory> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 40 in src/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QLoggingCategory> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <unistd.h>

Check warning on line 42 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <unistd.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 42 in src/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <unistd.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <fcntl.h>

Check warning on line 43 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <fcntl.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 43 in src/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <fcntl.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <stdio.h>
#include <csignal>

Expand Down Expand Up @@ -135,6 +139,9 @@

int main(int argc, char *argv[])
{
// 初始化日志规则:读取环境变量和 DConfig 配置
MLogger logger;

qInfo() << "Starting deepin-camera application...";
// Task 326583 不参与合成器崩溃重连
unsetenv("QT_WAYLAND_RECONNECT");
Expand Down
17 changes: 17 additions & 0 deletions src/src/ddlog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef DDLOG_H
#define DDLOG_H

#include <DLog>

Check warning on line 8 in src/src/ddlog.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DLog> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 8 in src/src/ddlog.h

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <DLog> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dtkcore_global.h>

Check warning on line 9 in src/src/ddlog.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dtkcore_global.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 9 in src/src/ddlog.h

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dtkcore_global.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DCORE_USE_NAMESPACE

namespace DDLog {
inline Q_LOGGING_CATEGORY(appLog, "org.deepin.camera")
}

#endif // DDLOG_H
65 changes: 65 additions & 0 deletions src/src/logconfigread.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "logconfigread.h"
#include "ddlog.h"
#include "dtkcore_global.h"
#include "qglobal.h"
#include <QLoggingCategory>
#include <QObject>
#include <DConfig>

DCORE_USE_NAMESPACE
using namespace DDLog;

MLogger::MLogger(QObject *parent)
: QObject(parent), m_rules(""), m_config(nullptr) {
QByteArray logRules = qgetenv("QT_LOGGING_RULES");
// qunsetenv 之前一定不要有任何日志打印,否则取消环境变量设置不会生效
qunsetenv("QT_LOGGING_RULES");
// 保存环境变量中的规则
m_rules = logRules;
// 从 DConfig 读取日志规则
m_config = DConfig::create("org.deepin.camera", "org.deepin.camera.encode");
if (m_config && m_config->isValid()) {
logRules = m_config->value("rules").toByteArray();
appendRules(logRules);
setRules(m_rules);
// 监听 DConfig 变化,动态更新日志规则
connect(m_config, &DConfig::valueChanged, this, [this](const QString &key) {
if (key == "rules") {
setRules(m_config->value(key).toByteArray());
}
});
}
}

MLogger::~MLogger() {
if (m_config) {
m_config->deleteLater();
}
}

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

void MLogger::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");
}
32 changes: 32 additions & 0 deletions src/src/logconfigread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef LOGCONFIGREAD_H
#define LOGCONFIGREAD_H

#include <QObject>
#include <dtkcore_global.h>

DCORE_BEGIN_NAMESPACE
class DConfig;
DCORE_END_NAMESPACE

class MLogger : public QObject {
Q_OBJECT
public:
explicit MLogger(QObject *parent = nullptr);
~MLogger();

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 // LOGCONFIGREAD_H
Loading