Repository navigation
feat:Add authentication log support - #417
Merged
Merged
Conversation
re2zero
force-pushed
the
auth
branch
2 times, most recently
from
November 5, 2025 08:03
fb6b3c5 to
fbda99f
Compare
Implement authentication log viewing functionality to parse and display logs from /var/log/auth.log and its rotated files. Includes UI integration, filtering, export capabilities, and full feature parity with existing audit log functionality. Log: Add authentication log support. story: https://pms.uniontech.com/story-view-39399.html
deepin pr auto review这是一个关于添加认证日志(Auth Log)功能的大型代码变更。让我从几个方面分析这段代码:
改进建议:
// 建议将正则表达式编译为类的成员变量,避免重复编译
class LogAuthThread {
private:
static const QRegularExpression authRe; // 在cpp文件中初始化
};
// 在parseListToModel中使用智能指针
for (int i = 0; i < listCount; i++) {
items.clear();
QScopedPointer<DStandardItem> item(new DStandardItem(iList[i].dateTime));
// ...
}
// 添加更详细的错误信息
if (!file.exists()) {
qCWarning(logApp) << "Auth log file does not exist:" << filePath
<< "Error:" << file.errorString();
emit errorOccurred(tr("Log file not found: %1").arg(filePath));
return;
}
// 使用QByteArray直接处理,避免不必要的字符串转换
QByteArray logData = file.readAll();
QTextStream stream(logData);
while (!stream.atEnd()) {
// 处理每一行
}
// 将通用的日志处理逻辑提取为模板函数
template<typename T>
void LogAuthThread::processLogFile(const QString& filePath,
std::function<T(const QString&)> parser) {
// 通用处理逻辑
}
// 添加日志文件完整性检查
bool verifyLogFile(const QString& filePath) {
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly)) {
return false;
}
// 检查文件大小
if (file.size() > MAX_LOG_SIZE) {
return false;
}
// 检查文件头
QByteArray header = file.read(HEADER_SIZE);
return isValidLogHeader(header);
}
// 将认证日志相关的类和方法组织到单独的头文件和源文件中
// authlog.h
class AuthLogParser {
public:
static QList<LOG_MSG_AUTH> parse(const QString& content);
static bool validate(const QString& line);
};
// authlog.cpp
QList<LOG_MSG_AUTH> AuthLogParser::parse(const QString& content) {
// 实现解析逻辑
}
// 确保所有用户可见的字符串都使用tr()函数
QString errorMsg = tr("Failed to read auth log: %1").arg(filePath);
// 添加单元测试
class TestAuthLog : public QObject {
Q_OBJECT
private slots:
void testParseAuthLog();
void testInvalidLogFormat();
void testLargeLogHandling();
};
/**
* @brief parseAuthLog 解析认证日志文件
* @param filePath 日志文件路径
* @return 解析后的日志条目列表
*
* 该函数支持以下格式的认证日志:
* - 标准syslog格式
* - 带时间戳的格式
* - 带进程ID的格式
*
* @note 该函数会自动处理日志轮转文件
* @warning 需要root权限才能访问某些认证日志文件
*/这些改进建议可以帮助提高代码的质量、性能和可维护性。建议在实施这些改进时保持与现有代码风格的一致性。 |
add DBus fallback for restricted file access in zip export. Log: Fix auth logs can not be exported if with all.
lzwind
approved these changes
Nov 5, 2025
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, re2zero The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
Author
|
/forcemerge |
Contributor
|
This pr force merged! (status: unstable) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement authentication log viewing functionality to parse and display logs from /var/log/auth.log and its rotated files. Includes UI integration, filtering, export capabilities, and full feature parity with existing audit log functionality.
Log: Add authentication log support.
story:https://pms.uniontech.com/story-view-39399.html