Share file line logic between logger and message box (#7441)
* Share file line logic between logger and message box * Update ChangeLog
This commit is contained in:
parent
7bb1bb2611
commit
28cefff13b
5 changed files with 18 additions and 21 deletions
|
|
@ -82,6 +82,7 @@ Enhancements:
|
|||
- #7437 Show message box explaining why settings are read-only
|
||||
- #7438 Compare result of `clickedButton` instead of `exec`
|
||||
- #7440 Fixed light logo filename on about screen
|
||||
- #7441 Share file line logic between logger and message box
|
||||
|
||||
# 1.14.6
|
||||
|
||||
|
|
|
|||
|
|
@ -40,13 +40,6 @@ const auto kForceDebugMessages = QStringList{
|
|||
|
||||
Logger Logger::s_instance;
|
||||
|
||||
QString fileLine(const QMessageLogContext &context) {
|
||||
if (!context.file) {
|
||||
return "";
|
||||
}
|
||||
return QString("%1:%2").arg(context.file).arg(context.line);
|
||||
}
|
||||
|
||||
QString printLine(
|
||||
FILE *out, const QString &type, const QString &message,
|
||||
const QString &fileLine = "") {
|
||||
|
|
@ -97,8 +90,7 @@ void Logger::logVerbose(const QString &message) const {
|
|||
}
|
||||
|
||||
void Logger::handleMessage(
|
||||
const QtMsgType type, const QMessageLogContext &context,
|
||||
const QString &message) {
|
||||
const QtMsgType type, const QString &fileLine, const QString &message) {
|
||||
|
||||
auto mutatedType = type;
|
||||
if (kForceDebugMessages.contains(message)) {
|
||||
|
|
@ -131,7 +123,7 @@ void Logger::handleMessage(
|
|||
break;
|
||||
}
|
||||
|
||||
const auto logLine = printLine(out, typeString, message, fileLine(context));
|
||||
const auto logLine = printLine(out, typeString, message, fileLine);
|
||||
emit newLine(logLine);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,8 +35,7 @@ public:
|
|||
|
||||
void loadEnvVars();
|
||||
void handleMessage(
|
||||
const QtMsgType type, const QMessageLogContext &context,
|
||||
const QString &message);
|
||||
const QtMsgType type, const QString &fileLine, const QString &message);
|
||||
void logVerbose(const QString &message) const;
|
||||
|
||||
signals:
|
||||
|
|
|
|||
|
|
@ -50,9 +50,7 @@ void raiseCriticalDialog() {
|
|||
}
|
||||
|
||||
void showErrorDialog(
|
||||
const QString &message, const QMessageLogContext &context, QtMsgType type) {
|
||||
auto filename = QFileInfo(context.file).fileName();
|
||||
auto contextString = QString("%1:%2").arg(filename).arg(context.line);
|
||||
const QString &message, const QString &fileLine, QtMsgType type) {
|
||||
|
||||
auto title = type == QtFatalMsg ? "Fatal error" : "Critical error";
|
||||
QString text;
|
||||
|
|
@ -75,8 +73,7 @@ void showErrorDialog(
|
|||
}
|
||||
|
||||
const QString version = QString::fromStdString(synergy::version());
|
||||
text +=
|
||||
QString("<pre>v%1\n%2\n%3</pre>").arg(version, message, contextString);
|
||||
text += QString("<pre>v%1\n%2\n%3</pre>").arg(version, message, fileLine);
|
||||
|
||||
if (type == QtFatalMsg) {
|
||||
// create a blocking message box for fatal errors, as we want to wait
|
||||
|
|
@ -109,13 +106,21 @@ void showErrorDialog(
|
|||
}
|
||||
}
|
||||
|
||||
QString fileLine(const QMessageLogContext &context) {
|
||||
if (!context.file) {
|
||||
return "";
|
||||
}
|
||||
return QString("%1:%2").arg(context.file).arg(context.line);
|
||||
}
|
||||
|
||||
void messageHandler(
|
||||
QtMsgType type, const QMessageLogContext &context, const QString &message) {
|
||||
|
||||
Logger::instance().handleMessage(type, context, message);
|
||||
const auto fileLine = messages::fileLine(context);
|
||||
Logger::instance().handleMessage(type, fileLine, message);
|
||||
|
||||
if (type == QtFatalMsg || type == QtCriticalMsg) {
|
||||
showErrorDialog(message, context, type);
|
||||
showErrorDialog(message, fileLine, type);
|
||||
}
|
||||
|
||||
if (type == QtFatalMsg) {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ TEST(LoggerTests, handleMessage_withDebugEnvVarOn_emitsNewLine) {
|
|||
qputenv("SYNERGY_GUI_DEBUG", "true");
|
||||
logger.loadEnvVars();
|
||||
|
||||
logger.handleMessage(QtDebugMsg, QMessageLogContext(), "test");
|
||||
logger.handleMessage(QtDebugMsg, "stub", "test");
|
||||
|
||||
EXPECT_THAT(newLineEmitted, HasSubstr("test"));
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ TEST(LoggerTests, handleMessage_withDebugEnvVarOff_doesNotEmitNewLine) {
|
|||
qputenv("SYNERGY_GUI_DEBUG", "false");
|
||||
logger.loadEnvVars();
|
||||
|
||||
logger.handleMessage(QtDebugMsg, QMessageLogContext(), "test");
|
||||
logger.handleMessage(QtDebugMsg, "stub", "test");
|
||||
|
||||
EXPECT_FALSE(newLineEmitted);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue