mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-22 10:06:44 +00:00
feat(GODT-2446): Attach logs to sentry reports for relevant bridge-gui exceptions.
Cherry picked from release/perth_narrows (2aa4e7c)
# Conflicts:
# internal/frontend/bridge-gui/bridge-gui/AppController.cpp
# internal/frontend/bridge-gui/bridge-gui/AppController.h
# internal/frontend/bridge-gui/bridge-gui/LogUtils.cpp
# internal/frontend/bridge-gui/bridge-gui/LogUtils.h
# internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp
# internal/frontend/bridge-gui/bridge-gui/SentryUtils.cpp
# internal/frontend/bridge-gui/bridge-gui/SentryUtils.h
# internal/frontend/bridge-gui/bridge-gui/main.cpp
This commit is contained in:
@ -24,6 +24,11 @@
|
||||
using namespace bridgepp;
|
||||
|
||||
|
||||
namespace {
|
||||
qsizetype const logFileTailMaxLength = 25 * 1024; ///< The maximum length of the portion of log returned by tailOfLatestBridgeLog()
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return user logs directory used by bridge.
|
||||
//****************************************************************************************************************************************************
|
||||
@ -64,3 +69,36 @@ Log &initLog() {
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \brief Return the path of the latest bridge log.
|
||||
/// \return The path of the latest bridge log file.
|
||||
/// \return An empty string if no bridge log file was found.
|
||||
//****************************************************************************************************************************************************
|
||||
QString latestBridgeLogPath() {
|
||||
QDir const logsDir(userLogsDir());
|
||||
if (logsDir.isEmpty()) {
|
||||
return QString();
|
||||
}
|
||||
QFileInfoList files = logsDir.entryInfoList({ "v*.log" }, QDir::Files); // could do sorting, but only by last modification time. we want to sort by creation time.
|
||||
std::sort(files.begin(), files.end(), [](QFileInfo const &lhs, QFileInfo const &rhs) -> bool {
|
||||
return lhs.birthTime() < rhs.birthTime();
|
||||
});
|
||||
return files.back().absoluteFilePath();
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// Return the maxSize last bytes of the latest bridge log.
|
||||
//****************************************************************************************************************************************************
|
||||
QByteArray tailOfLatestBridgeLog() {
|
||||
QString path = latestBridgeLogPath();
|
||||
if (path.isEmpty()) {
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
QFile file(path);
|
||||
return file.open(QIODevice::Text | QIODevice::ReadOnly) ? file.readAll().right(logFileTailMaxLength) : QByteArray();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user