Compare commits
16 Commits
master
...
release/5.
| Author | SHA1 | Date |
|---|---|---|
|
|
74be723b50 | |
|
|
fdeba32ff4 | |
|
|
50a4aaa1d4 | |
|
|
e06cb8dd59 | |
|
|
f5885f9af0 | |
|
|
a6e7b7d7a9 | |
|
|
62b99ef6b0 | |
|
|
58ed38a4ba | |
|
|
6a16ab47be | |
|
|
3999af8a96 | |
|
|
5ba84146b4 | |
|
|
bd4ad9ac09 | |
|
|
1d42ac67e1 | |
|
|
7455c270a6 | |
|
|
b1e3ac4c54 | |
|
|
56a616e9e1 |
|
|
@ -92,6 +92,8 @@ write_basic_package_version_file(
|
|||
VERSION ${DVERSION}
|
||||
COMPATIBILITY SameMajorVersion
|
||||
)
|
||||
install(FILES misc/org.deepin.dtk.loggingrules.json DESTINATION share/dsg/configs/)
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/DtkCoreConfig.cmake DESTINATION ${CONFIG_CMAKE_INSTALL_DIR})
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/DtkCoreConfigVersion.cmake DESTINATION ${CONFIG_CMAKE_INSTALL_DIR})
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,9 @@
|
|||
dtkcore (5.6.8.7) unstable; urgency=medium
|
||||
|
||||
* Release 5.6.8.7
|
||||
|
||||
-- Deepin Packages Builder <packages@deepin.com> Jan, 25 Feb 2024 16:08:07 +0800
|
||||
|
||||
dtkcore (5.6.8) unstable; urgency=medium
|
||||
|
||||
* Release 5.6.8
|
||||
|
|
@ -72,6 +78,6 @@ dtkcore (2.0.8) unstable; urgency=medium
|
|||
|
||||
dtkcore (0.3.3-1) unstable; urgency=medium
|
||||
|
||||
* Initial release
|
||||
* Initial release
|
||||
|
||||
-- Deepin Packages Builder <packages@deepin.com> Mon, 10 Oct 2016 16:58:07 +0800
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
usr/lib/*/lib*.so.*
|
||||
usr/share/dsg/configs/org.deepin.dtk.loggingrules.json
|
||||
|
|
|
|||
|
|
@ -8,9 +8,15 @@ DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
|
|||
|
||||
VERSION = $(DEB_VERSION_UPSTREAM)
|
||||
PACK_VER = $(shell echo $(VERSION) | awk -F'[+_~-]' '{print $$1}')
|
||||
# Fix: invalid digit "8" in octal constant. e.g. u008 ==> 008 ==> 8
|
||||
BUILD_VER = $(shell echo $(VERSION) | awk -F'[+_~-]' '{print $$2}' | sed 's/[^0-9]//g' | awk '{print int($$1)}')
|
||||
|
||||
# Calculate build version:
|
||||
# 5.6.8 -> 0; 5.6.8.7 -> 7; 5.6.8+u001 -> 1; 5.6.8.7+u001 -> 7; 5.6.8.0+u001 -> 0
|
||||
BUILD_VER = $(shell echo $(VERSION) | awk -F'[+_~-]' '{print $$1}' | awk -F'.' '{print $$4}' | sed 's/[^0-9]//g' | awk '{print int($$1)}')
|
||||
ifeq ($(BUILD_VER), 0)
|
||||
ifeq ($(shell expr $(shell echo "$(VERSION)" | awk -F. '{print NF-1}') '<' 3), 1)
|
||||
BUILD_VER=$(shell echo $(VERSION) | awk -F'[+_~-]' '{print $$2}' | sed 's/[^0-9]//g' | awk '{print int($$1)}')
|
||||
endif
|
||||
endif
|
||||
|
||||
%:
|
||||
dh $@
|
||||
|
|
|
|||
|
|
@ -34,7 +34,9 @@ public:
|
|||
|
||||
enum Permissions {
|
||||
ReadOnly,
|
||||
ReadWrite
|
||||
ReadWrite,
|
||||
AuthorizedReadOnly,
|
||||
AuthorizedReadWrite,
|
||||
};
|
||||
|
||||
enum Visibility {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ public:
|
|||
DeepinDesktop,
|
||||
DeepinProfessional,
|
||||
DeepinServer,
|
||||
DeepinPersonal
|
||||
DeepinPersonal,
|
||||
DeepinMilitary
|
||||
};
|
||||
|
||||
enum LogoType {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ class ConsoleAppender;
|
|||
class RollingFileAppender;
|
||||
class JournalAppender;
|
||||
|
||||
class DConfig;
|
||||
|
||||
class LIBDTKCORESHARED_EXPORT DLogManager
|
||||
{
|
||||
public:
|
||||
|
|
@ -33,6 +35,13 @@ public:
|
|||
|
||||
static void setLogFormat(const QString &format);
|
||||
|
||||
/*!
|
||||
* \brief 监听 org.deepin.dtk.log 的变化动态调整应用的日志输出规则
|
||||
* 此方法应该在创建 QApplication 之前调用,否则 QT_LOGGING_RULES 环境变量会覆盖 dconfig 的的值
|
||||
* \a logFilePath 指定 dconfig 的 appId
|
||||
*/
|
||||
static void registerLoggingRulesWatcher(const QString &appId);
|
||||
|
||||
private:
|
||||
//TODO: move it to private class (DTK6)
|
||||
QString m_format;
|
||||
|
|
@ -40,10 +49,12 @@ private:
|
|||
ConsoleAppender* m_consoleAppender;
|
||||
RollingFileAppender* m_rollingFileAppender;
|
||||
JournalAppender* m_journalAppender;
|
||||
DConfig* m_loggingRulesConfig;
|
||||
|
||||
void initConsoleAppender();
|
||||
void initRollingFileAppender();
|
||||
void initJournalAppender();
|
||||
void initLoggingRules(const QString &appId);
|
||||
QString joinPath(const QString &path, const QString &fileName);
|
||||
|
||||
inline static DLogManager* instance(){
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public:
|
|||
void registerAppender(AbstractAppender *appender);
|
||||
void registerCategoryAppender(const QString &category, AbstractAppender *appender);
|
||||
|
||||
void logToGlobalInstance(const QString &category, bool logToGlobal = false);
|
||||
QT_DEPRECATED_X("no longer take effect") void logToGlobalInstance(const QString &category, bool logToGlobal = false);
|
||||
|
||||
void setDefaultCategory(const QString &category);
|
||||
QString defaultCategory() const;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"magic": "dsg.config.meta",
|
||||
"version": "1.0",
|
||||
"contents": {
|
||||
"rules": {
|
||||
"value": "",
|
||||
"serial": 0,
|
||||
"flags": ["global"],
|
||||
"name": "The logging rules of dtk applications",
|
||||
"name[zh_CN]": "日志输出的规则配置",
|
||||
"description": "Configure the category and level of log output",
|
||||
"description[zh_CN]": "配置日志输出的类别和等级",
|
||||
"permissions": "readwrite",
|
||||
"visibility": "public"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -287,8 +287,13 @@ public:
|
|||
{
|
||||
DConfigFile::Permissions p = DConfigFile::ReadOnly;
|
||||
const auto &tmp = values[key][QLatin1String("permissions")].toString();
|
||||
if (tmp == QLatin1String("readwrite"))
|
||||
if (tmp == QLatin1String("readwrite")) {
|
||||
p = DConfigFile::ReadWrite;
|
||||
} else if (tmp == QLatin1String("authorizedreadonly")) {
|
||||
p = DConfigFile::AuthorizedReadOnly;
|
||||
} else if (tmp == QLatin1String("authorizedreadwrite")) {
|
||||
p = DConfigFile::AuthorizedReadWrite;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
|
@ -984,7 +989,7 @@ public:
|
|||
// If target user is current user, then get the home path by environment variable first.
|
||||
const QString &homePath = (getuid() == userid) ? DStandardPaths::homePath()
|
||||
: DStandardPaths::homePath(userid);
|
||||
if (homePath.isEmpty()) {
|
||||
if (homePath.isEmpty() || !QDir().exists(homePath)) {
|
||||
return QString();
|
||||
}
|
||||
const QString userHomeConfigDir = homePath + QStringLiteral("/.config/dsg/configs") + suffix;
|
||||
|
|
@ -1127,7 +1132,7 @@ bool DConfigCacheImpl::save(const QString &localPrefix, QJsonDocument::JsonForma
|
|||
cacheChanged = false;
|
||||
const QString &dir = getCacheDir(localPrefix);
|
||||
if (dir.isEmpty()) {
|
||||
qCWarning(cfLog, "Falied on saveing, the config cache directory is empty for the user[%d], "
|
||||
qCWarning(cfLog, "Failed on saving, the config cache directory is empty for the user[%d], "
|
||||
"the current user[%d].", userid, getuid());
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1139,7 +1144,7 @@ bool DConfigCacheImpl::save(const QString &localPrefix, QJsonDocument::JsonForma
|
|||
}
|
||||
|
||||
if (!cache.open(QIODevice::WriteOnly)) {
|
||||
qCWarning(cfLog, "Falied on saveing data when open file: \"%s\", error message: \"%s\"",
|
||||
qCWarning(cfLog, "Failed on saving data when open file: \"%s\", error message: \"%s\"",
|
||||
qPrintable(cache.fileName()), qPrintable(cache.errorString()));
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include <QByteArray>
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
|
||||
DCORE_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -16,12 +18,23 @@ static inline QByteArray getSelfAppId() {
|
|||
return selfId;
|
||||
selfId = DSGApplication::getId(QCoreApplication::applicationPid());
|
||||
if (selfId.isEmpty() && !qEnvironmentVariableIsSet("DTK_DISABLED_FALLBACK_APPID")) {
|
||||
selfId = QCoreApplication::applicationName().toLocal8Bit();
|
||||
auto appName = QCoreApplication::applicationName().toLocal8Bit();
|
||||
if (!appName.isEmpty()) {
|
||||
selfId = appName;
|
||||
} else {
|
||||
#ifdef Q_OS_LINUX
|
||||
if (QFile::exists("/proc/self/exe")) {
|
||||
auto id = QFileInfo("/proc/self/exe").symLinkTarget().replace("/", ".");
|
||||
selfId = id.size() > 0 ? id.remove(0, 1).toLocal8Bit() : id.toLocal8Bit();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Q_ASSERT(!selfId.isEmpty());
|
||||
if (selfId.isEmpty()) {
|
||||
qt_assert("The application ID is empty", __FILE__, __LINE__);
|
||||
qWarning() << "The application ID is empty. " << __FILE__ << __LINE__;
|
||||
}
|
||||
|
||||
Q_ASSERT(!selfId.isEmpty());
|
||||
return selfId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
#include <QStandardPaths>
|
||||
#include <QDateTime>
|
||||
#include <QRegularExpression>
|
||||
#include <QLoggingCategory>
|
||||
#include <qmath.h>
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
|
|
@ -33,6 +34,12 @@
|
|||
|
||||
DCORE_BEGIN_NAMESPACE
|
||||
|
||||
#ifdef QT_DEBUG
|
||||
Q_LOGGING_CATEGORY(logSysInfo, "dtk.dsysinfo")
|
||||
#else
|
||||
Q_LOGGING_CATEGORY(logSysInfo, "dtk.dsysinfo", QtInfoMsg)
|
||||
#endif
|
||||
|
||||
class Q_DECL_HIDDEN DSysInfoPrivate
|
||||
{
|
||||
public:
|
||||
|
|
@ -146,7 +153,7 @@ bool DSysInfoPrivate::splitA_BC_DMode()
|
|||
|
||||
void DSysInfoPrivate::ensureDeepinInfo()
|
||||
{
|
||||
if (static_cast<int>(deepinType) >= 0)
|
||||
if (static_cast<int>(deepinType) > 0)
|
||||
return;
|
||||
|
||||
QFile file("/etc/deepin-version");
|
||||
|
|
@ -212,6 +219,8 @@ void DSysInfoPrivate::ensureDeepinInfo()
|
|||
deepinType = DSysInfo::DeepinServer;
|
||||
} else if (deepin_type == "Personal") {
|
||||
deepinType = DSysInfo::DeepinPersonal;
|
||||
} else if (deepin_type == "Military") {
|
||||
deepinType = DSysInfo::DeepinMilitary;
|
||||
} else {
|
||||
deepinType = DSysInfo::UnknownDeepin;
|
||||
}
|
||||
|
|
@ -410,7 +419,7 @@ static bool readLsbRelease(DSysInfoPrivate *info)
|
|||
|
||||
void DSysInfoPrivate::ensureReleaseInfo()
|
||||
{
|
||||
if (productType >= 0) {
|
||||
if (productType > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1087,18 +1096,35 @@ qint64 DSysInfo::memoryInstalledSize()
|
|||
}
|
||||
|
||||
const QByteArray &lshwInfoJson = lshw.readAllStandardOutput();
|
||||
QJsonArray lshwResultArray = QJsonDocument::fromJson(lshwInfoJson).array();
|
||||
if (!lshwResultArray.isEmpty()) {
|
||||
QJsonValue memoryHwInfo = lshwResultArray.first();
|
||||
QString id = memoryHwInfo.toObject().value("id").toString();
|
||||
Q_ASSERT(id == "memory");
|
||||
siGlobal->memoryInstalledSize = memoryHwInfo.toObject().value("size").toDouble(); // TODO: check "units" is "bytes" ?
|
||||
|
||||
QJsonParseError error;
|
||||
auto doc = QJsonDocument::fromJson(lshwInfoJson, &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(logSysInfo(), "parse failed, expect json doc from lshw command");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!doc.isArray()) {
|
||||
qCWarning(logSysInfo(), "parse failed, expect array");
|
||||
return -1;
|
||||
}
|
||||
|
||||
QJsonArray lshwResultArray = doc.array();
|
||||
for (const QJsonValue value : lshwResultArray) {
|
||||
QJsonObject obj = value.toObject();
|
||||
if (obj.contains("id") && obj.value("id").toString() == "memory") {
|
||||
siGlobal->memoryInstalledSize = obj.value("size").toDouble(); // TODO: check "units" is "bytes" ?
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Q_ASSERT(siGlobal->memoryInstalledSize > 0);
|
||||
|
||||
return siGlobal->memoryInstalledSize;
|
||||
#endif
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -311,6 +311,11 @@ QString AbstractStringAppender::formattedString(const QDateTime &time, Logger::L
|
|||
const QString &category, const QString &msg) const
|
||||
{
|
||||
QString f = format();
|
||||
|
||||
// dtkcore无法正确解析Qt的日志格式,dtk默认的日志格式并未和Qt统一,解析方式需要兼容两种不同的格式。
|
||||
if (f.contains(QLatin1String("time ")))
|
||||
f.replace(f.indexOf(' ', f.indexOf(QLatin1String("time")) + QLatin1String("time").size()), 1, QLatin1String("}{"));
|
||||
|
||||
const int size = f.size();
|
||||
|
||||
QString result;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ DCORE_BEGIN_NAMESPACE
|
|||
|
||||
ConsoleAppender::ConsoleAppender()
|
||||
: AbstractStringAppender()
|
||||
,m_ignoreEnvPattern(false)
|
||||
, m_ignoreEnvPattern(false)
|
||||
{
|
||||
setFormat("[%{type:-7}] <%{function}> %{message}\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
#include "LogManager.h"
|
||||
#include "dconfig.h"
|
||||
|
||||
#include <Logger.h>
|
||||
#include <ConsoleAppender.h>
|
||||
#include <RollingFileAppender.h>
|
||||
|
|
@ -10,6 +12,8 @@
|
|||
|
||||
DCORE_BEGIN_NAMESPACE
|
||||
|
||||
#define RULES_KEY ("rules")
|
||||
|
||||
/*!
|
||||
@~english
|
||||
\class Dtk::Core::DLogManager
|
||||
|
|
@ -19,10 +23,12 @@ DCORE_BEGIN_NAMESPACE
|
|||
*/
|
||||
|
||||
DLogManager::DLogManager()
|
||||
: m_loggingRulesConfig(nullptr)
|
||||
{
|
||||
m_format = "%{time}{yyyy-MM-dd, HH:mm:ss.zzz} [%{type:-7}] [%{file:-20} %{function:-35} %{line}] %{message}\n";
|
||||
}
|
||||
|
||||
|
||||
void DLogManager::initConsoleAppender(){
|
||||
m_consoleAppender = new ConsoleAppender;
|
||||
m_consoleAppender->setFormat(m_format);
|
||||
|
|
@ -72,6 +78,55 @@ void DLogManager::registerJournalAppender()
|
|||
DLogManager::instance()->initJournalAppender();
|
||||
}
|
||||
|
||||
void DLogManager::initLoggingRules(const QString &appId)
|
||||
{
|
||||
if (appId.isEmpty()) {
|
||||
qWarning() << "App id is empty, logging rules won't take effect";
|
||||
return;
|
||||
}
|
||||
|
||||
// QT_LOGGING_RULES环境变量设置日志的优先级最高
|
||||
// QLoggingRegistry 初始化时会获取 QT_LOGGING_RULES 的值并保存,后续重置了环境变量 QLoggingRegistry 不会进行同步
|
||||
// 需要在 QLoggingRegistry 初始化之前重置 QT_LOGGING_RULES 的值
|
||||
QByteArray logRules = qgetenv("QT_LOGGING_RULES");
|
||||
qunsetenv("QT_LOGGING_RULES");
|
||||
|
||||
if (!logRules.isEmpty()) {
|
||||
QLoggingCategory::setFilterRules(logRules.replace(";", "\n"));
|
||||
}
|
||||
|
||||
m_loggingRulesConfig = DConfig::create(appId, "org.deepin.dtk.loggingrules");
|
||||
if (!m_loggingRulesConfig) {
|
||||
qWarning() << "Create logging rules dconfig object failed, logging rules won't take effect";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_loggingRulesConfig->isValid()) {
|
||||
qWarning() << "Logging rules config is invalid, please check `appId` arg is correct";
|
||||
delete m_loggingRulesConfig;
|
||||
m_loggingRulesConfig = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
auto updateLoggingRules = [this](const QString & key) {
|
||||
if (key != RULES_KEY)
|
||||
return;
|
||||
|
||||
const QVariant &var = m_loggingRulesConfig->value(RULES_KEY);
|
||||
if (var.isValid() && !var.toString().isEmpty()) {
|
||||
QLoggingCategory::setFilterRules(var.toString().replace(";", "\n"));
|
||||
}
|
||||
};
|
||||
|
||||
updateLoggingRules(RULES_KEY);
|
||||
QObject::connect(m_loggingRulesConfig, &DConfig::valueChanged, m_loggingRulesConfig, updateLoggingRules);
|
||||
}
|
||||
|
||||
void DLogManager::registerLoggingRulesWatcher(const QString &appId)
|
||||
{
|
||||
DLogManager::instance()->initLoggingRules(appId);
|
||||
}
|
||||
|
||||
/*!
|
||||
@~english
|
||||
\brief Return the path file log storage.
|
||||
|
|
@ -131,7 +186,10 @@ QString DLogManager::joinPath(const QString &path, const QString &fileName){
|
|||
|
||||
DLogManager::~DLogManager()
|
||||
{
|
||||
|
||||
if (m_loggingRulesConfig) {
|
||||
delete m_loggingRulesConfig;
|
||||
m_loggingRulesConfig = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
DCORE_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -508,7 +508,6 @@ public:
|
|||
QList<AbstractAppender*> appenders;
|
||||
mutable QMutex loggerMutex;
|
||||
|
||||
QMap<QString, bool> categories;
|
||||
QMultiMap<QString, AbstractAppender*> categoryAppenders;
|
||||
QString defaultCategory;
|
||||
|
||||
|
|
@ -822,13 +821,8 @@ void Logger::registerCategoryAppender(const QString &category, AbstractAppender
|
|||
*/
|
||||
void Logger::logToGlobalInstance(const QString &category, bool logToGlobal)
|
||||
{
|
||||
Q_D(Logger);
|
||||
if (this == globalInstance()) {
|
||||
QMutexLocker locker(&d->loggerMutex);
|
||||
d->categories.insert(category, logToGlobal);
|
||||
} else {
|
||||
globalInstance()->logToGlobalInstance(category, logToGlobal);
|
||||
}
|
||||
Q_UNUSED(category)
|
||||
Q_UNUSED(logToGlobal)
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -985,24 +979,18 @@ void Logger::write(const QDateTime &time, Logger::LogLevel level, const char *fi
|
|||
|
||||
bool wasWritten = false;
|
||||
bool isGlobalInstance = this == globalInstance();
|
||||
bool linkedToGlobal = isGlobalInstance && d->categories.value(logCategory, false);
|
||||
|
||||
if (!logCategory.isNull()) {
|
||||
QList<AbstractAppender*> appenders = d->categoryAppenders.values(logCategory);
|
||||
if (appenders.length() == 0) {
|
||||
if (logCategory != d->defaultCategory && !linkedToGlobal && !fromLocalInstance)
|
||||
std::cerr << "No appenders assotiated with category " << qPrintable(logCategory) << std::endl;
|
||||
} else {
|
||||
for (AbstractAppender* appender : appenders)
|
||||
appender->write(time, level, file, line, func, logCategory, msg);
|
||||
|
||||
for (AbstractAppender* appender : appenders)
|
||||
appender->write(time, level, file, line, func, logCategory, msg);
|
||||
if (!appenders.isEmpty())
|
||||
wasWritten = true;
|
||||
}
|
||||
}
|
||||
|
||||
// the default category is linked to the main logger appenders
|
||||
// global logger instance also writes all linked categories to the main appenders
|
||||
if (logCategory.isNull() || logCategory == d->defaultCategory || linkedToGlobal) {
|
||||
// if we can't find the corresponding category, log will be appended to all Appenders.
|
||||
if (!wasWritten) {
|
||||
if (!d->appenders.isEmpty()) {
|
||||
for (AbstractAppender* appender : d->appenders)
|
||||
appender->write(time, level, file, line, func, logCategory, msg);
|
||||
|
|
|
|||
Loading…
Reference in New Issue