diff options
| author | Shauren <shauren.trinity@gmail.com> | 2023-01-08 21:16:53 +0100 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2023-01-08 21:16:53 +0100 |
| commit | d791afae1dfcfaf592326f787755ca32d629e4d3 (patch) | |
| tree | 54dc9916ede5800e110a2f0edff91530811fbdb8 /src/server/database/Updater | |
| parent | b6820a706f46f18b9652fcd9806e4bec8805d29d (diff) | |
Core/Logging: Switch from fmt::sprintf to fmt::format (c++20 standard compatible api)
Diffstat (limited to 'src/server/database/Updater')
| -rw-r--r-- | src/server/database/Updater/DBUpdater.cpp | 42 | ||||
| -rw-r--r-- | src/server/database/Updater/UpdateFetcher.cpp | 54 |
2 files changed, 48 insertions, 48 deletions
diff --git a/src/server/database/Updater/DBUpdater.cpp b/src/server/database/Updater/DBUpdater.cpp index 90001bc19e4..c43b61fb51b 100644 --- a/src/server/database/Updater/DBUpdater.cpp +++ b/src/server/database/Updater/DBUpdater.cpp @@ -50,8 +50,8 @@ bool DBUpdaterUtil::CheckExecutable() return true; } - TC_LOG_FATAL("sql.updates", "Didn't find any executable MySQL binary at \'%s\' or in path, correct the path in the *.conf (\"MySQLExecutable\").", - absolute(exe).generic_string().c_str()); + TC_LOG_FATAL("sql.updates", "Didn't find any executable MySQL binary at \'{}\' or in path, correct the path in the *.conf (\"MySQLExecutable\").", + absolute(exe).generic_string()); return false; } @@ -192,15 +192,15 @@ BaseLocation DBUpdater<T>::GetBaseLocationType() template<class T> bool DBUpdater<T>::Create(DatabaseWorkerPool<T>& pool) { - TC_LOG_INFO("sql.updates", "Database \"%s\" does not exist, do you want to create it? [yes (default) / no]: ", - pool.GetConnectionInfo()->database.c_str()); + TC_LOG_INFO("sql.updates", "Database \"{}\" does not exist, do you want to create it? [yes (default) / no]: ", + pool.GetConnectionInfo()->database); std::string answer; std::getline(std::cin, answer); if (!answer.empty() && !(answer.substr(0, 1) == "y")) return false; - TC_LOG_INFO("sql.updates", "Creating database \"%s\"...", pool.GetConnectionInfo()->database.c_str()); + TC_LOG_INFO("sql.updates", "Creating database \"{}\"...", pool.GetConnectionInfo()->database); // Path of temp file static Path const temp("create_table.sql"); @@ -209,7 +209,7 @@ bool DBUpdater<T>::Create(DatabaseWorkerPool<T>& pool) std::ofstream file(temp.generic_string()); if (!file.is_open()) { - TC_LOG_FATAL("sql.updates", "Failed to create temporary query file \"%s\"!", temp.generic_string().c_str()); + TC_LOG_FATAL("sql.updates", "Failed to create temporary query file \"{}\"!", temp.generic_string()); return false; } @@ -224,7 +224,7 @@ bool DBUpdater<T>::Create(DatabaseWorkerPool<T>& pool) } catch (UpdateException&) { - TC_LOG_FATAL("sql.updates", "Failed to create database %s! Does the user (named in *.conf) have `CREATE`, `ALTER`, `DROP`, `INSERT` and `DELETE` privileges on the MySQL server?", pool.GetConnectionInfo()->database.c_str()); + TC_LOG_FATAL("sql.updates", "Failed to create database {}! Does the user (named in *.conf) have `CREATE`, `ALTER`, `DROP`, `INSERT` and `DELETE` privileges on the MySQL server?", pool.GetConnectionInfo()->database); boost::filesystem::remove(temp); return false; } @@ -240,13 +240,13 @@ bool DBUpdater<T>::Update(DatabaseWorkerPool<T>& pool) if (!DBUpdaterUtil::CheckExecutable()) return false; - TC_LOG_INFO("sql.updates", "Updating %s database...", DBUpdater<T>::GetTableName().c_str()); + TC_LOG_INFO("sql.updates", "Updating {} database...", DBUpdater<T>::GetTableName()); Path const sourceDirectory(BuiltInConfig::GetSourceDirectory()); if (!is_directory(sourceDirectory)) { - TC_LOG_ERROR("sql.updates", "DBUpdater: The given source directory %s does not exist, change the path to the directory where your sql directory exists (for example c:\\source\\trinitycore). Shutting down.", sourceDirectory.generic_string().c_str()); + TC_LOG_ERROR("sql.updates", "DBUpdater: The given source directory {} does not exist, change the path to the directory where your sql directory exists (for example c:\\source\\trinitycore). Shutting down.", sourceDirectory.generic_string()); return false; } @@ -268,13 +268,13 @@ bool DBUpdater<T>::Update(DatabaseWorkerPool<T>& pool) return false; } - std::string const info = Trinity::StringFormat("Containing " SZFMTD " new and " SZFMTD " archived updates.", + std::string const info = Trinity::StringFormat("Containing {} new and {} archived updates.", result.recent, result.archived); if (!result.updated) - TC_LOG_INFO("sql.updates", ">> %s database is up-to-date! %s", DBUpdater<T>::GetTableName().c_str(), info.c_str()); + TC_LOG_INFO("sql.updates", ">> {} database is up-to-date! {}", DBUpdater<T>::GetTableName(), info); else - TC_LOG_INFO("sql.updates", ">> Applied " SZFMTD " %s. %s", result.updated, result.updated == 1 ? "query" : "queries", info.c_str()); + TC_LOG_INFO("sql.updates", ">> Applied {} {}. {}", result.updated, result.updated == 1 ? "query" : "queries", info); return true; } @@ -291,7 +291,7 @@ bool DBUpdater<T>::Populate(DatabaseWorkerPool<T>& pool) if (!DBUpdaterUtil::CheckExecutable()) return false; - TC_LOG_INFO("sql.updates", "Database %s is empty, auto populating it...", DBUpdater<T>::GetTableName().c_str()); + TC_LOG_INFO("sql.updates", "Database {} is empty, auto populating it...", DBUpdater<T>::GetTableName()); std::string const p = DBUpdater<T>::GetBaseFile(); if (p.empty()) @@ -307,8 +307,8 @@ bool DBUpdater<T>::Populate(DatabaseWorkerPool<T>& pool) { case LOCATION_REPOSITORY: { - TC_LOG_ERROR("sql.updates", ">> Base file \"%s\" is missing. Try fixing it by cloning the source again.", - base.generic_string().c_str()); + TC_LOG_ERROR("sql.updates", ">> Base file \"{}\" is missing. Try fixing it by cloning the source again.", + base.generic_string()); break; } @@ -316,8 +316,8 @@ bool DBUpdater<T>::Populate(DatabaseWorkerPool<T>& pool) { std::string const filename = base.filename().generic_string(); std::string const workdir = boost::filesystem::current_path().generic_string(); - TC_LOG_ERROR("sql.updates", ">> File \"%s\" is missing, download it from \"https://github.com/TrinityCore/TrinityCore/releases\"" \ - " uncompress it and place the file \"%s\" in the directory \"%s\".", filename.c_str(), filename.c_str(), workdir.c_str()); + TC_LOG_ERROR("sql.updates", ">> File \"{}\" is missing, download it from \"https://github.com/TrinityCore/TrinityCore/releases\"" \ + " uncompress it and place the file \"{}\" in the directory \"{}\".", filename, filename, workdir); break; } } @@ -325,7 +325,7 @@ bool DBUpdater<T>::Populate(DatabaseWorkerPool<T>& pool) } // Update database - TC_LOG_INFO("sql.updates", ">> Applying \'%s\'...", base.generic_string().c_str()); + TC_LOG_INFO("sql.updates", ">> Applying \'{}\'...", base.generic_string()); try { ApplyFile(pool, base); @@ -416,7 +416,7 @@ void DBUpdater<T>::ApplyFile(DatabaseWorkerPool<T>& pool, std::string const& hos // Execute sql file args.emplace_back("-e"); - args.emplace_back(Trinity::StringFormat("BEGIN; SOURCE %s; COMMIT;", path.generic_string().c_str())); + args.emplace_back(Trinity::StringFormat("BEGIN; SOURCE {}; COMMIT;", path.generic_string())); // Database if (!database.empty()) @@ -428,12 +428,12 @@ void DBUpdater<T>::ApplyFile(DatabaseWorkerPool<T>& pool, std::string const& hos if (ret != EXIT_SUCCESS) { - TC_LOG_FATAL("sql.updates", "Applying of file \'%s\' to database \'%s\' failed!" \ + TC_LOG_FATAL("sql.updates", "Applying of file \'{}\' to database \'{}\' failed!" \ " If you are a user, please pull the latest revision from the repository. " "Also make sure you have not applied any of the databases with your sql client. " "You cannot use auto-update system and import sql files from TrinityCore repository with your sql client. " "If you are a developer, please fix your sql query.", - path.generic_string().c_str(), pool.GetConnectionInfo()->database.c_str()); + path.generic_string(), pool.GetConnectionInfo()->database); throw UpdateException("update failed"); } diff --git a/src/server/database/Updater/UpdateFetcher.cpp b/src/server/database/Updater/UpdateFetcher.cpp index 76dabf37e66..33a3eb4613b 100644 --- a/src/server/database/Updater/UpdateFetcher.cpp +++ b/src/server/database/Updater/UpdateFetcher.cpp @@ -74,7 +74,7 @@ void UpdateFetcher::FillFileListRecursively(Path const& path, LocaleFileStorage& } else if (itr->path().extension() == ".sql") { - TC_LOG_TRACE("sql.updates", "Added locale file \"%s\".", itr->path().filename().generic_string().c_str()); + TC_LOG_TRACE("sql.updates", "Added locale file \"{}\".", itr->path().filename().generic_string()); LocaleFileEntry const entry = { itr->path(), state }; @@ -82,8 +82,8 @@ void UpdateFetcher::FillFileListRecursively(Path const& path, LocaleFileStorage& // Because elements are only compared by their filenames, this is ok if (storage.find(entry) != storage.end()) { - TC_LOG_FATAL("sql.updates", "Duplicate filename \"%s\" occurred. Because updates are ordered " \ - "by their filenames, every name needs to be unique!", itr->path().generic_string().c_str()); + TC_LOG_FATAL("sql.updates", "Duplicate filename \"{}\" occurred. Because updates are ordered " \ + "by their filenames, every name needs to be unique!", itr->path().generic_string()); throw UpdateException("Updating failed, see the log for details."); } @@ -113,14 +113,14 @@ UpdateFetcher::DirectoryStorage UpdateFetcher::ReceiveIncludedDirectories() cons if (!is_directory(p)) { - TC_LOG_WARN("sql.updates", "DBUpdater: Given update include directory \"%s\" does not exist, skipped!", p.generic_string().c_str()); + TC_LOG_WARN("sql.updates", "DBUpdater: Given update include directory \"{}\" does not exist, skipped!", p.generic_string()); continue; } DirectoryEntry const entry = { p, AppliedFileEntry::StateConvert(fields[1].GetString()) }; directories.push_back(entry); - TC_LOG_TRACE("sql.updates", "Added applied file \"%s\" from remote.", p.filename().generic_string().c_str()); + TC_LOG_TRACE("sql.updates", "Added applied file \"{}\" from remote.", p.filename().generic_string()); } while (result->NextRow()); @@ -154,10 +154,10 @@ std::string UpdateFetcher::ReadSQLUpdate(boost::filesystem::path const& file) co std::ifstream in(file.c_str()); if (!in.is_open()) { - TC_LOG_FATAL("sql.updates", "Failed to open the sql update \"%s\" for reading! " + TC_LOG_FATAL("sql.updates", "Failed to open the sql update \"{}\" for reading! " "Stopping the server to keep the database integrity, " "try to identify and solve the issue or disable the database updater.", - file.generic_string().c_str()); + file.generic_string()); throw UpdateException("Opening the sql update failed!"); } @@ -199,7 +199,7 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks, for (auto const& availableQuery : available) { - TC_LOG_DEBUG("sql.updates", "Checking update \"%s\"...", availableQuery.first.filename().generic_string().c_str()); + TC_LOG_DEBUG("sql.updates", "Checking update \"{}\"...", availableQuery.first.filename().generic_string()); AppliedFileStorage::const_iterator iter = applied.find(availableQuery.first.filename().string()); if (iter != applied.end()) @@ -242,16 +242,16 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks, // Conflict! if (localeIter != available.end()) { - TC_LOG_WARN("sql.updates", ">> It seems like the update \"%s\" \'%s\' was renamed, but the old file is still there! " \ - "Treating it as a new file! (It is probably an unmodified copy of the file \"%s\")", - availableQuery.first.filename().string().c_str(), hash.substr(0, 7).c_str(), - localeIter->first.filename().string().c_str()); + TC_LOG_WARN("sql.updates", ">> It seems like the update \"{}\" \'{}\' was renamed, but the old file is still there! " \ + "Treating it as a new file! (It is probably an unmodified copy of the file \"{}\")", + availableQuery.first.filename().string(), hash.substr(0, 7), + localeIter->first.filename().string()); } // It is safe to treat the file as renamed here else { - TC_LOG_INFO("sql.updates", ">> Renaming update \"%s\" to \"%s\" \'%s\'.", - hashIter->second.c_str(), availableQuery.first.filename().string().c_str(), hash.substr(0, 7).c_str()); + TC_LOG_INFO("sql.updates", ">> Renaming update \"{}\" to \"{}\" \'{}\'.", + hashIter->second, availableQuery.first.filename().string(), hash.substr(0, 7)); RenameEntry(hashIter->second, availableQuery.first.filename().string()); applied.erase(hashIter->second); @@ -261,8 +261,8 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks, // Apply the update if it was never seen before. else { - TC_LOG_INFO("sql.updates", ">> Applying update \"%s\" \'%s\'...", - availableQuery.first.filename().string().c_str(), hash.substr(0, 7).c_str()); + TC_LOG_INFO("sql.updates", ">> Applying update \"{}\" \'{}\'...", + availableQuery.first.filename().string(), hash.substr(0, 7)); } } // Rehash the update entry if it exists in our database with an empty hash. @@ -270,29 +270,29 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks, { mode = MODE_REHASH; - TC_LOG_INFO("sql.updates", ">> Re-hashing update \"%s\" \'%s\'...", availableQuery.first.filename().string().c_str(), - hash.substr(0, 7).c_str()); + TC_LOG_INFO("sql.updates", ">> Re-hashing update \"{}\" \'{}\'...", availableQuery.first.filename().string(), + hash.substr(0, 7)); } else { // If the hash of the files differs from the one stored in our database, reapply the update (because it changed). if (iter->second.hash != hash) { - TC_LOG_INFO("sql.updates", ">> Reapplying update \"%s\" \'%s\' -> \'%s\' (it changed)...", availableQuery.first.filename().string().c_str(), - iter->second.hash.substr(0, 7).c_str(), hash.substr(0, 7).c_str()); + TC_LOG_INFO("sql.updates", ">> Reapplying update \"{}\" \'{}\' -> \'{}\' (it changed)...", availableQuery.first.filename().string(), + iter->second.hash.substr(0, 7), hash.substr(0, 7)); } else { // If the file wasn't changed and just moved, update its state (if necessary). if (iter->second.state != availableQuery.second) { - TC_LOG_DEBUG("sql.updates", ">> Updating the state of \"%s\" to \'%s\'...", - availableQuery.first.filename().string().c_str(), AppliedFileEntry::StateConvert(availableQuery.second).c_str()); + TC_LOG_DEBUG("sql.updates", ">> Updating the state of \"{}\" to \'{}\'...", + availableQuery.first.filename().string(), AppliedFileEntry::StateConvert(availableQuery.second)); UpdateState(availableQuery.first.filename().string(), availableQuery.second); } - TC_LOG_DEBUG("sql.updates", ">> Update is already applied and matches the hash \'%s\'.", hash.substr(0, 7).c_str()); + TC_LOG_DEBUG("sql.updates", ">> Update is already applied and matches the hash \'{}\'.", hash.substr(0, 7)); applied.erase(iter); continue; @@ -326,18 +326,18 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks, for (auto const& entry : applied) { - TC_LOG_WARN("sql.updates", ">> The file \'%s\' was applied to the database, but is missing in" \ - " your update directory now!", entry.first.c_str()); + TC_LOG_WARN("sql.updates", ">> The file \'{}\' was applied to the database, but is missing in" \ + " your update directory now!", entry.first); if (doCleanup) - TC_LOG_INFO("sql.updates", "Deleting orphaned entry \'%s\'...", entry.first.c_str()); + TC_LOG_INFO("sql.updates", "Deleting orphaned entry \'{}\'...", entry.first); } if (doCleanup) CleanUp(applied); else { - TC_LOG_ERROR("sql.updates", "Cleanup is disabled! There were " SZFMTD " dirty files applied to your database, " \ + TC_LOG_ERROR("sql.updates", "Cleanup is disabled! There were {} dirty files applied to your database, " \ "but they are now missing in your source directory!", applied.size()); } } |
