diff options
author | Kargatum <dowlandtop@yandex.com> | 2022-01-27 22:44:41 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 16:44:41 +0100 |
commit | 5969df4e303121cca77166df28aa0e9ff2f17e9f (patch) | |
tree | af8b4ad44f17854fb0e8eeeb0d4eb387b0715bbf /src/server/database/Database/MySQLConnection.cpp | |
parent | 5228d293794bb1137a1f857ade784a39ee460bdd (diff) |
refactor(Core/Logging): switch to fmt style for LOG_ (#10366)
* feat(Core/Common): add support fmt style for ASSERT and ABORT
* correct CheckCompactArrayMaskOverflow
* 1
* Update src/server/game/Spells/Spell.cpp
* rework logging
* add fmt replace logs
* logging
* FMT_LOG_
* settings
* fix startup
* 1
* 2
* 3
* 4
* 5
* fmt::print
* to fmt
Diffstat (limited to 'src/server/database/Database/MySQLConnection.cpp')
-rw-r--r-- | src/server/database/Database/MySQLConnection.cpp | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/src/server/database/Database/MySQLConnection.cpp b/src/server/database/Database/MySQLConnection.cpp index 692b32f5bb..e594e22434 100644 --- a/src/server/database/Database/MySQLConnection.cpp +++ b/src/server/database/Database/MySQLConnection.cpp @@ -91,7 +91,7 @@ uint32 MySQLConnection::Open() MYSQL* mysqlInit = mysql_init(nullptr); if (!mysqlInit) { - LOG_ERROR("sql.sql", "Could not initialize Mysql connection to database `%s`", m_connectionInfo.database.c_str()); + LOG_ERROR("sql.sql", "Could not initialize Mysql connection to database `{}`", m_connectionInfo.database); return CR_UNKNOWN_ERROR; } @@ -154,14 +154,14 @@ uint32 MySQLConnection::Open() { if (!m_reconnecting) { - LOG_INFO("sql.sql", "MySQL client library: %s", mysql_get_client_info()); - LOG_INFO("sql.sql", "MySQL server ver: %s ", mysql_get_server_info(m_Mysql)); + LOG_INFO("sql.sql", "MySQL client library: {}", mysql_get_client_info()); + LOG_INFO("sql.sql", "MySQL server ver: {} ", mysql_get_server_info(m_Mysql)); // MySQL version above 5.1 IS required in both client and server and there is no known issue with different versions above 5.1 // if (mysql_get_server_version(m_Mysql) != mysql_get_client_version()) // LOG_INFO("sql.sql", "[WARNING] MySQL client/server version mismatch; may conflict with behaviour of prepared statements."); } - LOG_INFO("sql.sql", "Connected to MySQL database at %s", m_connectionInfo.host.c_str()); + LOG_INFO("sql.sql", "Connected to MySQL database at {}", m_connectionInfo.host); mysql_autocommit(m_Mysql, 1); // set connection properties to UTF8 to properly handle locales for different @@ -171,7 +171,7 @@ uint32 MySQLConnection::Open() } else { - LOG_ERROR("sql.sql", "Could not connect to MySQL database at %s: %s", m_connectionInfo.host.c_str(), mysql_error(mysqlInit)); + LOG_ERROR("sql.sql", "Could not connect to MySQL database at {}: {}", m_connectionInfo.host, mysql_error(mysqlInit)); uint32 errorCode = mysql_errno(mysqlInit); mysql_close(mysqlInit); return errorCode; @@ -196,8 +196,8 @@ bool MySQLConnection::Execute(char const* sql) { uint32 lErrno = mysql_errno(m_Mysql); - LOG_INFO("sql.sql", "SQL: %s", sql); - LOG_ERROR("sql.sql", "[%u] %s", lErrno, mysql_error(m_Mysql)); + LOG_INFO("sql.sql", "SQL: {}", sql); + LOG_ERROR("sql.sql", "[{}] {}", lErrno, mysql_error(m_Mysql)); if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled successfully (i.e. reconnection) return Execute(sql); // Try again @@ -205,7 +205,7 @@ bool MySQLConnection::Execute(char const* sql) return false; } else - LOG_DEBUG("sql.sql", "[%u ms] SQL: %s", getMSTimeDiff(_s, getMSTime()), sql); + LOG_DEBUG("sql.sql", "[{} ms] SQL: {}", getMSTimeDiff(_s, getMSTime()), sql); } return true; @@ -231,7 +231,7 @@ bool MySQLConnection::Execute(PreparedStatementBase* stmt) if (mysql_stmt_bind_param(msql_STMT, msql_BIND)) { uint32 lErrno = mysql_errno(m_Mysql); - LOG_ERROR("sql.sql", "SQL(p): %s\n [ERROR]: [%u] %s", m_mStmt->getQueryString().c_str(), lErrno, mysql_stmt_error(msql_STMT)); + LOG_ERROR("sql.sql", "SQL(p): {}\n [ERROR]: [{}] {}", m_mStmt->getQueryString(), lErrno, mysql_stmt_error(msql_STMT)); if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled successfully (i.e. reconnection) return Execute(stmt); // Try again @@ -243,7 +243,7 @@ bool MySQLConnection::Execute(PreparedStatementBase* stmt) if (mysql_stmt_execute(msql_STMT)) { uint32 lErrno = mysql_errno(m_Mysql); - LOG_ERROR("sql.sql", "SQL(p): %s\n [ERROR]: [%u] %s", m_mStmt->getQueryString().c_str(), lErrno, mysql_stmt_error(msql_STMT)); + LOG_ERROR("sql.sql", "SQL(p): {}\n [ERROR]: [{}] {}", m_mStmt->getQueryString(), lErrno, mysql_stmt_error(msql_STMT)); if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled successfully (i.e. reconnection) return Execute(stmt); // Try again @@ -252,7 +252,7 @@ bool MySQLConnection::Execute(PreparedStatementBase* stmt) return false; } - LOG_DEBUG("sql.sql", "[%u ms] SQL(p): %s", getMSTimeDiff(_s, getMSTime()), m_mStmt->getQueryString().c_str()); + LOG_DEBUG("sql.sql", "[{} ms] SQL(p): {}", getMSTimeDiff(_s, getMSTime()), m_mStmt->getQueryString()); m_mStmt->ClearParameters(); return true; @@ -279,7 +279,7 @@ bool MySQLConnection::_Query(PreparedStatementBase* stmt, MySQLPreparedStatement if (mysql_stmt_bind_param(msql_STMT, msql_BIND)) { uint32 lErrno = mysql_errno(m_Mysql); - LOG_ERROR("sql.sql", "SQL(p): %s\n [ERROR]: [%u] %s", m_mStmt->getQueryString().c_str(), lErrno, mysql_stmt_error(msql_STMT)); + LOG_ERROR("sql.sql", "SQL(p): {}\n [ERROR]: [{}] {}", m_mStmt->getQueryString(), lErrno, mysql_stmt_error(msql_STMT)); if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled successfully (i.e. reconnection) return _Query(stmt, mysqlStmt, pResult, pRowCount, pFieldCount); // Try again @@ -291,8 +291,8 @@ bool MySQLConnection::_Query(PreparedStatementBase* stmt, MySQLPreparedStatement if (mysql_stmt_execute(msql_STMT)) { uint32 lErrno = mysql_errno(m_Mysql); - LOG_ERROR("sql.sql", "SQL(p): %s\n [ERROR]: [%u] %s", - m_mStmt->getQueryString().c_str(), lErrno, mysql_stmt_error(msql_STMT)); + LOG_ERROR("sql.sql", "SQL(p): {}\n [ERROR]: [{}] {}", + m_mStmt->getQueryString(), lErrno, mysql_stmt_error(msql_STMT)); if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled successfully (i.e. reconnection) return _Query(stmt, mysqlStmt, pResult, pRowCount, pFieldCount); // Try again @@ -301,7 +301,7 @@ bool MySQLConnection::_Query(PreparedStatementBase* stmt, MySQLPreparedStatement return false; } - LOG_DEBUG("sql.sql", "[%u ms] SQL(p): %s", getMSTimeDiff(_s, getMSTime()), m_mStmt->getQueryString().c_str()); + LOG_DEBUG("sql.sql", "[{} ms] SQL(p): {}", getMSTimeDiff(_s, getMSTime()), m_mStmt->getQueryString()); m_mStmt->ClearParameters(); @@ -339,8 +339,8 @@ bool MySQLConnection::_Query(const char* sql, MySQLResult** pResult, MySQLField* if (mysql_query(m_Mysql, sql)) { uint32 lErrno = mysql_errno(m_Mysql); - LOG_INFO("sql.sql", "SQL: %s", sql); - LOG_ERROR("sql.sql", "[%u] %s", lErrno, mysql_error(m_Mysql)); + LOG_INFO("sql.sql", "SQL: {}", sql); + LOG_ERROR("sql.sql", "[{}] {}", lErrno, mysql_error(m_Mysql)); if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled successfully (i.e. reconnection) return _Query(sql, pResult, pFields, pRowCount, pFieldCount); // We try again @@ -348,7 +348,7 @@ bool MySQLConnection::_Query(const char* sql, MySQLResult** pResult, MySQLField* return false; } else - LOG_DEBUG("sql.sql", "[%u ms] SQL: %s", getMSTimeDiff(_s, getMSTime()), sql); + LOG_DEBUG("sql.sql", "[{} ms] SQL: {}", getMSTimeDiff(_s, getMSTime()), sql); *pResult = reinterpret_cast<MySQLResult*>(mysql_store_result(m_Mysql)); *pRowCount = mysql_affected_rows(m_Mysql); @@ -403,7 +403,7 @@ int MySQLConnection::ExecuteTransaction(std::shared_ptr<TransactionBase> transac ASSERT(stmt); if (!Execute(stmt)) { - LOG_WARN("sql.sql", "Transaction aborted. %u queries not executed.", (uint32)queries.size()); + LOG_WARN("sql.sql", "Transaction aborted. {} queries not executed.", (uint32)queries.size()); int errorCode = GetLastError(); RollbackTransaction(); return errorCode; @@ -416,7 +416,7 @@ int MySQLConnection::ExecuteTransaction(std::shared_ptr<TransactionBase> transac ASSERT(sql); if (!Execute(sql)) { - LOG_WARN("sql.sql", "Transaction aborted. %u queries not executed.", (uint32)queries.size()); + LOG_WARN("sql.sql", "Transaction aborted. {} queries not executed.", (uint32)queries.size()); int errorCode = GetLastError(); RollbackTransaction(); return errorCode; @@ -471,8 +471,8 @@ MySQLPreparedStatement* MySQLConnection::GetPreparedStatement(uint32 index) index, m_stmts.size(), m_connectionInfo.database, (m_connectionFlags & CONNECTION_ASYNC) ? "asynchronous" : "synchronous"); MySQLPreparedStatement* ret = m_stmts[index].get(); if (!ret) - LOG_ERROR("sql.sql", "Could not fetch prepared statement %u on database `%s`, connection type: %s.", - index, m_connectionInfo.database.c_str(), (m_connectionFlags & CONNECTION_ASYNC) ? "asynchronous" : "synchronous"); + LOG_ERROR("sql.sql", "Could not fetch prepared statement {} on database `{}`, connection type: {}.", + index, m_connectionInfo.database, (m_connectionFlags & CONNECTION_ASYNC) ? "asynchronous" : "synchronous"); return ret; } @@ -491,16 +491,16 @@ void MySQLConnection::PrepareStatement(uint32 index, std::string const& sql, Con MYSQL_STMT* stmt = mysql_stmt_init(m_Mysql); if (!stmt) { - LOG_ERROR("sql.sql", "In mysql_stmt_init() id: %u, sql: \"%s\"", index, sql.c_str()); - LOG_ERROR("sql.sql", "%s", mysql_error(m_Mysql)); + LOG_ERROR("sql.sql", "In mysql_stmt_init() id: {}, sql: \"{}\"", index, sql); + LOG_ERROR("sql.sql", "{}", mysql_error(m_Mysql)); m_prepareError = true; } else { if (mysql_stmt_prepare(stmt, sql.c_str(), static_cast<unsigned long>(sql.size()))) { - LOG_ERROR("sql.sql", "In mysql_stmt_prepare() id: %u, sql: \"%s\"", index, sql.c_str()); - LOG_ERROR("sql.sql", "%s", mysql_stmt_error(stmt)); + LOG_ERROR("sql.sql", "In mysql_stmt_prepare() id: {}, sql: \"{}\"", index, sql); + LOG_ERROR("sql.sql", "{}", mysql_stmt_error(stmt)); mysql_stmt_close(stmt); m_prepareError = true; } @@ -560,8 +560,8 @@ bool MySQLConnection::_HandleMySQLErrno(uint32 errNo, uint8 attempts /*= 5*/) std::abort(); } - LOG_INFO("sql.sql", "Successfully reconnected to %s @%s:%s (%s).", - m_connectionInfo.database.c_str(), m_connectionInfo.host.c_str(), m_connectionInfo.port_or_socket.c_str(), + LOG_INFO("sql.sql", "Successfully reconnected to {} @{}:{} ({}).", + m_connectionInfo.database, m_connectionInfo.host, m_connectionInfo.port_or_socket, (m_connectionFlags & CONNECTION_ASYNC) ? "asynchronous" : "synchronous"); m_reconnecting = false; @@ -608,7 +608,7 @@ bool MySQLConnection::_HandleMySQLErrno(uint32 errNo, uint8 attempts /*= 5*/) std::abort(); return false; default: - LOG_ERROR("sql.sql", "Unhandled MySQL errno %u. Unexpected behaviour possible.", errNo); + LOG_ERROR("sql.sql", "Unhandled MySQL errno {}. Unexpected behaviour possible.", errNo); return false; } } |