diff --git a/src/core/astnode.cpp b/src/core/astnode.cpp index 339900bf..7dcbb8e3 100644 --- a/src/core/astnode.cpp +++ b/src/core/astnode.cpp @@ -50,7 +50,7 @@ bool AstNode::isValid() const std::optional AstNode::node() const { if (!isValid()) { - spdlog::warn("AstNode is invalid"); + spdlog::warn("{}: AstNode is invalid", FUNCTION); return std::nullopt; } diff --git a/src/core/classsymbol.cpp b/src/core/classsymbol.cpp index 5105d36d..92dd9c01 100644 --- a/src/core/classsymbol.cpp +++ b/src/core/classsymbol.cpp @@ -40,7 +40,7 @@ QList ClassSymbol::findMembers() const } return members; } - spdlog::warn("Parent of CppClass {} is not an CodeDocument!", m_name); + spdlog::warn("{}: Parent of CppClass {} is not an CodeDocument!", FUNCTION, m_name); return {}; } diff --git a/src/core/codedocument.cpp b/src/core/codedocument.cpp index 8baa3655..14b760b7 100644 --- a/src/core/codedocument.cpp +++ b/src/core/codedocument.cpp @@ -132,7 +132,7 @@ void CodeDocument::deleteSymbol(const Symbol &symbol) */ Core::SymbolList CodeDocument::symbols() const { - LOG("CodeDocument::symbols"); + LOG(FUNCTION); return m_treeSitterHelper->symbols(); } @@ -199,7 +199,7 @@ QString CodeDocument::hover(int position, std::function a std::pair> CodeDocument::hoverWithRange( int position, std::function)> asyncCallback /* = {} */) const { - spdlog::debug("CodeDocument::hover"); + spdlog::debug("{}", FUNCTION); if (!checkClient()) return {"", {}}; @@ -226,8 +226,10 @@ std::pair> CodeDocument::hoverWithRange( if (const auto *content = std::get_if(&hover.contents)) { return {QString::fromStdString(content->value), range}; } else { - spdlog::warn("LSP returned deprecated MarkedString type which is unsupported by Knut\n - Consider updating " - "your LSP server"); + spdlog::warn( + "{}: LSP returned deprecated MarkedString type which is unsupported by Knut\n - Consider updating " + "your LSP server", + FUNCTION); return {"", {}}; } }; @@ -245,7 +247,7 @@ std::pair> CodeDocument::hoverWithRange( // a Tooltip is requested. // See: TextView::eventFilter. if (!std::holds_alternative(result.value())) { - spdlog::debug("LSP server returned no result for Hover"); + spdlog::debug("{}: LSP server returned no result for Hover", FUNCTION); } return convertResult(result.value()); } @@ -256,7 +258,7 @@ std::pair> CodeDocument::hoverWithRange( RangeMarkList CodeDocument::references(int position) const { - spdlog::debug("CodeDocument::references"); + spdlog::debug("{}", FUNCTION); if (!checkClient()) { return {}; @@ -271,10 +273,10 @@ RangeMarkList CodeDocument::references(int position) const if (const auto *locations = std::get_if>(&value)) { return Utils::lspToRangeMarkList(*locations); } else { - spdlog::warn("CodeDocument::references: Language server returned unsupported references type!"); + spdlog::warn("{}: Language server returned unsupported references type!", FUNCTION); } } else { - spdlog::warn("CodeDocument::references: LSP call to references returned nothing!"); + spdlog::warn("{}: LSP call to references returned nothing!", FUNCTION); } return {}; @@ -283,7 +285,7 @@ RangeMarkList CodeDocument::references(int position) const // Follows the symbol under the cursor. Document *CodeDocument::followSymbol() { - spdlog::debug("CodeDocument::followSymbol"); + spdlog::debug("{}", FUNCTION); if (!checkClient()) return {}; @@ -332,7 +334,7 @@ Document *CodeDocument::followSymbol(int pos) return nullptr; if (locations.size() > 1) - spdlog::warn("CodeDocument::followSymbol: Multiple locations returned!"); + spdlog::warn("{}: Multiple locations returned!", FUNCTION); // Heuristic: If multiple locations were found, use the last one. auto location = locations.back(); @@ -347,8 +349,7 @@ Document *CodeDocument::followSymbol(int pos) if (auto *codeDocument = qobject_cast(document)) { codeDocument->selectRange(Utils::lspToRange(*codeDocument, location.range)); } else { - spdlog::warn("CodeDocument::followSymbol: Opened document '{}' is not an CodeDocument", - document->fileName()); + spdlog::warn("{}: Opened document '{}' is not an CodeDocument", FUNCTION, document->fileName()); } } @@ -358,7 +359,7 @@ Document *CodeDocument::followSymbol(int pos) // Switches between the function declaration or definition. Document *CodeDocument::switchDeclarationDefinition() { - spdlog::debug("CodeDocument::switchDeclarationDefinition"); + spdlog::debug("{}", FUNCTION); if (!checkClient()) return {}; @@ -371,7 +372,7 @@ Document *CodeDocument::switchDeclarationDefinition() }); if (!currentFunction) { - spdlog::info("CodeDocument::switchDeclarationDefinition: Cursor is currently not within a function!"); + spdlog::info("{}: Cursor is currently not within a function!", FUNCTION); return nullptr; } @@ -390,7 +391,7 @@ Document *CodeDocument::switchDeclarationDefinition() */ void CodeDocument::selectSymbol(const QString &name, int options) { - LOG("CodeDocument::selectSymbol", LOG_ARG("text", name), options); + LOG(FUNCTION, LOG_ARG("text", name), options); if (auto symbol = findSymbol(name, options)) selectRange(symbol->selectionRange()); @@ -469,8 +470,7 @@ int CodeDocument::selectSmallerSyntaxNode(int count /* = 1*/) if (node.has_value()) { selectRegion(node->startPosition(), node->endPosition()); } else { - spdlog::warn( - "CodeDocument::selectSmallerSyntaxNode: No smaller node found! Do you currently not have a selection?"); + spdlog::warn("{}: No smaller node found! Do you currently not have a selection?", FUNCTION); } LOG_RETURN("pos", position()); @@ -566,7 +566,7 @@ int CodeDocument::selectPreviousSyntaxNode(int count /*= 1*/) */ Symbol *CodeDocument::findSymbol(const QString &name, int options) const { - LOG("CodeDocument::findSymbol", LOG_ARG("text", name), options); + LOG(FUNCTION, LOG_ARG("text", name), options); auto symbols = this->symbols(); const auto regexp = @@ -681,7 +681,7 @@ Core::QueryMatchList CodeDocument::query(const std::shared_ptrquery(m_treeSitterHelper->constructQuery(query)); } @@ -701,7 +701,7 @@ Core::QueryMatchList CodeDocument::query(const QString &query) */ Core::QueryMatch CodeDocument::queryFirst(const QString &query) { - LOG("CodeDocument::queryOne", LOG_ARG("query", query)); + LOG(FUNCTION, LOG_ARG("query", query)); return this->queryFirst(m_treeSitterHelper->constructQuery(query)); } @@ -715,20 +715,20 @@ Core::QueryMatch CodeDocument::queryFirst(const QString &query) */ Core::QueryMatchList CodeDocument::queryInRange(const Core::RangeMark &range, const QString &query) { - LOG("CodeDocument::queryInRange", LOG_ARG("range", range), LOG_ARG("query", query)); + LOG(FUNCTION, LOG_ARG("range", range), LOG_ARG("query", query)); if (!range.isValid()) { - spdlog::warn("CodeDocument::queryInRange: Range is not valid"); + spdlog::warn("{}: Range is not valid", FUNCTION); return {}; } const auto nodes = m_treeSitterHelper->nodesInRange(range); if (nodes.isEmpty()) { - spdlog::warn("CodeDocument::queryInRange: No nodes in range"); + spdlog::warn("{}: No nodes in range", FUNCTION); return {}; } - spdlog::debug("CodeDocument::queryInRange: Found {} nodes in range", nodes.size()); + spdlog::debug("{}: Found {} nodes in range", FUNCTION, nodes.size()); auto tsQuery = m_treeSitterHelper->constructQuery(query); if (!tsQuery) @@ -755,7 +755,7 @@ bool CodeDocument::checkClient() const { Q_ASSERT(textEdit()); if (!client()) { - spdlog::error("CodeDocument {} has no LSP client - API not available", fileName()); + spdlog::error("{}: CodeDocument {} has no LSP client - API not available", FUNCTION, fileName()); return false; } return true; @@ -770,14 +770,16 @@ void CodeDocument::changeContentLsp(int position, int charsRemoved, int charsAdd // TODO: Keep copy of previous string around, so we can find the oldEndPosition. // const auto document = textEdit()->document(); // const auto startblock = document->findBlock(position); - // spdlog::warn("start point: {}, {}", startblock.blockNumber(), position - startblock.position()); + // spdlog::warn("{} - start point: {}, {}", FUNCTION, startblock.blockNumber(), position - + // startblock.position()); // const auto newEndPosition = position + charsAdded; // const auto newEndBlock = document->findBlock(newEndPosition); - // spdlog::warn("new end point: {}, {}", newEndBlock.blockNumber(), newEndPosition - newEndBlock.position()); + // spdlog::warn("{} - new end point: {}, {}", FUNCTION, newEndBlock.blockNumber(), newEndPosition - + // newEndBlock.position()); // const auto plain = document->toPlainText(); - // spdlog::warn("added: {}", plain.sliced(position, charsAdded)); + // spdlog::warn("{} - added: {}", FUNCTION, plain.sliced(position, charsAdded)); if (!checkClient()) { return; @@ -811,7 +813,7 @@ void CodeDocument::changeContentLsp(int position, int charsRemoved, int charsAdd client()->didChange(std::move(params)); } else { - spdlog::error("LSP server does not support Document changes!"); + spdlog::error("{}: LSP server does not support Document changes!", FUNCTION); } } diff --git a/src/core/codedocument_p.cpp b/src/core/codedocument_p.cpp index d23db3e6..775eb9f0 100644 --- a/src/core/codedocument_p.cpp +++ b/src/core/codedocument_p.cpp @@ -50,12 +50,12 @@ std::optional &TreeSitterHelper::syntaxTree() if (!m_tree) { auto &parser = this->parser(); if (!parser.setIncludedRanges(m_document->includedRanges())) { - spdlog::warn("TreeSitterHelper::syntaxTree: Unable to set the included ranges on the treesitter parser!"); + spdlog::warn("{}: Unable to set the included ranges on the treesitter parser!", FUNCTION); parser.setIncludedRanges({}); } m_tree = parser.parseString(m_document->text()); if (!m_tree) { - spdlog::warn("CodeDocument::syntaxTree: Failed to parse document {}!", m_document->fileName()); + spdlog::warn("{}: Failed to parse document {}!", FUNCTION, m_document->fileName()); } } return m_tree; @@ -67,8 +67,8 @@ std::shared_ptr TreeSitterHelper::constructQuery(const QStrin try { tsQuery = std::make_shared(parser().language(), query); } catch (treesitter::Query::Error &error) { - spdlog::error("CodeDocument::constructQuery: Failed to parse query `{}` error: {} at: {}", query, - error.description, error.utf8_offset); + spdlog::error("{}: Failed to parse query `{}` error: {} at: {}", FUNCTION, query, error.description, + error.utf8_offset); return {}; } return tsQuery; diff --git a/src/core/cppdocument.cpp b/src/core/cppdocument.cpp index c8be798b..42098438 100644 --- a/src/core/cppdocument.cpp +++ b/src/core/cppdocument.cpp @@ -320,7 +320,7 @@ bool CppDocument::isHeader() const */ void CppDocument::commentSelection() { - LOG("CppDocument::commentSelection"); + LOG(FUNCTION); QTextCursor cursor = textEdit()->textCursor(); cursor.beginEditBlock(); @@ -434,7 +434,7 @@ static int commonFilePathLength(const QString &s1, const QString &s2) */ QString CppDocument::correspondingHeaderSource() const { - LOG("CppDocument::correspondingHeaderSource"); + LOG(FUNCTION); static QHash cache; QString cacheData = cache.value(fileName()); @@ -453,7 +453,7 @@ QString CppDocument::correspondingHeaderSource() const if (QFile::exists(testFileName)) { cache[fileName()] = testFileName; cache[testFileName] = fileName(); - spdlog::debug("CppDocument::correspondingHeaderSource {} => {}", fileName(), testFileName); + spdlog::debug("{}: {} => {}", FUNCTION, fileName(), testFileName); LOG_RETURN("path", testFileName); } } @@ -482,11 +482,11 @@ QString CppDocument::correspondingHeaderSource() const if (!bestFileName.isEmpty()) { cache[fileName()] = bestFileName; cache[bestFileName] = fileName(); - spdlog::debug("CppDocument::correspondingHeaderSource {} => {}", fileName(), bestFileName); + spdlog::debug("{}: {} => {}", FUNCTION, fileName(), bestFileName); LOG_RETURN("path", bestFileName); } - spdlog::warn("CppDocument::correspondingHeaderSource {} - not found ", fileName()); + spdlog::warn("{}: {} - not found ", FUNCTION, fileName()); return {}; } @@ -497,7 +497,7 @@ QString CppDocument::correspondingHeaderSource() const */ CppDocument *CppDocument::openHeaderSource() { - LOG("CppDocument::openHeaderSource"); + LOG(FUNCTION); const QString fileName = correspondingHeaderSource(); if (!fileName.isEmpty()) LOG_RETURN("document", qobject_cast(Project::instance()->open(fileName))); @@ -517,19 +517,18 @@ CppDocument *CppDocument::openHeaderSource() */ Core::QueryMatch CppDocument::queryClassDefinition(const QString &className) { - LOG("CppDocument::queryClassDefinition", LOG_ARG("className", className)); + LOG(FUNCTION, LOG_ARG("className", className)); const auto classDefinitionQuery = classQuery({className}); auto matches = query(classDefinitionQuery); if (matches.isEmpty()) { - spdlog::warn("CppDocument::queryClassDefinition: No class named `{}` found in `{}`", className, fileName()); + spdlog::warn("{}: No class named `{}` found in `{}`", FUNCTION, className, fileName()); return {}; } if (matches.size() > 1) { - spdlog::error("CppDocument::queryClassDefinition: Multiple classes named `{}` found in `{}`!", className, - fileName()); + spdlog::error("{}: Multiple classes named `{}` found in `{}`!", FUNCTION, className, fileName()); } return matches.first(); } @@ -556,7 +555,7 @@ Core::QueryMatch CppDocument::queryClassDefinition(const QString &className) */ Core::QueryMatchList CppDocument::queryMethodDefinition(const QString &scope, const QString &functionName) { - LOG("CppDocument::queryMethodDefinition", LOG_ARG("scope", scope), LOG_ARG("functionName", functionName)); + LOG(FUNCTION, LOG_ARG("scope", scope), LOG_ARG("functionName", functionName)); const auto functionDeclarator = functionDeclaratorQuery(scope, {functionName}); const auto pointerDeclaration = pointerDeclaratorQuery(functionDeclarator, "@return"); @@ -597,11 +596,11 @@ QList CppDocument::internalQueryFunctionCall(const QString &function */ Core::QueryMatchList CppDocument::queryFunctionCall(const QString &functionName, const QStringList &argumentCaptures) { - LOG("queryFunctionCall", LOG_ARG("functionName", functionName), LOG_ARG("argumentCaptures", argumentCaptures)); + LOG(FUNCTION, LOG_ARG("functionName", functionName), LOG_ARG("argumentCaptures", argumentCaptures)); for (const auto &argument : argumentCaptures) { if (kdalgorithms::value_in(argument, {"call", "name", "argument-list"})) { - spdlog::warn("CppDocument::queryFunctionCall: provided capture {} is reserved!", argument); + spdlog::warn("{}: provided capture {} is reserved!", FUNCTION, argument); } } @@ -634,7 +633,7 @@ Core::QueryMatchList CppDocument::queryFunctionCall(const QString &functionName, */ Core::QueryMatchList CppDocument::queryFunctionCall(const QString &functionName) { - LOG("queryFunctionCall", LOG_ARG("functionName", functionName)); + LOG(FUNCTION, LOG_ARG("functionName", functionName)); return internalQueryFunctionCall(functionName, R"EOF([(_) @arguments ","]* (#exclude! @arguments comment))EOF"); } @@ -650,16 +649,16 @@ Core::QueryMatchList CppDocument::queryFunctionCall(const QString &functionName) */ bool CppDocument::insertCodeInMethod(const QString &methodName, QString code, Position insertAt) { - LOG("CppDocument::insertCodeInMethod", methodName, code, insertAt); + LOG(FUNCTION, methodName, code, insertAt); auto symbol = findSymbol(methodName); if (!symbol) { - spdlog::warn("CppDocument::insertCodeInMethod: No symbol found for {}.", methodName); + spdlog::warn("{}: No symbol found for {}.", FUNCTION, methodName); return false; } if (!symbol->isFunction()) { - spdlog::warn("CppDocument::insertCodeInMethod: {} is not a function or a method.", symbol->name()); + spdlog::warn("{}: {} is not a function or a method.", FUNCTION, symbol->name()); return false; } @@ -667,7 +666,7 @@ bool CppDocument::insertCodeInMethod(const QString &methodName, QString code, Po cursor.setPosition(symbol->range().end()); cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor); if (cursor.selectedText() != "}") { - spdlog::warn("CppDocument::insertCodeInMethod: {} is not a function definition.", symbol->name()); + spdlog::warn("{}: {} is not a function definition.", FUNCTION, symbol->name()); return false; } @@ -724,9 +723,9 @@ bool CppDocument::insertCodeInMethod(const QString &methodName, QString code, Po */ bool CppDocument::insertForwardDeclaration(const QString &forwardDeclaration) { - LOG("CppDocument::insertForwardDeclaration", LOG_ARG("text", forwardDeclaration)); + LOG(FUNCTION, LOG_ARG("text", forwardDeclaration)); if (!isHeader()) { - spdlog::warn("CppDocument::insertForwardDeclaration: {} - is not a header file. ", fileName()); + spdlog::warn("{}: {} - is not a header file. ", FUNCTION, fileName()); return false; } @@ -734,8 +733,7 @@ bool CppDocument::insertForwardDeclaration(const QString &forwardDeclaration) const auto classOrStruct = QStringView(forwardDeclaration).left(spacePos); if (forwardDeclaration.isEmpty() || (classOrStruct != QStringLiteral("class") && classOrStruct != QStringLiteral("struct"))) { - spdlog::warn("CppDocument::insertForwardDeclaration: {} - should start with 'class ' or 'struct '. ", - forwardDeclaration); + spdlog::warn("{}: {} - should start with 'class ' or 'struct '. ", FUNCTION, forwardDeclaration); return false; } @@ -751,7 +749,7 @@ bool CppDocument::insertForwardDeclaration(const QString &forwardDeclaration) QTextCursor cursor(doc); cursor = doc->find(result, cursor, QTextDocument::FindWholeWords); if (!cursor.isNull()) { - spdlog::warn("CppDocument::insertForwardDeclaration: '{}' - already exists in file.", forwardDeclaration); + spdlog::warn("{}: '{}' - already exists in file.", FUNCTION, forwardDeclaration); return false; } @@ -794,17 +792,17 @@ bool CppDocument::insertForwardDeclaration(const QString &forwardDeclaration) */ DataExchange CppDocument::mfcExtractDDX(const QString &className) { - LOG("CppDocument::mfcExtractDDX", LOG_ARG("text", className)); + LOG(FUNCTION, LOG_ARG("text", className)); auto functions = queryMethodDefinition(className, "DoDataExchange"); if (functions.isEmpty()) { - spdlog::warn("CppDocument::mfcExtractDDX: No DoDataExchange found in `{}`", fileName()); + spdlog::warn("{}: No DoDataExchange found in `{}`", FUNCTION, fileName()); return {}; } if (functions.size() > 1) { - spdlog::warn("CppDocument::mfcExtractDDX: Too many DoDataExchange methods found in `{}`", fileName()); + spdlog::warn("{}: Too many DoDataExchange methods found in `{}`", FUNCTION, fileName()); } auto &function = functions.first(); @@ -872,7 +870,7 @@ MessageMap CppDocument::mfcExtractMessageMap(const QString &className /* = ""*/) // As the MessageMap query is quite complicated, this can significantly improve performance. auto match = queryFirst(queryString); if (match.isEmpty()) { - spdlog::warn("CppDocument::mfcExtractMessageMap: No message map found in `{}`", fileName()); + spdlog::warn("{}: No message map found in `{}`", FUNCTION, fileName()); return {}; } @@ -900,12 +898,12 @@ MessageMap CppDocument::mfcExtractMessageMap(const QString &className /* = ""*/) */ Core::QueryMatchList CppDocument::queryMethodDeclaration(const QString &className, const QString &functionName) { - LOG("CppDocument::queryMethodDeclaration", LOG_ARG("className", className), LOG_ARG("functionName", functionName)); + LOG(FUNCTION, LOG_ARG("className", className), LOG_ARG("functionName", functionName)); auto classQuery = queryClassDefinition(className); if (classQuery.isEmpty()) { - spdlog::warn("CppDocument::queryMethodDeclaration: No class named `{}` found in `{}`", className, fileName()); + spdlog::warn("{}: No class named `{}` found in `{}`", FUNCTION, className, fileName()); return {}; } @@ -940,8 +938,7 @@ Core::QueryMatchList CppDocument::queryMethodDeclaration(const QString &classNam auto matches = classQuery.queryIn("body", queryString); if (matches.isEmpty()) { - spdlog::warn("CppDocument::queryMethodDeclaration: No method named `{}` found in `{}`", functionName, - fileName()); + spdlog::warn("{}: No method named `{}` found in `{}`", FUNCTION, functionName, fileName()); } return matches; @@ -963,18 +960,18 @@ Core::QueryMatchList CppDocument::queryMethodDeclaration(const QString &classNam */ Core::QueryMatch CppDocument::queryMember(const QString &className, const QString &memberName) { - LOG("CppDocument::queryMember", LOG_ARG("className", className), LOG_ARG("memberName", memberName)); + LOG(FUNCTION, LOG_ARG("className", className), LOG_ARG("memberName", memberName)); auto classQuery = queryClassDefinition(className); auto matches = classQuery.queryIn("body", membersQuery(memberName)); if (matches.isEmpty()) { - spdlog::warn("CppDocument::queryMember: No member named `{}` found in `{}`", memberName, fileName()); + spdlog::warn("{}: No member named `{}` found in `{}`", FUNCTION, memberName, fileName()); return {}; } if (matches.size() > 1) { - spdlog::error("CppDocument::queryMember: Multiple members named `{}` found in `{}`!", memberName, fileName()); + spdlog::error("{}: Multiple members named `{}` found in `{}`!", FUNCTION, memberName, fileName()); } return matches.first(); } @@ -1166,7 +1163,7 @@ int CppDocument::moveBlock(int startPos, QTextCursor::MoveOperation direction) */ void CppDocument::toggleSection() { - LOG("CppDocument::toggleSection"); + LOG(FUNCTION); auto sectionSettings = Settings::instance()->value(Settings::ToggleSection); const auto endifString = QStringLiteral("#endif // ") + sectionSettings.tag; @@ -1264,18 +1261,17 @@ void CppDocument::toggleSection() */ bool CppDocument::insertInclude(const QString &include, bool newGroup) { - LOG("CppDocument::insertInclude", LOG_ARG("text", include), newGroup); + LOG(FUNCTION, LOG_ARG("text", include), newGroup); IncludeHelper includeHelper(this); auto includePos = includeHelper.includePositionForInsertion(include, newGroup); if (!includePos) { - spdlog::error(R"(CppDocument::insertInclude - the include '{}' is malformed, should be '' or '"foo.h"')", - include); + spdlog::error(R"({}: the include '{}' is malformed, should be '' or '"foo.h"')", FUNCTION, include); return false; } if (includePos->alreadyExists()) { - spdlog::info("CppDocument::insertInclude - the include '{}' is already included.", include); + spdlog::info("{}: the include '{}' is already included.", FUNCTION, include); return true; } @@ -1342,11 +1338,11 @@ CppDocument::addMemberOrMethod(const QString &memberInfo, const QString &classNa */ bool CppDocument::addMember(const QString &member, const QString &className, AccessSpecifier specifier) { - LOG("CppDocument::addMember", member, className, specifier); + LOG(FUNCTION, member, className, specifier); auto result = addMemberOrMethod(member, className, specifier); if (result == MemberOrMethodAdditionResult::ClassNotFound) { - spdlog::error(R"(CppDocument::addMember- Can't find class '{}')", className); + spdlog::error(R"({}: Can't find class '{}')", FUNCTION, className); } return true; @@ -1367,11 +1363,11 @@ bool CppDocument::addMember(const QString &member, const QString &className, Acc */ bool CppDocument::addMethodDeclaration(const QString &method, const QString &className, AccessSpecifier specifier) { - LOG("CppDocument::addMethodDeclaration", method, className, specifier); + LOG(FUNCTION, method, className, specifier); auto result = addMemberOrMethod(method, className, specifier); if (result == MemberOrMethodAdditionResult::ClassNotFound) { - spdlog::error(R"(CppDocument::addMethodDeclaration - Can't find class '{}')", className); + spdlog::error(R"({}: Can't find class '{}')", FUNCTION, className); } return true; @@ -1389,7 +1385,7 @@ bool CppDocument::addMethodDeclaration(const QString &method, const QString &cla */ bool CppDocument::addMethodDefinition(const QString &method, const QString &className, const QString &body /*= ""*/) { - LOG("CppDocument::addMethodDefinition", method, className); + LOG(FUNCTION, method, className); QString definition = method; @@ -1460,13 +1456,13 @@ bool CppDocument::addMethod(const QString &declaration, const QString &className if (header) { result &= header->addMethodDeclaration(declaration, className, specifier); } else { - spdlog::error("CppDocument::addMethod - Can't find header file for '{}'", className); + spdlog::error("{}: Can't find header file for '{}'", FUNCTION, className); } if (source) { result &= source->addMethodDefinition(declaration, className, body); } else { - spdlog::error("CppDocument::addMethod - Can't find source file for '{}'", className); + spdlog::error("{}: Can't find source file for '{}'", FUNCTION, className); } return result; @@ -1509,18 +1505,17 @@ bool CppDocument::addSpecifierSection(const QString &memberText, const QString & */ bool CppDocument::removeInclude(const QString &include) { - LOG("CppDocument::removeInclude", LOG_ARG("text", include)); + LOG(FUNCTION, LOG_ARG("text", include)); IncludeHelper includeHelper(this); auto line = includeHelper.includePositionForRemoval(include); if (!line) { - spdlog::error(R"(CppDocument::removeInclude - the include '{}' is malformed, should be '' or '"foo.h"')", - include); + spdlog::error(R"({}: the include '{}' is malformed, should be '' or '"foo.h"')", FUNCTION, include); return false; } if (line.value() == -1) { - spdlog::info("CppDocument::removeInclude - the include '{}' is not included."); + spdlog::info("{}: the include '{}' is not included.", FUNCTION, include); return true; } @@ -1558,7 +1553,7 @@ void CppDocument::deleteMethodLocal(const QString &methodName, const QString &si std::ranges::sort(symbolList, byRange); for (const auto &symbol : std::as_const(symbolList)) { - spdlog::trace("CppDocument::deleteMethodLocal: Removing symbol '{}'", symbol->name()); + spdlog::trace("{}: Removing symbol '{}'", FUNCTION, symbol->name()); deleteSymbol(*symbol); } @@ -1591,7 +1586,7 @@ void CppDocument::deleteMethodLocal(const QString &methodName, const QString &si */ void CppDocument::deleteMethod(const QString &method, const QString &signature) { - LOG("CppDocument::deleteMethod", method, signature); + LOG(FUNCTION, method, signature); QString headerSourceName = correspondingHeaderSource(); if (!headerSourceName.isEmpty()) { @@ -1611,7 +1606,7 @@ void CppDocument::deleteMethod(const QString &method, const QString &signature) */ void CppDocument::deleteMethod(const QString &methodName) { - LOG("CppDocument::deleteMethod", LOG_ARG("text", methodName)); + LOG(FUNCTION, LOG_ARG("text", methodName)); deleteMethod(methodName, "" /*empty string means ignore signature*/); } @@ -1626,7 +1621,7 @@ void CppDocument::deleteMethod(const QString &methodName) */ void CppDocument::deleteMethod() { - LOG("CppDocument::deleteMethod"); + LOG(FUNCTION); auto isFunction = [](const auto &symbol) { return symbol.isFunction(); @@ -1635,8 +1630,7 @@ void CppDocument::deleteMethod() auto symbol = currentSymbol(isFunction); if (!symbol) { - spdlog::error( - "CppDocument::deleteMethod: Cursor is not currently within a function definition or declaration!"); + spdlog::error("{}: Cursor is not currently within a function definition or declaration!", FUNCTION); } else { deleteMethod(symbol->name(), symbol->toFunction()->signature()); } @@ -1684,20 +1678,19 @@ bool CppDocument::changeBaseClass(CppDocument *header, CppDocument *source, cons auto result = true; const QString baseClassName = header->queryClassDefinition(className).get("base").text(); if (baseClassName.isEmpty()) { - spdlog::error("CppDocument::changeBaseClass - Can't find base class name for class: '{}'", - className.toStdString()); + spdlog::error("{}: Can't find base class name for class: '{}'", FUNCTION, className.toStdString()); return false; } if (header) { result &= header->changeBaseClassHeader(className, baseClassName, newClassBaseName); } else { - spdlog::warn("CppDocument::changeBaseClass - Can't find header file for '{}'", baseClassName); + spdlog::warn("{}: Can't find header file for '{}'", FUNCTION, baseClassName); result = false; } if (source) { result &= source->changeBaseClassSource(className, baseClassName, newClassBaseName); } else { - spdlog::warn("CppDocument::changeBaseClass - Can't find source file for '{}'", baseClassName); + spdlog::warn("{}: Can't find source file for '{}'", FUNCTION, baseClassName); result = false; } return result; @@ -1713,12 +1706,12 @@ bool CppDocument::changeBaseClass(CppDocument *header, CppDocument *source, cons */ bool CppDocument::changeBaseClass(const QString &className, const QString &newClassBaseName) { - LOG("CppDocument::changeBaseClass"); + LOG(FUNCTION); auto header = this; auto source = openHeaderSource(); if (!source) { - spdlog::warn("CppDocument::changeBaseClass - Can't find source file"); + spdlog::warn("{}: Can't find source file", FUNCTION); } else if (!isHeader()) { std::swap(header, source); } @@ -1757,8 +1750,7 @@ QList CppDocument::includedRanges() const QRegularExpression regex(macros.join("|")); if (!regex.isValid()) { - spdlog::error("CppDocument::includedRanges: Failed to create regex for excluded macros: {}", - regex.errorString()); + spdlog::error("{}: Failed to create regex for excluded macros: {}", FUNCTION, regex.errorString()); return {}; } diff --git a/src/core/dir.cpp b/src/core/dir.cpp index 506b1fce..68c7878d 100644 --- a/src/core/dir.cpp +++ b/src/core/dir.cpp @@ -56,7 +56,7 @@ Dir::~Dir() = default; */ QString Dir::toNativeSeparators(const QString &pathName) { - LOG("Dir::toNativeSeparators", pathName); + LOG(FUNCTION, pathName); return QDir::toNativeSeparators(pathName); } @@ -65,7 +65,7 @@ QString Dir::toNativeSeparators(const QString &pathName) */ QString Dir::fromNativeSeparators(const QString &pathName) { - LOG("Dir::fromNativeSeparators", pathName); + LOG(FUNCTION, pathName); return QDir::fromNativeSeparators(pathName); } @@ -74,7 +74,7 @@ QString Dir::fromNativeSeparators(const QString &pathName) */ bool Dir::isRelativePath(const QString &path) { - LOG("Dir::isRelativePath", path); + LOG(FUNCTION, path); return QDir::isRelativePath(path); } @@ -83,7 +83,7 @@ bool Dir::isRelativePath(const QString &path) */ bool Dir::isAbsolutePath(const QString &path) { - LOG("Dir::isAbsolutePath", path); + LOG(FUNCTION, path); return !isRelativePath(path); } @@ -94,7 +94,7 @@ QChar Dir::separator() const bool Dir::setCurrentPath(const QString &path) { - LOG("Dir::setCurrentPath", path); + LOG(FUNCTION, path); if (path != QDir::currentPath()) { if (QDir::setCurrent(path)) { emit currentPathChanged(path); @@ -150,13 +150,13 @@ QString Dir::tempPath() const */ bool Dir::match(const QStringList &filters, const QString &fileName) { - LOG("Dir::match", filters, fileName); + LOG(FUNCTION, filters, fileName); return QDir::match(filters, fileName); } bool Dir::match(const QString &filter, const QString &fileName) { - LOG("Dir::match", filter, fileName); + LOG(FUNCTION, filter, fileName); return QDir::match(filter, fileName); } @@ -165,7 +165,7 @@ bool Dir::match(const QString &filter, const QString &fileName) */ QString Dir::cleanPath(const QString &path) { - LOG("Dir::cleanPath", path); + LOG(FUNCTION, path); return QDir::cleanPath(path); } @@ -174,7 +174,7 @@ QString Dir::cleanPath(const QString &path) */ QDirValueType Dir::create(const QString &path) { - LOG("Dir::create", path); + LOG(FUNCTION, path); return QDirValueType(path); } diff --git a/src/core/document.cpp b/src/core/document.cpp index 902ae18d..af89e8ed 100644 --- a/src/core/document.cpp +++ b/src/core/document.cpp @@ -73,7 +73,7 @@ const QString &Document::fileName() const void Document::setFileName(const QString &newFileName) { - LOG("Document::setFileName", newFileName); + LOG(FUNCTION, newFileName); if (m_fileName == newFileName) return; load(newFileName); @@ -144,9 +144,9 @@ void Document::reload() */ bool Document::load(const QString &fileName) { - LOG("Document::load", fileName); + LOG(FUNCTION, fileName); if (fileName.isEmpty()) { - spdlog::warn("Document::load - fileName is empty"); + spdlog::warn("{}: fileName is empty", FUNCTION); return false; } if (m_fileName == fileName) @@ -169,7 +169,7 @@ bool Document::load(const QString &fileName) */ bool Document::save() { - LOG("Document::save"); + LOG(FUNCTION); return saveAs(m_fileName); } @@ -180,9 +180,9 @@ bool Document::save() */ bool Document::saveAs(const QString &fileName) { - LOG("Document::saveAs", fileName); + LOG(FUNCTION, fileName); if (fileName.isEmpty()) { - spdlog::error("Document::saveAs - fileName is empty"); + spdlog::error("{}: fileName is empty", FUNCTION); return false; } @@ -217,7 +217,7 @@ bool Document::saveAs(const QString &fileName) */ void Document::close() { - LOG("Document::close"); + LOG(FUNCTION); if (m_fileName.isEmpty()) return; if (m_hasChanged) diff --git a/src/core/file.cpp b/src/core/file.cpp index 8c0fa93a..79d1da84 100644 --- a/src/core/file.cpp +++ b/src/core/file.cpp @@ -37,7 +37,7 @@ File::~File() = default; */ bool File::copy(const QString &fileName, const QString &newName) { - LOG("File::copy", fileName, newName); + LOG(FUNCTION, fileName, newName); return QFile::copy(fileName, newName); } @@ -46,7 +46,7 @@ bool File::copy(const QString &fileName, const QString &newName) */ bool File::exists(const QString &fileName) { - LOG("File::exists", fileName); + LOG(FUNCTION, fileName); return QFile::exists(fileName); } @@ -55,7 +55,7 @@ bool File::exists(const QString &fileName) */ bool File::remove(const QString &fileName) { - LOG("File::remove", fileName); + LOG(FUNCTION, fileName); return QFile::remove(fileName); } @@ -64,7 +64,7 @@ bool File::remove(const QString &fileName) */ bool File::rename(const QString &oldName, const QString &newName) { - LOG("File::rename", oldName, newName); + LOG(FUNCTION, oldName, newName); return QFile::rename(oldName, newName); } @@ -73,7 +73,7 @@ bool File::rename(const QString &oldName, const QString &newName) */ bool File::touch(const QString &fileName) { - LOG("File::touch", fileName); + LOG(FUNCTION, fileName); QFile file(fileName); return file.open(QFile::Append); } @@ -83,7 +83,7 @@ bool File::touch(const QString &fileName) */ QString File::readAll(const QString &fileName) { - LOG("File::readAll", fileName); + LOG(FUNCTION, fileName); QFile file(fileName); if (file.open(QFile::ReadOnly | QIODevice::Text)) { QTextStream stream(&file); diff --git a/src/core/imagedocument.cpp b/src/core/imagedocument.cpp index 5b3ca235..2eeee589 100644 --- a/src/core/imagedocument.cpp +++ b/src/core/imagedocument.cpp @@ -26,7 +26,7 @@ QImage ImageDocument::image() const bool ImageDocument::doSave(const QString &fileName) { Q_UNUSED(fileName) - spdlog::error("ImageDocument::doSave - not implemented yet"); + spdlog::error("{}: not implemented yet", FUNCTION); return false; } diff --git a/src/core/knutcore.cpp b/src/core/knutcore.cpp index 9418519a..a3aadab4 100644 --- a/src/core/knutcore.cpp +++ b/src/core/knutcore.cpp @@ -100,7 +100,7 @@ bool KnutCore::process(const QStringList &arguments) if (pathDir.exists()) { Project::instance()->setRoot(rootDir); } else { - spdlog::error("KnutCore::process - Root directory: {}, does not exist. Cannot open a new project!", + spdlog::error("{} - Root directory: {}, does not exist. Cannot open a new project!", FUNCTION, pathDir.absolutePath()); return false; } @@ -131,7 +131,7 @@ bool KnutCore::process(const QStringList &arguments) try { jsonData = json::parse(jsonDataStr.toStdString()); } catch (const json::parse_error &ex) { - spdlog::error("JSON parsing error at byte {}: {}", ex.byte, ex.what()); + spdlog::error("{}: JSON parsing error at byte {}: {}", FUNCTION, ex.byte, ex.what()); return false; } } diff --git a/src/core/logger.h b/src/core/logger.h index 7d5daff6..37ff61ff 100644 --- a/src/core/logger.h +++ b/src/core/logger.h @@ -1,4 +1,4 @@ -/* +/* This file is part of Knut. SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company @@ -29,13 +29,17 @@ /** * Log a method, with all its parameters. */ -#define LOG(name, ...) Core::LoggerObject __loggerObject(name, false, ##__VA_ARGS__) +#define LOG(name, ...) \ + Core::LoggerObject __loggerObject(Core::formatToClassNameFunctionName(std::source_location::current()), name, \ + false, ##__VA_ARGS__) /** * Log a method, with all its parameters. If the previous log is also the same method, it will be merged into one * operation */ -#define LOG_AND_MERGE(name, ...) Core::LoggerObject __loggerObject(name, true, ##__VA_ARGS__) +#define LOG_AND_MERGE(name, ...) \ + Core::LoggerObject __loggerObject(Core::formatToClassNameFunctionName(std::source_location::current()), name, \ + true, ##__VA_ARGS__) /** * Macro to save the returned value in the historymodel @@ -211,7 +215,7 @@ class HistoryModel : public QAbstractTableModel class LoggerObject { public: - explicit LoggerObject(QString name, bool /*unused*/) + explicit LoggerObject(QString location, QString name, bool /*unused*/) : LoggerObject() { if (!m_canLog) @@ -225,22 +229,38 @@ class LoggerObject // This has nothing to do with logging itself, but is just a good place to do it. ScriptDialogItem::updateProgress(); + // Use 'location function name' for: + // e.g LOG("") or LOG(FUNCTION) + // Otherwise keep 'name' as it is passed. + if (name.isEmpty() || name == location) { + name = location; + } + if (m_model) m_model->logData(name); log(std::move(name)); } template - explicit LoggerObject(QString name, bool merge, Ts... params) + explicit LoggerObject(QString location, QString name, bool merge, Ts... params) : LoggerObject() { if (!m_canLog) return; + + // Use 'location function name' for: + // e.g LOG("", ) or LOG(FUNCTION, ) + // Otherwise keep 'name' as it is passed. + if (name.isEmpty() || name == location) { + name = location; + } + if (m_model) m_model->logData(name, merge, params...); QStringList paramList; (paramList.push_back(valueToString(params)), ...); + QString result = name + " - " + paramList.join(", "); log(std::move(result)); } diff --git a/src/core/mark.cpp b/src/core/mark.cpp index d02c30e2..2361deb7 100644 --- a/src/core/mark.cpp +++ b/src/core/mark.cpp @@ -51,7 +51,7 @@ namespace Core { bool MarkPrivate::checkEditor() const { if (!m_editor) { - spdlog::error("Mark::checkEditor - document does not exist anymore"); + spdlog::error("{}: - document does not exist anymore", FUNCTION); return false; } return true; @@ -139,7 +139,7 @@ TextDocument *Mark::document() const */ void Mark::restore() const { - LOG("Mark::restore"); + LOG(FUNCTION); if (isValid()) { document()->gotoMark(*this); } diff --git a/src/core/project.cpp b/src/core/project.cpp index aa537fe9..fc206c2a 100644 --- a/src/core/project.cpp +++ b/src/core/project.cpp @@ -88,15 +88,15 @@ const QString &Project::root() const bool Project::setRoot(const QString &newRoot) { - LOG("Project::setRoot", newRoot); + LOG(FUNCTION, newRoot); const QDir dir(newRoot); if (m_root == dir.absolutePath()) return true; if (m_root.isEmpty()) { - spdlog::info("Project::setRoot {}", dir.absolutePath()); + spdlog::info("{}: {}", FUNCTION, dir.absolutePath()); } else { - spdlog::error("Project::setRoot - can't open a new project"); + spdlog::error("{}: can't open a new project", FUNCTION); return false; } @@ -122,7 +122,7 @@ QStringList Project::allFiles(PathType type) const if (m_root.isEmpty()) return {}; - LOG("Project::allFiles", type); + LOG(FUNCTION, type); QDir dir(m_root); QDirIterator it(m_root, QDirIterator::Subdirectories); @@ -150,7 +150,7 @@ QStringList Project::allFilesWithExtension(const QString &extension, PathType ty if (m_root.isEmpty()) return {}; - LOG("Project::allFilesWithExtension", extension, type); + LOG(FUNCTION, extension, type); QDir dir(m_root); QDirIterator it(m_root, QDirIterator::Subdirectories); @@ -178,7 +178,7 @@ QStringList Project::allFilesWithExtensions(const QStringList &extensions, PathT if (m_root.isEmpty()) return {}; - LOG("Project::allFilesWithExtensions", extensions, type); + LOG(FUNCTION, extensions, type); QDir dir(m_root); QDirIterator it(m_root, QDirIterator::Subdirectories); @@ -289,7 +289,7 @@ Document *Project::getDocument(QString fileName, bool moveToBack) m_documents.push_back(doc); emit documentsChanged(); } else { - spdlog::error("Project::open {} - unknown document type", fi.suffix()); + spdlog::error("{}: {} - unknown document type", FUNCTION, fi.suffix()); return nullptr; } } @@ -309,7 +309,7 @@ Document *Project::getDocument(QString fileName, bool moveToBack) */ Document *Project::get(const QString &fileName) { - LOG("Project::get", LOG_ARG("path", fileName)); + LOG(FUNCTION, LOG_ARG("path", fileName)); LOG_RETURN("document", getDocument(fileName, false)); } @@ -326,7 +326,7 @@ Document *Project::open(const QString &fileName) if (m_current && m_current->fileName() == fileName) return m_current; - LOG("Project::open", LOG_ARG("path", fileName)); + LOG(FUNCTION, LOG_ARG("path", fileName)); m_current = getDocument(fileName, true); emit currentDocumentChanged(m_current); @@ -340,7 +340,8 @@ Document *Project::open(const QString &fileName) */ void Project::closeAll() { - LOG("Project::closeAll"); + LOG(FUNCTION); + for (auto d : std::as_const(m_documents)) d->close(); } @@ -356,7 +357,7 @@ Core::Document *Project::currentDocument() const */ void Project::saveAllDocuments() { - LOG("Project::saveAllDocuments"); + LOG(FUNCTION); for (auto d : std::as_const(m_documents)) { if (d->hasChanged()) { @@ -373,7 +374,7 @@ void Project::saveAllDocuments() */ Document *Project::openPrevious(int index) { - LOG("Project::openPrevious", index); + LOG(FUNCTION, index); Q_ASSERT(index < m_documents.size()); index = m_documents.size() - index - 1; diff --git a/src/core/qttsdocument.cpp b/src/core/qttsdocument.cpp index adff5d3c..3695801e 100644 --- a/src/core/qttsdocument.cpp +++ b/src/core/qttsdocument.cpp @@ -60,7 +60,7 @@ void QtTsDocument::initializeXml() */ void QtTsDocument::setLanguage(const QString &lang) { - LOG("QtTsDocument::setLanguage", lang); + LOG(FUNCTION, lang); initializeXml(); auto ts = m_document.select_node("TS"); const auto attributeName = "language"; @@ -81,7 +81,7 @@ void QtTsDocument::setLanguage(const QString &lang) */ void QtTsDocument::setSourceLanguage(const QString &lang) { - LOG("QtTsDocument::setSourceLanguage", lang); + LOG(FUNCTION, lang); initializeXml(); auto ts = m_document.select_node("TS"); const auto attributeName = "sourcelanguage"; @@ -125,9 +125,9 @@ void QtTsDocument::addMessage(pugi::xml_node contextChild, const QString &contex void QtTsDocument::addMessage(const QString &context, const QString &fileName, const QString &source, const QString &translation, const QString &comment) { - LOG("QtTsDocument::addMessage", context, fileName, source, translation, comment); + LOG(FUNCTION, context, fileName, source, translation, comment); if (fileName.isEmpty() || source.isEmpty() || context.isEmpty()) { - spdlog::error(R"(Location or context or source is empty)"); + spdlog::error(R"({}: Location or context or source is empty)", FUNCTION); } initializeXml(); @@ -167,7 +167,7 @@ void QtTsDocument::addMessage(const QString &context, const QString &fileName, c void QtTsDocument::setMessageContext(const QString &context, const QString &comment, const QString &source, const QString &newContext) { - LOG("QtTsDocument::setContext", context, comment, source, newContext); + LOG(FUNCTION, context, comment, source, newContext); initializeXml(); @@ -249,7 +249,7 @@ bool QtTsDocument::doLoad(const QString &fileName) const auto ts = m_document.select_nodes("TS"); if (ts.empty()) { - spdlog::critical("invalid file {}", fileName); + spdlog::critical("{}: invalid file {}", FUNCTION, fileName); return false; } @@ -330,7 +330,7 @@ QString QtTsMessage::fileName() const void QtTsMessage::setFileName(const QString &file) { - LOG("QtTsMessage::setFileName", file); + LOG(FUNCTION, file); m_message.child("location").attribute("filename").set_value(file.toLatin1().constData()); qobject_cast(parent())->setHasChanged(true); Q_EMIT fileNameChanged(); @@ -343,7 +343,7 @@ int QtTsMessage::line() const void QtTsMessage::setLine(int line) { - LOG("QtTsMessage::setLine", line); + LOG(FUNCTION, line); m_message.child("location").attribute("line").set_value(QByteArray::number(line).constData()); qobject_cast(parent())->setHasChanged(true); Q_EMIT lineChanged(); @@ -356,7 +356,7 @@ QString QtTsMessage::comment() const void QtTsMessage::setComment(const QString &comment) { - LOG("QtTsMessage::setComment", comment); + LOG(FUNCTION, comment); m_message.child("comment").set_value(comment.toLatin1().constData()); qobject_cast(parent())->setHasChanged(true); Q_EMIT commentChanged(); @@ -369,7 +369,7 @@ QString QtTsMessage::source() const void QtTsMessage::setSource(const QString &source) { - LOG("QtTsMessage::setSource", source); + LOG(FUNCTION, source); m_message.child("source").set_value(source.toLatin1().constData()); qobject_cast(parent())->setHasChanged(true); Q_EMIT sourceChanged(); @@ -382,7 +382,7 @@ QString QtTsMessage::translation() const void QtTsMessage::setTranslation(const QString &translation) { - LOG("QtTsMessage::setTranslation", translation); + LOG(FUNCTION, translation); m_message.child("translation").remove_attribute("type"); m_message.child("translation").text().set(translation.toUtf8().constData()); qobject_cast(parent())->setHasChanged(true); diff --git a/src/core/qtuidocument.cpp b/src/core/qtuidocument.cpp index 97d1bb2d..d159dfa6 100644 --- a/src/core/qtuidocument.cpp +++ b/src/core/qtuidocument.cpp @@ -44,7 +44,7 @@ QtUiDocument::~QtUiDocument() = default; */ QtUiWidget *QtUiDocument::findWidget(const QString &name) const { - LOG("QtUiDocument::findWidget", name); + LOG(FUNCTION, name); auto result = kdalgorithms::find_if(m_widgets, [name](QtUiWidget *widget) { return widget->name() == name; @@ -62,10 +62,10 @@ QtUiWidget *QtUiDocument::findWidget(const QString &name) const */ Core::QtUiWidget *QtUiDocument::addWidget(const QString &className, const QString &name, Core::QtUiWidget *parent) { - LOG("QtUiDocument::addWidget", className, name); + LOG(FUNCTION, className, name); if (m_widgets.empty() && parent) { - spdlog::error("QtUiDocument::addWidget - adding a widget to a non-root widget is not supported yet."); + spdlog::error("{}: adding a widget to a non-root widget is not supported yet.", FUNCTION); return nullptr; } @@ -92,7 +92,7 @@ Core::QtUiWidget *QtUiDocument::addWidget(const QString &className, const QStrin void QtUiDocument::addCustomWidget(const QString &className, const QString &baseClassName, const QString &header, bool isContainer) { - LOG("QtUiDocument::addCustomWidget", className, baseClassName, header, isContainer); + LOG(FUNCTION, className, baseClassName, header, isContainer); const auto result = uiWriter()->addCustomWidget(className, baseClassName, header, isContainer); @@ -101,12 +101,10 @@ void QtUiDocument::addCustomWidget(const QString &className, const QString &base setHasChanged(true); return; case Utils::QtUiWriter::AlreadyExists: - spdlog::info(R"(QtUiDocument::addCustomWidget - the custom widget '{}' already exists)", className); + spdlog::info(R"({}: the custom widget '{}' already exists)", FUNCTION, className); return; case Utils::QtUiWriter::InvalidHeader: - spdlog::error( - R"(QtUiDocument::addCustomWidget - the include '{}' is malformed, should be '' or '"foo.h"')", - header); + spdlog::error(R"({}: the include '{}' is malformed, should be '' or '"foo.h"')", FUNCTION, header); return; case Utils::QtUiWriter::InvalidProperty: Q_UNREACHABLE(); @@ -119,7 +117,7 @@ void QtUiDocument::addCustomWidget(const QString &className, const QString &base */ void QtUiDocument::preview() const { - LOG("QtUiDocument::preview"); + LOG(FUNCTION); QUiLoader loader; @@ -201,7 +199,7 @@ QString QtUiWidget::name() const void QtUiWidget::setName(const QString &newName) { - LOG("QtUiWidget::setName", newName); + LOG(FUNCTION, newName); if (newName == name()) return; @@ -218,7 +216,7 @@ QString QtUiWidget::className() const void QtUiWidget::setClassName(const QString &newClassName) { - LOG("QtUiWidget::setClassName", newClassName); + LOG(FUNCTION, newClassName); if (newClassName == className()) return; @@ -234,7 +232,7 @@ void QtUiWidget::setClassName(const QString &newClassName) */ QVariant QtUiWidget::getProperty(const QString &name) const { - LOG("QtUiWidget::getProperty", name); + LOG(FUNCTION, name); const QString propertyPath = "property[@name='" % name % "']/*[1]"; const auto dataNode = m_widget.select_node(propertyPath.toLatin1().constData()).node(); @@ -256,7 +254,7 @@ QVariant QtUiWidget::getProperty(const QString &name) const return dataNode.text().as_string(); } - spdlog::error(R"(QtUiWidget::property - unknown {} property)", name); + spdlog::error(R"({}: unknown {} property)", FUNCTION, name); return {}; } @@ -275,7 +273,7 @@ QVariant QtUiWidget::getProperty(const QString &name) const void QtUiWidget::addProperty(const QString &name, const QVariant &value, const QHash &attributes, bool userProperty) { - LOG("QtUiWidget::addProperty", name, value); + LOG(FUNCTION, name, value); const auto result = qobject_cast(parent())->uiWriter()->addWidgetProperty(m_widget, name, value, attributes, userProperty); @@ -285,7 +283,7 @@ void QtUiWidget::addProperty(const QString &name, const QVariant &value, const Q qobject_cast(parent())->setHasChanged(true); return; case Utils::QtUiWriter::InvalidProperty: - spdlog::error(R"(QtUiWidget::addProperty - unknown {} type)", value.typeName()); + spdlog::error(R"({}: unknown {} type)", FUNCTION, value.typeName()); return; case Utils::QtUiWriter::AlreadyExists: case Utils::QtUiWriter::InvalidHeader: diff --git a/src/core/querymatch.cpp b/src/core/querymatch.cpp index 382aa229..c38748db 100644 --- a/src/core/querymatch.cpp +++ b/src/core/querymatch.cpp @@ -223,7 +223,7 @@ Core::QueryMatchList QueryMatch::queryIn(const QString &capture, const QString & if (document) { result.append(document->queryInRange(range, query)); } else { - spdlog::warn("QueryMatch::queryIn: RangeMark is not backed by CodeDocument!"); + spdlog::warn("{}: RangeMark is not backed by CodeDocument!", FUNCTION); } } diff --git a/src/core/rangemark.cpp b/src/core/rangemark.cpp index 21056fbd..b4f41f02 100644 --- a/src/core/rangemark.cpp +++ b/src/core/rangemark.cpp @@ -66,7 +66,7 @@ RangeMarkPrivate::RangeMarkPrivate(TextDocument *editor, int start, int end) bool RangeMarkPrivate::checkEditor() const { if (!m_editor) { - spdlog::error("RangeMark::checkEditor - document does not exist anymore"); + spdlog::error("{}: document does not exist anymore", FUNCTION); return false; } return true; @@ -75,7 +75,7 @@ bool RangeMarkPrivate::checkEditor() const void RangeMarkPrivate::ensureInvariant() { if (m_start > m_end) { - spdlog::warn("RangeMark::ensureInvariant: invariant violated: m_start > m_end ({} > {})", m_start, m_end); + spdlog::warn("{}: invariant violated: m_start > m_end ({} > {})", FUNCTION, m_start, m_end); std::swap(m_start, m_end); } } @@ -199,15 +199,15 @@ RangeMark RangeMark::join(const RangeMark &other) const QString RangeMark::textExcept(const RangeMark &other) const { if (!isValid()) { - spdlog::error("RangeMark::textExcept: invalid range"); + spdlog::error("{}: invalid range", FUNCTION); return ""; } if (!other.isValid()) { - spdlog::debug("RangeMark::textExcept: invalid other range"); + spdlog::debug("{}: invalid other range", FUNCTION); return text(); } if (document() != other.document()) { - spdlog::error("RangeMark::textExcept: different documents"); + spdlog::error("{}: different documents", FUNCTION); return text(); } diff --git a/src/core/rcdocument.cpp b/src/core/rcdocument.cpp index 7ae62b30..028250e7 100644 --- a/src/core/rcdocument.cpp +++ b/src/core/rcdocument.cpp @@ -123,7 +123,7 @@ QList RcDocument::actions() const */ RcCore::Action RcDocument::action(const QString &id) const { - LOG("RcDocument::action", id); + LOG(FUNCTION, id); // Make sure the action vector is populated by calling actions if (isDataValid() && !actions().isEmpty()) { @@ -143,7 +143,7 @@ RcCore::Action RcDocument::action(const QString &id) const */ RcCore::ActionList RcDocument::actionsFromMenu(const QString &menuId) const { - LOG("RcDocument::actionsFromMenu", menuId); + LOG(FUNCTION, menuId); if (!isDataValid()) return {}; @@ -163,7 +163,7 @@ RcCore::ActionList RcDocument::actionsFromMenu(const QString &menuId) const */ RcCore::ActionList RcDocument::actionsFromToolbar(const QString &toolBarId) const { - LOG("RcDocument::actionsFromMenu", toolBarId); + LOG(FUNCTION, toolBarId); if (!isDataValid()) return {}; @@ -190,7 +190,7 @@ QList RcDocument::toolBars() const */ RcCore::ToolBar RcDocument::toolBar(const QString &id) const { - LOG("RcDocument::toolBar", id); + LOG(FUNCTION, id); if (isDataValid()) { if (auto tb = data().toolBar(id)) @@ -216,7 +216,7 @@ RcCore::ToolBar RcDocument::toolBar(const QString &id) const */ RcCore::Widget RcDocument::dialog(const QString &id, int flags, double scaleX, double scaleY) const { - LOG("RcDocument::dialog", id, flags, scaleX, scaleY); + LOG(FUNCTION, id, flags, scaleX, scaleY); SET_DEFAULT_VALUE(RcDialogFlags, static_cast(flags)); SET_DEFAULT_VALUE(RcDialogScaleX, scaleX); @@ -235,7 +235,7 @@ RcCore::Widget RcDocument::dialog(const QString &id, int flags, double scaleX, d */ RcCore::Menu RcDocument::menu(const QString &id) const { - LOG("RcDocument::menu", id); + LOG(FUNCTION, id); if (isDataValid()) { if (auto menu = data().menu(id)) @@ -250,7 +250,7 @@ RcCore::Menu RcDocument::menu(const QString &id) const */ RcCore::Ribbon RcDocument::ribbon(const QString &id) const { - LOG("RcDocument::ribbon", id); + LOG(FUNCTION, id); if (isDataValid()) { if (auto ribbon = data().ribbon(id)) { @@ -263,7 +263,7 @@ RcCore::Ribbon RcDocument::ribbon(const QString &id) const QStringList RcDocument::dialogIds() const { - LOG("RcDocument::dialogIds"); + LOG(FUNCTION); if (isDataValid()) { const auto &dialogs = data().dialogs; QStringList result; @@ -279,7 +279,7 @@ QStringList RcDocument::dialogIds() const QStringList RcDocument::menuIds() const { - LOG("RcDocument::menuIds"); + LOG(FUNCTION); if (isDataValid()) { const auto &menus = data().menus; QStringList result; @@ -295,7 +295,7 @@ QStringList RcDocument::menuIds() const QStringList RcDocument::acceleratorIds() const { - LOG("RcDocument::acceleratorIds"); + LOG(FUNCTION); if (isDataValid()) { const auto &accelerators = data().acceleratorTables; QStringList result; @@ -311,7 +311,7 @@ QStringList RcDocument::acceleratorIds() const QStringList RcDocument::toolbarIds() const { - LOG("RcDocument::toolbarIds"); + LOG(FUNCTION); if (isDataValid()) { const auto &toolbars = data().toolBars; QStringList result; @@ -327,7 +327,7 @@ QStringList RcDocument::toolbarIds() const QStringList RcDocument::stringIds() const { - LOG("RcDocument::stringIds"); + LOG(FUNCTION); if (isDataValid()) return data().strings.keys(); return {}; @@ -335,7 +335,7 @@ QStringList RcDocument::stringIds() const QStringList RcDocument::ribbonIds() const { - LOG("RcDocument::ribbonIds"); + LOG(FUNCTION); if (isDataValid()) { const auto &ribbons = data().ribbons; QStringList result; @@ -355,7 +355,7 @@ QStringList RcDocument::ribbonIds() const */ QList RcDocument::stringsForLanguage(const QString &language) const { - LOG("RcDocument::stringsForLanguage", language); + LOG(FUNCTION, language); if (m_rcFile.isValid && m_rcFile.data.contains(language)) { const RcCore::Data data = const_cast(&m_rcFile)->data[language]; const auto &strings = data.strings; @@ -371,14 +371,14 @@ QList RcDocument::stringsForLanguage(const QString &language) co */ QString RcDocument::stringForLanguage(const QString &language, const QString &id) const { - LOG("RcDocument::stringForLanguage", language, id); + LOG(FUNCTION, language, id); if (m_rcFile.isValid && m_rcFile.data.contains(language)) { const RcCore::Data data = const_cast(&m_rcFile)->data[language]; const auto &strings = data.strings; return strings.value(id).text; } else { - spdlog::warn("RcDocument::stringForLanguage: language {} does not exist in the rc file.", language); + spdlog::warn("{}: language {} does not exist in the rc file.", FUNCTION, language); return {}; } } @@ -398,7 +398,7 @@ QList RcDocument::strings() const */ QString RcDocument::string(const QString &id) const { - LOG("RcDocument::string", id); + LOG(FUNCTION, id); if (isDataValid()) return data().strings.value(id).text; @@ -422,13 +422,12 @@ QString extractStringForDialog(const RcCore::Data::Dialog *dialog, const QString if (dialog) { const auto control = findControlWithId(dialog, id); if (!control) { - spdlog::warn("RcDocument::stringForDialogAndLanguage: control from id {} does not exist in the rc file.", - id); + spdlog::warn("{}: control from id {} does not exist in the rc file.", FUNCTION, id); return {}; } return control.value().text; } else { - spdlog::warn("RcDocument::stringForDialogAndLanguage: id {} does not exist in the rc file.", id); + spdlog::warn("{}: id {} does not exist in the rc file.", FUNCTION, id); return {}; } } @@ -440,14 +439,14 @@ QString extractStringForDialog(const RcCore::Data::Dialog *dialog, const QString QString RcDocument::stringForDialogAndLanguage(const QString &language, const QString &dialogId, const QString &id) const { - LOG("RcDocument::stringForDialogAndLanguage", language, dialogId, id); + LOG(FUNCTION, language, dialogId, id); if (m_rcFile.isValid && m_rcFile.data.contains(language)) { const RcCore::Data data = const_cast(&m_rcFile)->data[language]; const auto dialog = data.dialog(dialogId); return extractStringForDialog(dialog, id); } else { - spdlog::warn("RcDocument::stringForDialogAndLanguage: language {} does not exist in the rc file.", language); + spdlog::warn("{}: language {} does not exist in the rc file.", FUNCTION, language); return {}; } } @@ -458,7 +457,7 @@ QString RcDocument::stringForDialogAndLanguage(const QString &language, const QS */ QString RcDocument::stringForDialog(const QString &dialogId, const QString &id) const { - LOG("RcDocument::stringForDialog", dialogId, id); + LOG(FUNCTION, dialogId, id); if (isDataValid()) { const auto dialog = data().dialog(dialogId); return extractStringForDialog(dialog, id); @@ -474,16 +473,16 @@ const RcCore::Data &RcDocument::data() const QString RcDocument::language() const { - LOG("RcDocument::language"); + LOG(FUNCTION); LOG_RETURN("language", m_language); } void RcDocument::setLanguage(const QString &language) { - LOG("RcDocument::setLanguage", language); + LOG(FUNCTION, language); if (!m_rcFile.data.contains(language)) { - spdlog::warn("RcDocument::setLanguage: language {} does not exist in the rc file.", language); + spdlog::warn("{}: language {} does not exist in the rc file.", FUNCTION, language); return; } @@ -499,7 +498,7 @@ void RcDocument::setLanguage(const QString &language) QStringList RcDocument::languages() const { - LOG("RcDocument::languages"); + LOG(FUNCTION); QStringList langs; if (m_rcFile.isValid) { @@ -535,7 +534,7 @@ QList RcDocument::menus() const */ void RcDocument::convertAssets(int flags) { - LOG("RcDocument::convertAssets", flags); + LOG(FUNCTION, flags); SET_DEFAULT_VALUE(RcAssetFlags, static_cast(flags)); if (isDataValid()) { @@ -558,7 +557,7 @@ void RcDocument::convertAssets(int flags) */ void RcDocument::convertActions(int flags) { - LOG("RcDocument::convertActions", flags); + LOG(FUNCTION, flags); SET_DEFAULT_VALUE(RcAssetFlags, static_cast(flags)); if (isDataValid()) { @@ -584,7 +583,7 @@ void RcDocument::convertActions(int flags) */ bool RcDocument::writeAssetsToImage(int flags) { - LOG("RcDocument::writeAssetsToImage", flags); + LOG(FUNCTION, flags); SET_DEFAULT_VALUE(RcAssetColors, static_cast(flags)); if (m_cacheAssets.isEmpty()) @@ -602,7 +601,7 @@ bool RcDocument::writeAssetsToImage(int flags) */ bool RcDocument::writeAssetsToQrc(const QString &fileName) { - LOG("RcDocument::writeAssetsToQrc", fileName); + LOG(FUNCTION, fileName); if (m_cacheAssets.isEmpty()) convertAssets(); @@ -622,7 +621,7 @@ bool RcDocument::writeAssetsToQrc(const QString &fileName) */ bool RcDocument::writeDialogToUi(const RcCore::Widget &dialog, const QString &fileName) { - LOG("RcDocument::writeDialogToUi", dialog.id, fileName); + LOG(FUNCTION, dialog.id, fileName); QFile file(fileName); if (file.open(QIODevice::WriteOnly)) { @@ -639,7 +638,7 @@ bool RcDocument::writeDialogToUi(const RcCore::Widget &dialog, const QString &fi */ void RcDocument::previewDialog(const RcCore::Widget &dialog) const { - LOG("RcDocument::previewDialog", dialog.id); + LOG(FUNCTION, dialog.id); QUiLoader loader; @@ -662,7 +661,7 @@ void RcDocument::previewDialog(const RcCore::Widget &dialog) const */ void RcDocument::mergeAllLanguages(const QString &language) { - LOG("RcDocument::mergeAllLanguages", language); + LOG(FUNCTION, language); m_rcFile.mergeLanguages(m_rcFile.data.keys(), language); { @@ -684,7 +683,7 @@ void RcDocument::mergeAllLanguages(const QString &language) */ void RcDocument::mergeLanguages() { - LOG("RcDocument::mergeLanguages"); + LOG(FUNCTION); const auto languageMap = Settings::instance()->value>(Settings::RcLanguageMap); @@ -723,7 +722,7 @@ void RcDocument::mergeLanguages() */ QString RcDocument::convertLanguageToCode(const QString &language) { - LOG("RcDocument::convertLanguageToCode", language); + LOG(FUNCTION, language); if (language == DefaultLanguage) { return {}; } diff --git a/src/core/scriptdialogitem.cpp b/src/core/scriptdialogitem.cpp index ee68c2ab..d4c92e78 100644 --- a/src/core/scriptdialogitem.cpp +++ b/src/core/scriptdialogitem.cpp @@ -171,7 +171,7 @@ void ScriptDialogItem::initialize(nlohmann::json &&jsonData) } else if (it.value().is_number_float()) { value = it.value().get(); } else { - spdlog::error("Unsupported data type for key '{}'", it.key()); + spdlog::error("{}: Unsupported data type for key '{}'", FUNCTION, it.key()); value = QString::fromStdString(it.value().dump()); } @@ -292,7 +292,7 @@ void ScriptDialogItem::continueScript() void ScriptDialogItem::abortScript() { - spdlog::info("Script aborted."); + spdlog::info("{}: Script aborted.", FUNCTION); finishScript(); } @@ -311,7 +311,7 @@ void ScriptDialogItem::runNextStep() const auto done = result.property("done").toBool(); m_nextStepTitle = result.property("value").toString(); - spdlog::info("{} done.", m_currentStepTitle); + spdlog::info("{}: {} done.", FUNCTION, m_currentStepTitle); if (done) { finishScript(); @@ -497,7 +497,7 @@ void ScriptDialogItem::setUiFile(const QString &fileName) setWindowTitle(internalWidget->windowTitle()); createProperties(internalWidget); } else { - spdlog::error("Can't open {}", fileName); + spdlog::error("{}: Can't open {}", FUNCTION, fileName); } } @@ -638,9 +638,9 @@ void ScriptDialogItem::changeValue(const QString &key, const QVariant &value) } if (!widget) { - spdlog::warn("No widget found for the key '{}'.", key.toStdString()); + spdlog::warn("{}: No widget found for the key '{}'.", FUNCTION, key.toStdString()); } else { - spdlog::warn("Unsupported widget type '{}' for the key '{}'.", widget->metaObject()->className(), + spdlog::warn("{}: Unsupported widget type '{}' for the key '{}'.", FUNCTION, widget->metaObject()->className(), key.toStdString()); } } diff --git a/src/core/scriptdialogitem_p.cpp b/src/core/scriptdialogitem_p.cpp index 0011d467..0c410436 100644 --- a/src/core/scriptdialogitem_p.cpp +++ b/src/core/scriptdialogitem_p.cpp @@ -73,7 +73,7 @@ int DynamicObject::qt_metacall(QMetaObject::Call call, int id, void **argv) if (m_dataChangedCallback) m_dataChangedCallback(property.name, property.variant); } else { - spdlog::warn("DynamicObject::qt_metacall: id {} not handled.", id); + spdlog::warn("{}: id {} not handled.", FUNCTION, id); } return -1; diff --git a/src/core/scriptmanager.cpp b/src/core/scriptmanager.cpp index cc0b0268..eedba51f 100644 --- a/src/core/scriptmanager.cpp +++ b/src/core/scriptmanager.cpp @@ -208,7 +208,7 @@ void ScriptManager::doRunScript(const QString &fileName, nlohmann::json &&data, spdlog::error("{}({}): {}", error.url().toLocalFile(), error.line(), error.description()); } else { if (m_result.isValid()) - spdlog::info("Script result is {}", m_result.toString()); + spdlog::info("{}: Script result is {}", FUNCTION, m_result.toString()); } } diff --git a/src/core/scriptmodel.cpp b/src/core/scriptmodel.cpp index fb866407..48fb0a07 100644 --- a/src/core/scriptmodel.cpp +++ b/src/core/scriptmodel.cpp @@ -71,7 +71,7 @@ QVariant ScriptModel::columnHeaderDisplayData(int column) const case DescriptionColumn: return tr("Description"); default: - spdlog::error("SuggestedScripts::columnHeaderDisplayData: column out of range: {}", column); + spdlog::error("{}: Suggested Scripts - column out of range: {}", FUNCTION, column); return {}; } } @@ -95,7 +95,7 @@ QVariant ScriptModel::data(const QModelIndex &index, int role) const const auto &scripts = scriptList(); if (row < 0 || static_cast(row) >= scripts.size()) { - spdlog::error("SuggestedScripts::data: row out of range: {}", row); + spdlog::error("{}: Suggested Scripts - row out of range: {}", FUNCTION, row); return {}; } @@ -120,7 +120,7 @@ QVariant ScriptModel::displayData(const ScriptManager::Script &script, int colum case DescriptionColumn: return script.description; default: - spdlog::error("SuggestedScripts::displayData: column out of range: {}", column); + spdlog::error("{}: Suggested Scripts - column out of range: {}", FUNCTION, column); return {}; } } diff --git a/src/core/scriptrunner.cpp b/src/core/scriptrunner.cpp index f0370a01..5dcee371 100644 --- a/src/core/scriptrunner.cpp +++ b/src/core/scriptrunner.cpp @@ -196,7 +196,7 @@ QVariant ScriptRunner::runScript(const QString &fileName, nlohmann::json &&data, } // engine is deleted in runJavascript or runQml } else { - spdlog::error("File {} doesn't exist", fileName); + spdlog::error("{}: File {} doesn't exist", FUNCTION, fileName); return QVariant(ErrorCode); } diff --git a/src/core/settings.cpp b/src/core/settings.cpp index ef12560b..5ea0b8ea 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -121,7 +121,7 @@ void Settings::loadProjectSettings(const QString &rootDir) */ bool Settings::hasValue(QString path) const { - LOG("Settings::hasValue", path); + LOG(FUNCTION, path); if (!path.startsWith('/')) path.prepend('/'); @@ -135,9 +135,10 @@ bool Settings::hasValue(QString path) const QVariant Settings::value(QString path, const QVariant &defaultValue) const { if (defaultValue.isValid()) - LOG("Settings::value", path, defaultValue); + LOG(FUNCTION, path, defaultValue); else - LOG("Settings::value", path); + LOG(FUNCTION, path); + ; try { if (!path.startsWith('/')) path.prepend('/'); @@ -167,9 +168,9 @@ QVariant Settings::value(QString path, const QVariant &defaultValue) const return QStringList(); } } - spdlog::error("Settings::value {} - can't convert", path); + spdlog::error("{}: {} - cannot convert", FUNCTION, path); } catch (...) { - spdlog::info("Settings::value {} - accessing non-existing value", path); + spdlog::info("{}: {} - accessing non-existing value", FUNCTION, path); } return defaultValue; } @@ -180,10 +181,10 @@ QVariant Settings::value(QString path, const QVariant &defaultValue) const */ bool Settings::setValue(QString path, const QJSValue &value) { - LOG("Settings::setValue", path, value); + LOG(FUNCTION, path, value); if (value.isNull()) { - spdlog::error("Settings::setValue {} in {} - value is null", value.toString(), path); + spdlog::error("{}: {} in {} - value is null", FUNCTION, value.toString(), path); return false; } @@ -228,11 +229,11 @@ bool Settings::setValue(QString path, const QJSValue &value) m_settings[jsonPath] = list; m_projectSettings[jsonPath] = list; } else { - spdlog::error("Settings::setValue {} in {} - only string lists are supported", value.toString(), path); + spdlog::error("{}: {} in {} - only string lists are supported", FUNCTION, value.toString(), path); } } break; default: - spdlog::error("Settings::setValue {} in {} - value type not handled", value.toString(), path); + spdlog::error("{}: {} in {} - value type not handled", FUNCTION, value.toString(), path); return false; } @@ -289,7 +290,7 @@ void Settings::saveSettings() QFile file(filePath); if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - spdlog::error("Settings::saveSettings {}", filePath); + spdlog::error("{}: {}", FUNCTION, filePath); return; } diff --git a/src/core/symbol.cpp b/src/core/symbol.cpp index 29dcc6c8..283b8b23 100644 --- a/src/core/symbol.cpp +++ b/src/core/symbol.cpp @@ -138,12 +138,12 @@ bool Symbol::isClass() const ClassSymbol *Symbol::toClass() { - LOG("Symbol::toClass"); + LOG(FUNCTION); auto clazz = qobject_cast(this); if (!clazz) - spdlog::warn("Symbol::toClass - {} should be a `Class`.", m_name); + spdlog::warn("{}: {} should be a `Class`.", FUNCTION, m_name); return clazz; } @@ -164,7 +164,7 @@ FunctionSymbol *Symbol::toFunction() auto function = qobject_cast(this); if (!function) - spdlog::warn("Symbol::toFunction - {} should be either a method or a function.", m_name); + spdlog::warn("{}: {} should be either a method or a function.", FUNCTION, m_name); return function; } @@ -196,7 +196,7 @@ Core::RangeMark Symbol::selectionRange() const RangeMarkList Symbol::references() const { - LOG("Symbol::references"); + LOG(FUNCTION); if (const auto codedocument = document()) { auto references = codedocument->references(selectionRange().start()); diff --git a/src/core/textdocument.cpp b/src/core/textdocument.cpp index ec3ad4da..bd939abe 100644 --- a/src/core/textdocument.cpp +++ b/src/core/textdocument.cpp @@ -243,7 +243,7 @@ bool TextDocument::doSave(const QString &fileName) QFile file(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { setErrorString(file.errorString()); - spdlog::error("Can't save file {}: {}", fileName, errorString()); + spdlog::error("{} - Can't save file {}: {}", FUNCTION, fileName, errorString()); return false; } @@ -266,7 +266,7 @@ bool TextDocument::doLoad(const QString &fileName) QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { setErrorString(file.errorString()); - spdlog::warn("Can't load file {}: {}", fileName, errorString()); + spdlog::warn("{} - Can't load file {}: {}", FUNCTION, fileName, errorString()); return false; } @@ -306,45 +306,45 @@ void TextDocument::detectFormat(const QByteArray &data) int TextDocument::column() const { - LOG("TextDocument::column"); + LOG(FUNCTION); const QTextCursor cursor = m_document->textCursor(); LOG_RETURN("column", cursor.positionInBlock() + 1); } int TextDocument::line() const { - LOG("TextDocument::line"); + LOG(FUNCTION); const QTextCursor cursor = m_document->textCursor(); LOG_RETURN("line", cursor.blockNumber() + 1); } int TextDocument::lineCount() const { - LOG("TextDocument::lineCount"); + LOG(FUNCTION); return m_document->document()->lineCount(); } int TextDocument::position() const { - LOG("TextDocument::position"); + LOG(FUNCTION); LOG_RETURN("pos", m_document->textCursor().position()); } int TextDocument::selectionStart() const { - LOG("TextDocument::selectionStart"); + LOG(FUNCTION); LOG_RETURN("pos", m_document->textCursor().selectionStart()); } int TextDocument::selectionEnd() const { - LOG("TextDocument::selectionEnd"); + LOG(FUNCTION); LOG_RETURN("pos", m_document->textCursor().selectionEnd()); } void TextDocument::setPosition(int newPosition) { - LOG("TextDocument::position", LOG_ARG("pos", newPosition)); + LOG(FUNCTION, LOG_ARG("pos", newPosition)); if (position() == newPosition) return; @@ -388,7 +388,7 @@ int TextDocument::position(QTextCursor::MoveOperation operation, int pos) const */ int TextDocument::lineAtPosition(int position) { - LOG("TextDocument::lineAtPosition", LOG_ARG("position", position)); + LOG(FUNCTION, LOG_ARG("position", position)); int line = -1; int col = -1; convertPosition(position, &line, &col); @@ -401,7 +401,7 @@ int TextDocument::lineAtPosition(int position) */ int TextDocument::columnAtPosition(int position) { - LOG("TextDocument::columnAtPosition", LOG_ARG("position", position)); + LOG(FUNCTION, LOG_ARG("position", position)); int line = -1; int col = -1; convertPosition(position, &line, &col); @@ -414,7 +414,7 @@ int TextDocument::columnAtPosition(int position) */ int TextDocument::positionAt(int line, int column) { - LOG("TextDocument::positionAt", LOG_ARG("line", line), LOG_ARG("column", column)); + LOG(FUNCTION, LOG_ARG("line", line), LOG_ARG("column", column)); const QTextBlock block = m_document->document()->findBlockByLineNumber(line - 1); if (!block.isValid()) { return -1; @@ -425,20 +425,20 @@ int TextDocument::positionAt(int line, int column) QString TextDocument::text() const { - LOG("TextDocument::text"); + LOG(FUNCTION); LOG_RETURN("text", m_document->toPlainText()); } void TextDocument::setText(const QString &newText) { - LOG("TextDocument::text", LOG_ARG("text", newText)); + LOG(FUNCTION, LOG_ARG("text", newText)); m_document->setPlainText(newText); } QString TextDocument::currentLine() const { - LOG("TextDocument::currentLine"); + LOG(FUNCTION); QTextCursor cursor = m_document->textCursor(); cursor.movePosition(QTextCursor::StartOfLine); cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor); @@ -447,7 +447,7 @@ QString TextDocument::currentLine() const QString TextDocument::currentWord() const { - LOG("TextDocument::currentWord"); + LOG(FUNCTION); QTextCursor cursor = m_document->textCursor(); cursor.movePosition(QTextCursor::StartOfWord); cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); @@ -456,7 +456,7 @@ QString TextDocument::currentWord() const QString TextDocument::selectedText() const { - LOG("TextDocument::selectedText"); + LOG(FUNCTION); // Replace \u2029 with \n const QString text = m_document->textCursor().selectedText().replace(QChar(8233), "\n"); LOG_RETURN("text", text); @@ -529,7 +529,7 @@ void TextDocument::movePosition(QTextCursor::MoveOperation operation, QTextCurso */ void TextDocument::gotoLine(int line, int column) { - LOG("TextDocument::gotoLine", LOG_ARG("line", line), LOG_ARG("column", column)); + LOG(FUNCTION, LOG_ARG("line", line), LOG_ARG("column", column)); gotoLineInTextEdit(m_document, line, column); } @@ -555,7 +555,7 @@ void gotoLineInTextEdit(QPlainTextEdit *textEdit, int line, int column) */ void TextDocument::gotoStartOfLine() { - LOG("TextDocument::gotoStartOfLine"); + LOG(FUNCTION); movePosition(QTextCursor::StartOfLine); } @@ -565,7 +565,7 @@ void TextDocument::gotoStartOfLine() */ void TextDocument::gotoEndOfLine() { - LOG("TextDocument::gotoEndOfLine"); + LOG(FUNCTION); movePosition(QTextCursor::EndOfLine); } @@ -575,7 +575,7 @@ void TextDocument::gotoEndOfLine() */ void TextDocument::gotoStartOfWord() { - LOG("TextDocument::gotoStartOfWord"); + LOG(FUNCTION); movePosition(QTextCursor::StartOfWord); } @@ -585,7 +585,7 @@ void TextDocument::gotoStartOfWord() */ void TextDocument::gotoEndOfWord() { - LOG("TextDocument::gotoEndOfWord"); + LOG(FUNCTION); movePosition(QTextCursor::EndOfWord); } @@ -655,7 +655,7 @@ void TextDocument::gotoNextWord(int count) */ void TextDocument::gotoStartOfDocument() { - LOG("TextDocument::gotoStartOfDocument"); + LOG(FUNCTION); movePosition(QTextCursor::Start); } @@ -665,7 +665,7 @@ void TextDocument::gotoStartOfDocument() */ void TextDocument::gotoEndOfDocument() { - LOG("TextDocument::gotoEndOfDocument"); + LOG(FUNCTION); movePosition(QTextCursor::End); } @@ -675,7 +675,7 @@ void TextDocument::gotoEndOfDocument() */ void TextDocument::unselect() { - LOG("TextDocument::unselect"); + LOG(FUNCTION); QTextCursor cursor = m_document->textCursor(); cursor.clearSelection(); m_document->setTextCursor(cursor); @@ -687,7 +687,7 @@ void TextDocument::unselect() */ bool TextDocument::hasSelection() { - LOG("TextDocument::hasSelection"); + LOG(FUNCTION); return m_document->textCursor().hasSelection(); } @@ -697,7 +697,7 @@ bool TextDocument::hasSelection() */ void TextDocument::selectAll() { - LOG("TextDocument::selectAll"); + LOG(FUNCTION); m_document->selectAll(); } @@ -707,7 +707,7 @@ void TextDocument::selectAll() */ void TextDocument::selectTo(int pos) { - LOG("TextDocument::selectTo", LOG_ARG("pos", pos)); + LOG(FUNCTION, LOG_ARG("pos", pos)); QTextCursor cursor = m_document->textCursor(); cursor.setPosition(pos, QTextCursor::KeepAnchor); m_document->setTextCursor(cursor); @@ -719,7 +719,7 @@ void TextDocument::selectTo(int pos) */ void TextDocument::selectStartOfLine() { - LOG("TextDocument::selectStartOfLine"); + LOG(FUNCTION); movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor); } @@ -729,7 +729,7 @@ void TextDocument::selectStartOfLine() */ void TextDocument::selectEndOfLine() { - LOG("TextDocument::selectEndOfLine"); + LOG(FUNCTION); movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor); } @@ -739,7 +739,7 @@ void TextDocument::selectEndOfLine() */ void TextDocument::selectStartOfWord() { - LOG("TextDocument::selectStartOfWord"); + LOG(FUNCTION); movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor); } @@ -749,7 +749,7 @@ void TextDocument::selectStartOfWord() */ void TextDocument::selectEndOfWord() { - LOG("TextDocument::selectEndOfWord"); + LOG(FUNCTION); movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); } @@ -819,7 +819,7 @@ void TextDocument::selectNextWord(int count) */ void TextDocument::selectRegion(int from, int to) { - LOG("TextDocument::selectRegion", from, to); + LOG(FUNCTION, from, to); QTextCursor cursor(m_document->document()); cursor.setPosition(from, QTextCursor::MoveAnchor); cursor.setPosition(to, QTextCursor::KeepAnchor); @@ -832,7 +832,7 @@ void TextDocument::selectRegion(int from, int to) */ void TextDocument::selectRange(const RangeMark &range) { - LOG("TextDocument::selectRange", range); + LOG(FUNCTION, range); selectRegion(range.start(), range.end()); } @@ -842,7 +842,7 @@ void TextDocument::selectRange(const RangeMark &range) */ void TextDocument::copy() { - LOG("TextDocument::copy"); + LOG(FUNCTION); m_document->copy(); } @@ -852,7 +852,7 @@ void TextDocument::copy() */ void TextDocument::paste() { - LOG("TextDocument::paste"); + LOG(FUNCTION); m_document->paste(); } @@ -862,7 +862,7 @@ void TextDocument::paste() */ void TextDocument::cut() { - LOG("TextDocument::cut"); + LOG(FUNCTION); m_document->cut(); } @@ -872,7 +872,7 @@ void TextDocument::cut() */ void TextDocument::remove(int length) { - LOG("TextDocument::remove", length); + LOG(FUNCTION, length); QTextCursor cursor = m_document->textCursor(); cursor.setPosition(cursor.position() + length, QTextCursor::KeepAnchor); cursor.removeSelectedText(); @@ -896,9 +896,9 @@ void TextDocument::insert(const QString &text) void TextDocument::insertAtLine(const QString &text, int line) { if (line == -1) - LOG("TextDocument::insertAtLine", LOG_ARG("text", text)); + LOG(FUNCTION, LOG_ARG("text", text)); else - LOG("TextDocument::insertAtLine", LOG_ARG("text", text), LOG_ARG("line", line)); + LOG(FUNCTION, LOG_ARG("text", text), LOG_ARG("line", line)); QTextCursor cursor = m_document->textCursor(); if (line > 0) { @@ -916,7 +916,7 @@ void TextDocument::insertAtLine(const QString &text, int line) */ void TextDocument::insertAtPosition(const QString &text, int pos) { - LOG("TextDocument::insertAtPosition", text, pos); + LOG(FUNCTION, text, pos); QTextCursor cursor = m_document->textCursor(); cursor.setPosition(pos); cursor.beginEditBlock(); @@ -931,7 +931,7 @@ void TextDocument::insertAtPosition(const QString &text, int pos) */ void TextDocument::replace(int length, const QString &text) { - LOG("TextDocument::replace", length, text); + LOG(FUNCTION, length, text); QTextCursor cursor = m_document->textCursor(); cursor.setPosition(cursor.position() + length, QTextCursor::KeepAnchor); cursor.insertText(text); @@ -944,7 +944,7 @@ void TextDocument::replace(int length, const QString &text) */ void TextDocument::replace(int from, int to, const QString &text) { - LOG("TextDocument::replace", from, to, text); + LOG(FUNCTION, from, to, text); QTextCursor cursor(m_document->document()); cursor.setPosition(from); cursor.setPosition(to, QTextCursor::KeepAnchor); @@ -958,7 +958,7 @@ void TextDocument::replace(int from, int to, const QString &text) */ void TextDocument::replace(const RangeMark &range, const QString &text) { - LOG("TextDocument::replace", range, text); + LOG(FUNCTION, range, text); replace(range.start(), range.end(), text); } @@ -969,9 +969,9 @@ void TextDocument::replace(const RangeMark &range, const QString &text) void TextDocument::deleteLine(int line) { if (line == -1) - LOG("TextDocument::deleteLine"); + LOG(FUNCTION); else - LOG("TextDocument::deleteLine", LOG_ARG("line", line)); + LOG(FUNCTION, LOG_ARG("line", line)); QTextCursor cursor = m_document->textCursor(); if (line > 0) { @@ -992,7 +992,7 @@ void TextDocument::deleteLine(int line) */ void TextDocument::deleteSelection() { - LOG("TextDocument::deleteSelection"); + LOG(FUNCTION); m_document->textCursor().removeSelectedText(); } @@ -1002,7 +1002,7 @@ void TextDocument::deleteSelection() */ void TextDocument::deleteRegion(int from, int to) { - LOG("TextDocument::deleteRegion", from, to); + LOG(FUNCTION, from, to); QTextCursor cursor(m_document->document()); cursor.setPosition(from); cursor.setPosition(to, QTextCursor::KeepAnchor); @@ -1016,7 +1016,7 @@ void TextDocument::deleteRegion(int from, int to) */ void TextDocument::deleteRange(const RangeMark &range) { - LOG("TextDocument::deleteRange", range); + LOG(FUNCTION, range); QTextCursor cursor(m_document->document()); cursor.setPosition(range.start(), QTextCursor::MoveAnchor); cursor.setPosition(range.end(), QTextCursor::KeepAnchor); @@ -1030,7 +1030,7 @@ void TextDocument::deleteRange(const RangeMark &range) */ void TextDocument::deleteEndOfLine() { - LOG("TextDocument::deleteEndOfLine"); + LOG(FUNCTION); QTextCursor cursor = m_document->textCursor(); cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor); cursor.removeSelectedText(); @@ -1043,7 +1043,7 @@ void TextDocument::deleteEndOfLine() */ void TextDocument::deleteStartOfLine() { - LOG("TextDocument::deleteStartOfLine"); + LOG(FUNCTION); QTextCursor cursor = m_document->textCursor(); cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor); cursor.removeSelectedText(); @@ -1056,7 +1056,7 @@ void TextDocument::deleteStartOfLine() */ void TextDocument::deleteEndOfWord() { - LOG("TextDocument::deleteEndOfWord"); + LOG(FUNCTION); QTextCursor cursor = m_document->textCursor(); if (!cursor.hasSelection()) cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); @@ -1070,7 +1070,7 @@ void TextDocument::deleteEndOfWord() */ void TextDocument::deleteStartOfWord() { - LOG("TextDocument::deleteStartOfWord"); + LOG(FUNCTION); QTextCursor cursor = m_document->textCursor(); if (!cursor.hasSelection()) cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor); @@ -1112,7 +1112,7 @@ void TextDocument::deleteNextCharacter(int count) */ Mark TextDocument::createMark(int pos) { - LOG("TextDocument::createMark", LOG_ARG("pos", pos)); + LOG(FUNCTION, LOG_ARG("pos", pos)); if (pos < 0) pos = position(); LOG_RETURN("mark", Mark(this, pos)); @@ -1124,9 +1124,9 @@ Mark TextDocument::createMark(int pos) */ void TextDocument::gotoMark(const Mark &mark) { - LOG("TextDocument::gotoMark", LOG_ARG("mark", mark)); + LOG(FUNCTION, LOG_ARG("mark", mark)); if (mark.document() != this) { - spdlog::error("Can't use a mark from another editor."); + spdlog::error("{}: Can't use a mark from another editor.", FUNCTION); return; } @@ -1141,9 +1141,9 @@ void TextDocument::gotoMark(const Mark &mark) */ void TextDocument::selectToMark(const Mark &mark) { - LOG("TextDocument::selectToMark", LOG_ARG("mark", mark)); + LOG(FUNCTION, LOG_ARG("mark", mark)); if (mark.document() != this) { - spdlog::error("Can't use a mark from another editor."); + spdlog::error("{}: Can't use a mark from another editor.", FUNCTION); return; } @@ -1160,7 +1160,7 @@ void TextDocument::selectToMark(const Mark &mark) */ Core::RangeMark TextDocument::createRangeMark(int from, int to) { - LOG("TextDocument::createRangeMark", LOG_ARG("start", from), LOG_ARG("end", to)); + LOG(FUNCTION, LOG_ARG("start", from), LOG_ARG("end", to)); LOG_RETURN("rangeMark", Core::RangeMark(this, from, to)); } @@ -1174,13 +1174,13 @@ Core::RangeMark TextDocument::createRangeMark(int from, int to) */ Core::RangeMark TextDocument::createRangeMark() { - LOG("TextDocument::createRangeMark"); + LOG(FUNCTION); const auto cursor = m_document->textCursor(); const int start = cursor.selectionStart(); const int end = cursor.selectionEnd(); if (start == end) - spdlog::warn("TextDocument::createRangeMark: Creating a range mark with an empty range."); + spdlog::warn("{}: Creating a range mark with an empty range.", FUNCTION); LOG_RETURN("rangeMark", createRangeMark(start, end)); } @@ -1194,10 +1194,10 @@ Core::RangeMark TextDocument::createRangeMark() */ void TextDocument::selectRangeMark(const Core::RangeMark &mark) { - LOG("TextDocument::selectRangeMark", LOG_ARG("mark", mark)); + LOG(FUNCTION, LOG_ARG("mark", mark)); if (mark.document() != this) { - spdlog::error("Can't use a range mark from another editor."); + spdlog::error("{}: Can't use a range mark from another editor.", FUNCTION); return; } @@ -1217,7 +1217,7 @@ void TextDocument::selectRangeMark(const Core::RangeMark &mark) */ bool TextDocument::find(const QString &text, int options) { - LOG("TextDocument::find", LOG_ARG("text", text), options); + LOG(FUNCTION, LOG_ARG("text", text), options); if (options & FindRegexp) return findRegexp(text, options); else if (options & FindWholeWords) @@ -1238,7 +1238,7 @@ bool TextDocument::find(const QString &text, int options) */ bool TextDocument::findRegexp(const QString ®exp, int options) { - LOG("TextDocument::findRegexp", LOG_ARG("text", regexp), options); + LOG(FUNCTION, LOG_ARG("text", regexp), options); const auto found = selectRegexpMatch(regexp, options); return found.has_value(); @@ -1307,7 +1307,7 @@ auto TextDocument::selectRegexpMatch( */ QString TextDocument::match(const QString ®exp, int options) { - LOG("TextDocument::match", regexp, options); + LOG(FUNCTION, regexp, options); QString captureGroup; const auto result = selectRegexpMatch( @@ -1347,7 +1347,7 @@ QString TextDocument::match(const QString ®exp, int options) */ bool TextDocument::replaceOne(const QString &before, const QString &after, int options) { - LOG("TextDocument::replaceOne", LOG_ARG("text", before), after, options); + LOG(FUNCTION, LOG_ARG("text", before), after, options); auto cursor = m_document->textCursor(); cursor.movePosition(QTextCursor::Start); @@ -1399,7 +1399,7 @@ bool TextDocument::replaceOne(const QString &before, const QString &after, int o */ int TextDocument::replaceAll(const QString &before, const QString &after, int options /* = NoFindFlags */) { - LOG("TextDocument::replaceAll", LOG_ARG("text", before), after, options); + LOG(FUNCTION, LOG_ARG("text", before), after, options); return replaceAll(before, after, options, [](auto) { return true; }); @@ -1417,13 +1417,13 @@ int TextDocument::replaceAll(const QString &before, const QString &after, int op int TextDocument::replaceAllInRange(const QString &before, const QString &after, const Core::RangeMark &range, int options) { - LOG("TextDocument::replaceAllInRange", LOG_ARG("text", before), after, range, options); + LOG(FUNCTION, LOG_ARG("text", before), after, range, options); if (!range.isValid()) { - spdlog::warn("TextDocument::replaceAllInRange: Invalid range!"); + spdlog::warn("{}: Invalid range!", FUNCTION); return 0; } if (range.document() != this) { - spdlog::warn("TextDocument::replaceAllInRange: Range is not from this document!"); + spdlog::warn("{}: Range is not from this document!", FUNCTION); return 0; } @@ -1481,7 +1481,7 @@ int TextDocument::replaceAll(const QString &before, const QString &after, int op */ int TextDocument::replaceAllRegexp(const QString ®exp, const QString &after, int options /* = NoFindFlags */) { - LOG("TextDocument::replaceAllRegexp", LOG_ARG("text", regexp), after, options); + LOG(FUNCTION, LOG_ARG("text", regexp), after, options); return replaceAllRegexp(regexp, after, options, [](auto) { return true; }); @@ -1500,13 +1500,13 @@ int TextDocument::replaceAllRegexp(const QString ®exp, const QString &after, int TextDocument::replaceAllRegexpInRange(const QString ®exp, const QString &after, const RangeMark &range, int options /* = NoFindFlags*/) { - LOG("TextDocument::replaceAllRegexpInRange", LOG_ARG("text", regexp), after, range, options); + LOG(FUNCTION, LOG_ARG("text", regexp), after, range, options); if (!range.isValid()) { - spdlog::warn("TextDocument::replaceAllRegexpInRange: Invalid range!"); + spdlog::warn("{}: Invalid range!", FUNCTION); return 0; } if (range.document() != this) { - spdlog::warn("TextDocument::replaceAllRegexpInRange: Range is not from this document!"); + spdlog::warn("{}: Range is not from this document!", FUNCTION); return 0; } @@ -1635,7 +1635,7 @@ void TextDocument::removeIndent(int count) void TextDocument::setLineEnding(LineEnding newLineEnding) { - LOG("TextDocument::setLineEnding", newLineEnding); + LOG(FUNCTION, newLineEnding); if (m_lineEnding == newLineEnding) return; setHasChanged(true); @@ -1649,7 +1649,7 @@ void TextDocument::setLineEnding(LineEnding newLineEnding) */ QString TextDocument::indentationAtPosition(int pos) { - LOG("TextDocument::indentationAtPosition", pos); + LOG(FUNCTION, pos); auto cursor = m_document->textCursor(); cursor.setPosition(pos); cursor.movePosition(QTextCursor::StartOfLine); diff --git a/src/core/userdialog.cpp b/src/core/userdialog.cpp index b19a29e7..6df810eb 100644 --- a/src/core/userdialog.cpp +++ b/src/core/userdialog.cpp @@ -50,10 +50,10 @@ UserDialog::UserDialog(QQmlEngine *parent) */ QJSValue UserDialog::getOpenFileName(const QString &caption, const QString &dir, const QString &filters) { - LOG("UserDialog::getOpenFileName", caption, dir, filters); + LOG(FUNCTION, caption, dir, filters); const QString s = QFileDialog::getOpenFileName(dialogParent(), caption, dir, filters); if (!s.isEmpty()) { - spdlog::debug("UserDialog::getOpenFileName returns {}", s); + spdlog::debug("{} returns {}", FUNCTION, s); return s; } return QJSValue(QJSValue::NullValue); @@ -68,10 +68,10 @@ QJSValue UserDialog::getOpenFileName(const QString &caption, const QString &dir, */ QJSValue UserDialog::getSaveFileName(const QString &caption, const QString &dir, const QString &filters) { - LOG("UserDialog::getSaveFileName", caption, dir, filters); + LOG(FUNCTION, caption, dir, filters); const QString s = QFileDialog::getSaveFileName(dialogParent(), caption, dir, filters); if (!s.isEmpty()) { - spdlog::debug("UserDialog::getSaveFileName returns {}", s); + spdlog::debug("{} returns {}", FUNCTION, s); return s; } return QJSValue(QJSValue::NullValue); @@ -85,10 +85,10 @@ QJSValue UserDialog::getSaveFileName(const QString &caption, const QString &dir, */ QJSValue UserDialog::getExistingDirectory(const QString &caption, const QString &dir) { - LOG("UserDialog::getExistingDirectory", caption, dir); + LOG(FUNCTION, caption, dir); const QString s = QFileDialog::getExistingDirectory(dialogParent(), caption, dir); if (!s.isEmpty()) { - spdlog::debug("UserDialog::getExistingDirectory returns {}", s); + spdlog::debug("{} returns {}", FUNCTION, s); return s; } return QJSValue(QJSValue::NullValue); @@ -107,11 +107,11 @@ QJSValue UserDialog::getExistingDirectory(const QString &caption, const QString QJSValue UserDialog::getItem(const QString &title, const QString &label, const QStringList &items, int current, bool editable) { - LOG("UserDialog::getItem", title, label, items, current, editable); + LOG(FUNCTION, title, label, items, current, editable); bool ok; const QString ret = QInputDialog::getItem(dialogParent(), title, label, items, current, editable, &ok); if (ok) { - spdlog::debug("UserDialog::getItem returns {}", ret); + spdlog::debug("{} returns {}", FUNCTION, ret); return ret; } return QJSValue(QJSValue::NullValue); @@ -131,12 +131,12 @@ QJSValue UserDialog::getItem(const QString &title, const QString &label, const Q QJSValue UserDialog::getDouble(const QString &title, const QString &label, double value, int decimals, double step, double min, double max) { - LOG("UserDialog::getDouble", title, label, value, decimals, step, min, max); + LOG(FUNCTION, title, label, value, decimals, step, min, max); bool ok; const double ret = QInputDialog::getDouble(dialogParent(), title, label, value, min, max, decimals, &ok, Qt::WindowFlags(), step); if (ok) { - spdlog::debug("UserDialog::getDouble returns {}", ret); + spdlog::debug("{} returns {}", FUNCTION, ret); return ret; } return QJSValue(QJSValue::NullValue); @@ -154,11 +154,11 @@ QJSValue UserDialog::getDouble(const QString &title, const QString &label, doubl // clang-format on QJSValue UserDialog::getInt(const QString &title, const QString &label, int value, int step, int min, int max) { - LOG("UserDialog::getInt", title, label, value, step, min, max); + LOG(FUNCTION, title, label, value, step, min, max); bool ok; const int ret = QInputDialog::getInt(dialogParent(), title, label, value, min, max, step, &ok); if (ok) { - spdlog::debug("UserDialog::getInt returns {}", ret); + spdlog::debug("{} returns {}", FUNCTION, ret); return ret; } return QJSValue(QJSValue::NullValue); @@ -173,11 +173,11 @@ QJSValue UserDialog::getInt(const QString &title, const QString &label, int valu */ QJSValue UserDialog::getText(const QString &title, const QString &label, const QString &text) { - LOG("UserDialog::getText", title, label, text); + LOG(FUNCTION, title, label, text); bool ok; const QString ret = QInputDialog::getText(dialogParent(), title, label, QLineEdit::Normal, text, &ok); if (ok) { - spdlog::debug("UserDialog::getText returns {}", ret); + spdlog::debug("{} returns {}", FUNCTION, ret); return ret; } return QJSValue(QJSValue::NullValue); @@ -189,7 +189,7 @@ QJSValue UserDialog::getText(const QString &title, const QString &label, const Q */ void UserDialog::information(const QString &title, const QString &text) { - LOG("UserDialog::information", title, text); + LOG(FUNCTION, title, text); QMessageBox::information(dialogParent(), title, text); } @@ -199,7 +199,7 @@ void UserDialog::information(const QString &title, const QString &text) */ void UserDialog::warning(const QString &title, const QString &text) { - LOG("UserDialog::warning", title, text); + LOG(FUNCTION, title, text); QMessageBox::warning(dialogParent(), title, text); } @@ -209,7 +209,7 @@ void UserDialog::warning(const QString &title, const QString &text) */ void UserDialog::critical(const QString &title, const QString &text) { - LOG("UserDialog::critical", title, text); + LOG(FUNCTION, title, text); QMessageBox::critical(dialogParent(), title, text); } diff --git a/src/core/utils.cpp b/src/core/utils.cpp index 9d921f5f..9e8ccdc9 100644 --- a/src/core/utils.cpp +++ b/src/core/utils.cpp @@ -45,7 +45,7 @@ Utils::~Utils() = default; */ QString Utils::getEnv(const QString &varName) { - LOG("Utils::getEnv", varName); + LOG(FUNCTION, varName); return QString::fromUtf8(qgetenv(varName.toLatin1())); } @@ -60,7 +60,7 @@ QString Utils::getEnv(const QString &varName) */ QString Utils::getGlobal(const QString &varName) { - LOG("Utils::getGlobal", varName); + LOG(FUNCTION, varName); return m_globals.value(varName); } @@ -75,7 +75,7 @@ QString Utils::getGlobal(const QString &varName) */ void Utils::setGlobal(const QString &varName, const QString &value) { - LOG("Utils::setGlobal", varName, value); + LOG(FUNCTION, varName, value); m_globals.insert(varName, value); } @@ -97,7 +97,7 @@ void Utils::setGlobal(const QString &varName, const QString &value) */ void Utils::addScriptPath(const QString &path) { - LOG("Utils::addScriptPath", path); + LOG(FUNCTION, path); ScriptManager::instance()->addDirectory(path); } @@ -108,7 +108,7 @@ void Utils::addScriptPath(const QString &path) */ void Utils::runScript(const QString &path, bool log) { - LOG("Utils::runScript", LOG_ARG("path", path), log); + LOG(FUNCTION, LOG_ARG("path", path), log); // Run the script synchronously ScriptManager::instance()->runScript(path, nlohmann::json::object(), false, log); @@ -120,7 +120,7 @@ void Utils::runScript(const QString &path, bool log) */ void Utils::sleep(int msecs) { - LOG("Utils::sleep", msecs); + LOG(FUNCTION, msecs); QElapsedTimer timer; timer.start(); @@ -136,7 +136,7 @@ void Utils::sleep(int msecs) // This function is copied from Qt Creator. QString Utils::mktemp(const QString &pattern) { - LOG("Utils::mktemp", pattern); + LOG(FUNCTION, pattern); QString tmp = pattern; if (tmp.isEmpty()) @@ -155,7 +155,7 @@ QString Utils::mktemp(const QString &pattern) return {}; file.close(); - spdlog::debug("Utils::mktemp created {}", tmp); + spdlog::debug("{}: created {}", FUNCTION, tmp); return file.fileName(); } @@ -174,7 +174,7 @@ QString Utils::mktemp(const QString &pattern) */ QString Utils::convertCase(const QString &str, Case from, Case to) { - LOG("Utils::convertCase", str, from, to); + LOG(FUNCTION, str, from, to); return ::Utils::convertCase(str, static_cast<::Utils::Case>(from), static_cast<::Utils::Case>(to)); } @@ -184,7 +184,7 @@ QString Utils::convertCase(const QString &str, Case from, Case to) */ void Utils::copyToClipboard(const QString &text) { - LOG("Utils::copyToClipboard", text); + LOG(FUNCTION, text); auto clipboard = QApplication::clipboard(); clipboard->setText(text); } @@ -203,7 +203,7 @@ void Utils::copyToClipboard(const QString &text) // The readonly C++ attribute has the same functionality as the readonly MIDL attribute. QStringList Utils::cppKeywords() { - LOG("Utils::cppKeywords"); + LOG(FUNCTION); return QStringList {"alignas", "alignof", "and", @@ -299,7 +299,7 @@ QStringList Utils::cppKeywords() */ QStringList Utils::cppPrimitiveTypes() { - LOG("Utils::cppPrimitiveTypes"); + LOG(FUNCTION); return QStringList {"int", "long", "short", "void", "float", "double", "char", "char8_t", "char16_t", "char32_t", "wchar_t"}; } diff --git a/src/gui/apiexecutorwidget.cpp b/src/gui/apiexecutorwidget.cpp index 2ef4c161..6d5110e1 100644 --- a/src/gui/apiexecutorwidget.cpp +++ b/src/gui/apiexecutorwidget.cpp @@ -288,7 +288,7 @@ void APIExecutorWidget::executeAPI(Core::Document *document, const QByteArray &n genericArgs.value(5), genericArgs.value(6), genericArgs.value(7), genericArgs.value(8), genericArgs.value(9)); if (!success) - spdlog::error("Error trying to execute the function {}", name); + spdlog::error("{}: Error trying to execute the function {}", FUNCTION, name); } void APIExecutorWidget::open() diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index e4eb0ed2..16652cae 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -235,7 +235,7 @@ void OptionsDialog::initializeCppSettings() if (model->insertRows(0, 1)) { model->setData(model->index(0), excludeMacro); } else { - spdlog::warn("OptionsDialog::excludeMacro: Failed to create new row!"); + spdlog::warn("{}: OptionsDialog::excludeMacro: Failed to create new row!", FUNCTION); } } }); diff --git a/src/gui/scriptlistpanel.cpp b/src/gui/scriptlistpanel.cpp index 35974360..18fb9470 100644 --- a/src/gui/scriptlistpanel.cpp +++ b/src/gui/scriptlistpanel.cpp @@ -93,7 +93,7 @@ void ScriptListPanel::runScript(const QModelIndex &index) const auto fileName = index.data(Core::ScriptModel::PathRole).toString(); if (fileName.isEmpty()) { - spdlog::warn("ScriptListPanel::runScript - fileName is empty"); + spdlog::warn("{}: fileName is empty", FUNCTION); return; } diff --git a/src/gui/scriptpanel.cpp b/src/gui/scriptpanel.cpp index abae63a7..b6676a2b 100644 --- a/src/gui/scriptpanel.cpp +++ b/src/gui/scriptpanel.cpp @@ -154,7 +154,7 @@ void ScriptPanel::openScript() QFileInfo fi(m_fileName); m_scriptName->setText(fi.fileName()); } else { - spdlog::error("Error reading script - can't open the file for reading."); + spdlog::error("{}: Error reading script - can't open the file for reading.", FUNCTION); } } @@ -207,7 +207,7 @@ void ScriptPanel::saveScript() if (isQml && text.contains("ScriptDialog")) createDialogFile(); } else { - spdlog::error("Error saving script - can't open the file for writing."); + spdlog::error("{}: Error saving script - can't open the file for writing.", FUNCTION); } } @@ -226,7 +226,7 @@ void ScriptPanel::editDialog() if (!QDesktopServices::openUrl(QString("file:///%1").arg(uiFileName))) { QMessageBox::information(this, "Script Dialog Edition", "In order to edit the dialog, you need to install the Qt Designer tool."); - spdlog::error("Error editing dialog - Qt Designer is not found."); + spdlog::error("{}: Error editing dialog - Qt Designer is not found.", FUNCTION); } } @@ -244,7 +244,7 @@ QString ScriptPanel::createDialogFile() QString uiFileName = fi.absolutePath() + '/' + fi.baseName() + ".ui"; if (!QFile::exists(uiFileName) && !QFile::copy(":/gui/default-dialog.ui", uiFileName)) { - spdlog::error("Error creating dialog - can't create the dialog file."); + spdlog::error("{}: Error creating dialog - can't create the dialog file.", FUNCTION); return {}; } return uiFileName; @@ -268,7 +268,7 @@ void ScriptPanel::runScript() file.close(); Core::ScriptManager::instance()->runScript(file.fileName(), false, false); } else { - spdlog::error("Error running script - can't save to temporary file."); + spdlog::error("{}: Error running script - can't save to temporary file.", FUNCTION); } } diff --git a/src/gui/slintview.cpp b/src/gui/slintview.cpp index c02137fe..07e7f3bb 100644 --- a/src/gui/slintview.cpp +++ b/src/gui/slintview.cpp @@ -67,7 +67,7 @@ SlintView::~SlintView() void SlintView::runSlint() { if (m_process && m_process->state() == QProcess::Running) { - spdlog::warn("Slint-viewer process is already running"); + spdlog::warn("{}: Slint-viewer process is already running", FUNCTION); return; } diff --git a/src/lsp/client.cpp b/src/lsp/client.cpp index fa328ee9..1985bc70 100644 --- a/src/lsp/client.cpp +++ b/src/lsp/client.cpp @@ -83,7 +83,7 @@ bool Client::initialize(const QString &rootPath) if (!m_backend->start()) return false; - spdlog::debug("LSP server started in: {}", rootPath); + spdlog::debug("{}: LSP server started in: {}", FUNCTION, rootPath); InitializeRequest request; request.id = m_nextRequestId++; @@ -254,14 +254,14 @@ void Client::setState(State newState) bool Client::initializeCallback(InitializeRequest::Response response) { if (!response.isValid() || response.error) { - spdlog::error("Error initializing the server"); + spdlog::error("{}: Error initializing the server", FUNCTION); setState(Error); return false; } m_serverCapabilities = response.result->capabilities; m_backend->sendNotification(InitializedNotification()); - spdlog::debug("LSP server initialized"); + spdlog::debug("{}: LSP server initialized", FUNCTION); setState(Initialized); return true; } @@ -269,13 +269,13 @@ bool Client::initializeCallback(InitializeRequest::Response response) bool Client::shutdownCallback(ShutdownRequest::Response response) { if (!response.isValid() || response.error) { - spdlog::error("Error shutting down the server"); + spdlog::error("{}: Error shutting down the server", FUNCTION); setState(Error); return false; } m_backend->sendNotification(ExitNotification()); - spdlog::debug("LSP server exited"); + spdlog::debug("{}: LSP server exited", FUNCTION); setState(Shutdown); return true; } diff --git a/src/rccore/rc_convert.cpp b/src/rccore/rc_convert.cpp index 7f77eb24..e3e10a72 100644 --- a/src/rccore/rc_convert.cpp +++ b/src/rccore/rc_convert.cpp @@ -915,7 +915,7 @@ QString convertLanguageToCode(const QString &name) } } } - spdlog::error("Unknown language name conversion {} ", name); + spdlog::error("{}: Unknown language name conversion {} ", FUNCTION, name); return "en"; } diff --git a/src/treesitter/node.cpp b/src/treesitter/node.cpp index 5de8a0db..9d4389dc 100644 --- a/src/treesitter/node.cpp +++ b/src/treesitter/node.cpp @@ -54,7 +54,7 @@ QString Node::fieldNameForChild(const Node &child) const // result = name; // } // } else { - // spdlog::warn("Node::fieldNameForChild - given node is not a child!"); + // spdlog::warn("{}: given node is not a child!", FUNCTION); // } // // However, the code produces incorrect field names in a few cases. @@ -105,7 +105,7 @@ QString Node::fieldNameForChild(const Node &child) const ts_tree_cursor_delete(&cursor); if (!found) { - spdlog::warn("Node::fieldNameForChild - given node is not a child!"); + spdlog::warn("{}: given node is not a child!", FUNCTION); } return result; diff --git a/src/treesitter/predicates.cpp b/src/treesitter/predicates.cpp index 09613dbf..94a6f265 100644 --- a/src/treesitter/predicates.cpp +++ b/src/treesitter/predicates.cpp @@ -447,7 +447,7 @@ void Predicates::findMessageMap() const } if (!m_rootNode.has_value()) { - spdlog::warn("Predicates::findMessageMap: No rootNode!"); + spdlog::warn("Predicate: #in_message_map? - No rootNode!"); return; } diff --git a/src/utils/log.h b/src/utils/log.h index eaefd5ef..cc647799 100644 --- a/src/utils/log.h +++ b/src/utils/log.h @@ -11,4 +11,43 @@ #pragma once #include "qt_fmt_format.h" + +#include +#include #include + +/** + * Format the std::source_location::current().function_name() return value + * to a simplified 'className::functionName' string value. + * The FUNCTION macro is meant to be called by spdlog to point to the function location. + * e.g: spdlog::error("{}: {} - cannot convert", FUNCTION, path); + */ + +#define FUNCTION Core::formatToClassNameFunctionName(std::source_location::current()) + +namespace Core { + +inline QString formatToClassNameFunctionName(const std::source_location &location) +{ + // Get the functionName. + // str = e.g: "QVariant Core::Settings::value(QString, const QVariant&) const" + QString str(location.function_name()); + + // Extract the section before the arguments list. + int openParenthesisIndex = str.indexOf("("); + str = str.mid(0, openParenthesisIndex); + // Split (whitespace and double columns). + static const QRegularExpression splitRegexp("\\s+|::"); + QStringList sections = str.split(splitRegexp); + + // Assert in case we have less than 2 elements. + Q_ASSERT(sections.size() >= 2); + + // Keep the 2 last elements of the list, remove the leading symbols. + sections = sections.mid(sections.size() - 2); + static const QRegularExpression symbolsRegexp("[*&]"); + str = sections[0].remove(symbolsRegexp) + "::" + sections[1]; + return str; +} + +} // namespace Core