Created
July 4, 2011 03:24
-
-
Save DDuarte/1062865 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r 32edb9db7028 -r 19ca6baa6808 src/server/shared/Database/MySQLConnection.cpp | |
--- a/src/server/shared/Database/MySQLConnection.cpp Wed Jan 05 19:50:23 2011 +0200 | |
+++ b/src/server/shared/Database/MySQLConnection.cpp Wed Jan 05 20:44:01 2011 +0200 | |
@@ -156,8 +156,11 @@ | |
{ | |
uint32 lErrno = mysql_errno(m_Mysql); | |
- sLog->outSQLDriver("SQL: %s", sql); | |
- sLog->outSQLDriver("ERROR: [%u] %s", lErrno, mysql_error(m_Mysql)); | |
+ if (sLog->GetSQLDriverQueryPrintErrors()) | |
+ { | |
+ sLog->outSQLDriver("SQL: %s", sql); | |
+ sLog->outSQLDriver("ERROR: [%u] %s", lErrno, mysql_error(m_Mysql)); | |
+ } | |
if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled succesfuly (ie reconnection) | |
return Execute(sql); // Try again | |
@@ -166,7 +169,10 @@ | |
} | |
else if (sLog->GetSQLDriverQueryLogging()) | |
{ | |
- sLog->outSQLDriver("[%u ms] SQL: %s", getMSTimeDiff(_s, getMSTime()), sql); | |
+ uint32 _diff = getMSTimeDiff(_s, getMSTime()); | |
+ | |
+ if (_diff >= sLog->GetSQLDriverQuertMinDiff()) | |
+ sLog->outSQLDriver("[%u ms] SQL: %s", _diff, sql); | |
} | |
} | |
diff -r 32edb9db7028 -r 19ca6baa6808 src/server/shared/Logging/Log.cpp | |
--- a/src/server/shared/Logging/Log.cpp Wed Jan 05 19:50:23 2011 +0200 | |
+++ b/src/server/shared/Logging/Log.cpp Wed Jan 05 20:44:01 2011 +0200 | |
@@ -167,6 +167,8 @@ | |
m_logFileLevel = sConfig->GetIntDefault("LogFileLevel", LOGL_NORMAL); | |
m_dbLogLevel = sConfig->GetIntDefault("DBLogLevel", LOGL_NORMAL); | |
m_sqlDriverQueryLogging = sConfig->GetBoolDefault("SQLDriverQueryLogging", false); | |
+ m_sqlDriverQueryPrintErrors = sConfig->GetBoolDefault("SQLDriverQueryPrintErrors", true); | |
+ m_sqlDriverQueryMinDiff = sConfig->GetIntDefault("SQLDriverQueryMinDiff", 0); | |
m_logFilter = 0; | |
diff -r 32edb9db7028 -r 19ca6baa6808 src/server/shared/Logging/Log.h | |
--- a/src/server/shared/Logging/Log.h Wed Jan 05 19:50:23 2011 +0200 | |
+++ b/src/server/shared/Logging/Log.h Wed Jan 05 20:44:01 2011 +0200 | |
@@ -119,6 +119,8 @@ | |
void SetLogFileLevel(char * Level); | |
void SetDBLogLevel(char * Level); | |
void SetSQLDriverQueryLogging(bool newStatus) { m_sqlDriverQueryLogging = newStatus; } | |
+ void SetSQLDriverQuertPrintErrors(bool Status) { m_sqlDriverQueryPrintErrors = Status; } | |
+ void SetSQLDriverQueryMinDiff(uint32 ms) { m_sqlDriverQueryMinDiff = ms; } | |
void SetRealmID(uint32 id) { realm = id; } | |
uint32 getLogFilter() const { return m_logFilter; } | |
@@ -130,6 +132,8 @@ | |
void SetLogDB(bool enable) { m_enableLogDB = enable; } | |
void SetLogDBLater(bool value) { m_enableLogDBLater = value; } | |
bool GetSQLDriverQueryLogging() const { return m_sqlDriverQueryLogging; } | |
+ bool GetSQLDriverQueryPrintErrors() const { return m_sqlDriverQueryPrintErrors; } | |
+ uint32 GetSQLDriverQuertMinDiff() const { return m_sqlDriverQueryMinDiff; } | |
private: | |
FILE* openLogFile(char const* configFileName,char const* configTimeStampFlag, char const* mode); | |
FILE* openGmlogPerAccount(uint32 account); | |
@@ -162,6 +166,8 @@ | |
// log levels: | |
// false: errors only, true: full query logging | |
bool m_sqlDriverQueryLogging; | |
+ bool m_sqlDriverQueryPrintErrors; | |
+ uint32 m_sqlDriverQueryMinDiff; | |
// log levels: | |
// 0 minimum/string, 1 basic/error, 2 detail, 3 full/debug | |
diff -r 32edb9db7028 -r 19ca6baa6808 src/server/worldserver/worldserver.conf.dist | |
--- a/src/server/worldserver/worldserver.conf.dist Wed Jan 05 19:50:23 2011 +0200 | |
+++ b/src/server/worldserver/worldserver.conf.dist Wed Jan 05 20:44:01 2011 +0200 | |
@@ -595,6 +595,22 @@ | |
SQLDriverQueryLogging = 0 | |
# | |
+# SQLDriverQueryPrintErrors | |
+# Description: Log SQL queries errors to the SQLDriverLogFile and console. | |
+# Default: 1 - (Enabled, enable printing errors to SQLDriverLogFile) | |
+# 0 - (Disabled, not print queries errors) | |
+ | |
+SQLDriverQueryPrintErrors = 1 | |
+ | |
+# | |
+# SQLDriverQueryMinDiff | |
+# Description: Allow to print long exeqution queries | |
+# Example: 100 - (Will be print queries with execution time more then 100 ms) | |
+# Default: 0 - (Print all queries with any execution time) | |
+ | |
+SQLDriverQueryMinDiff = 0 | |
+ | |
+# | |
# LogColors | |
# Description: Colors for log messages (Format: "normal basic detail debug"). | |
# Colors: 0 - Black | |
-- 2nd file | |
diff -r b1cdc367da18 -r ffa6d09ad28f src/server/shared/Database/MySQLConnection.cpp | |
--- a/src/server/shared/Database/MySQLConnection.cpp Wed Jan 05 23:08:12 2011 +0200 | |
+++ b/src/server/shared/Database/MySQLConnection.cpp Wed Jan 05 23:38:19 2011 +0200 | |
@@ -203,8 +203,9 @@ | |
if (mysql_stmt_bind_param(msql_STMT, msql_BIND)) | |
{ | |
uint32 lErrno = mysql_errno(m_Mysql); | |
- sLog->outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error binding params: [%u] %s", | |
- index, m_connectionInfo.database.c_str(), lErrno, mysql_stmt_error(msql_STMT)); | |
+ if (sLog->GetSQLDriverQueryPrintErrors()) | |
+ sLog->outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error binding params: [%u] %s", | |
+ index, m_connectionInfo.database.c_str(), lErrno, mysql_stmt_error(msql_STMT)); | |
if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled succesfuly (ie reconnection) | |
return Execute(stmt); // Try again | |
@@ -216,8 +217,9 @@ | |
if (mysql_stmt_execute(msql_STMT)) | |
{ | |
uint32 lErrno = mysql_errno(m_Mysql); | |
- sLog->outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error executing: [%u] %s", | |
- index, m_connectionInfo.database.c_str(), lErrno, mysql_stmt_error(msql_STMT)); | |
+ if (sLog->GetSQLDriverQueryPrintErrors()) | |
+ sLog->outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error executing: [%u] %s", | |
+ index, m_connectionInfo.database.c_str(), lErrno, mysql_stmt_error(msql_STMT)); | |
if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled succesfuly (ie reconnection) | |
return Execute(stmt); // Try again | |
@@ -227,8 +229,11 @@ | |
} | |
if (sLog->GetSQLDriverQueryLogging()) | |
- sLog->outSQLDriver("[%u ms] Prepared SQL: %u on database `%s`", | |
- getMSTimeDiff(_s, getMSTime()), index, m_connectionInfo.database.c_str()); | |
+ { | |
+ uint32 _diff = getMSTimeDiff(_s, getMSTime()); | |
+ if (_diff >= sLog->GetSQLDriverQuertMinDiff()) | |
+ sLog->outSQLDriver("[%u ms] Prepared SQL: %u on database `%s`", _diff, index, m_connectionInfo.database.c_str()); | |
+ } | |
m_mStmt->ClearParameters(); | |
return true; | |
@@ -259,8 +264,9 @@ | |
if (mysql_stmt_bind_param(msql_STMT, msql_BIND)) | |
{ | |
uint32 lErrno = mysql_errno(m_Mysql); | |
- sLog->outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error binding params: [%u] %s", | |
- index, m_connectionInfo.database.c_str(), lErrno, mysql_stmt_error(msql_STMT)); | |
+ if (sLog->GetSQLDriverQueryPrintErrors()) | |
+ sLog->outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error binding params: [%u] %s", | |
+ index, m_connectionInfo.database.c_str(), lErrno, mysql_stmt_error(msql_STMT)); | |
if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled succesfuly (ie reconnection) | |
return _Query(stmt, pResult, pRowCount, pFieldCount); // Try again | |
@@ -272,8 +278,9 @@ | |
if (mysql_stmt_execute(msql_STMT)) | |
{ | |
uint32 lErrno = mysql_errno(m_Mysql); | |
- sLog->outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error executing: [%u] %s", | |
- index, m_connectionInfo.database.c_str(), lErrno, mysql_stmt_error(msql_STMT)); | |
+ if (sLog->GetSQLDriverQueryPrintErrors()) | |
+ sLog->outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error executing: [%u] %s", | |
+ index, m_connectionInfo.database.c_str(), lErrno, mysql_stmt_error(msql_STMT)); | |
if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled succesfuly (ie reconnection) | |
return _Query(stmt, pResult, pRowCount, pFieldCount); // Try again | |
@@ -283,8 +290,11 @@ | |
} | |
if (sLog->GetSQLDriverQueryLogging()) | |
- sLog->outSQLDriver("[%u ms] Prepared SQL: %u on database `%s`", | |
- getMSTimeDiff(_s, getMSTime()), index, m_connectionInfo.database.c_str()); | |
+ { | |
+ uint32 _diff = getMSTimeDiff(_s, getMSTime()); | |
+ if (_diff >= sLog->GetSQLDriverQuertMinDiff()) | |
+ sLog->outSQLDriver("[%u ms] Prepared SQL: %u on database `%s`", _diff, index, m_connectionInfo.database.c_str()); | |
+ } | |
m_mStmt->ClearParameters(); | |
@@ -326,8 +336,11 @@ | |
if (mysql_query(m_Mysql, sql)) | |
{ | |
uint32 lErrno = mysql_errno(m_Mysql); | |
- sLog->outSQLDriver("SQL: %s", sql); | |
- sLog->outSQLDriver("ERROR: [%u] %s", lErrno, mysql_error(m_Mysql)); | |
+ if (sLog->GetSQLDriverQueryPrintErrors()) | |
+ { | |
+ sLog->outSQLDriver("SQL: %s", sql); | |
+ sLog->outSQLDriver("ERROR: [%u] %s", lErrno, mysql_error(m_Mysql)); | |
+ } | |
if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled succesfuly (ie reconnection) | |
return _Query(sql, pResult, pFields, pRowCount, pFieldCount); // We try again | |
@@ -336,7 +349,9 @@ | |
} | |
else if (sLog->GetSQLDriverQueryLogging()) | |
{ | |
- sLog->outSQLDriver("[%u ms] SQL: %s", getMSTimeDiff(_s,getMSTime()), sql); | |
+ uint32 _diff = getMSTimeDiff(_s, getMSTime()); | |
+ if (_diff >= sLog->GetSQLDriverQuertMinDiff()) | |
+ sLog->outSQLDriver("[%u ms] SQL: %s", _diff, sql); | |
} | |
*pResult = mysql_store_result(m_Mysql); | |
diff -r ffa6d09ad28f src/server/shared/Database/DatabaseWorkerPool.h | |
--- a/src/server/shared/Database/DatabaseWorkerPool.h Wed Jan 05 23:38:19 2011 +0200 | |
+++ b/src/server/shared/Database/DatabaseWorkerPool.h Wed Jan 05 23:52:39 2011 +0200 | |
@@ -335,7 +335,7 @@ | |
//! were appended to the transaction will be respected during execution. | |
void CommitTransaction(SQLTransaction transaction) | |
{ | |
- if (sLog->GetSQLDriverQueryLogging()) | |
+ if (sLog->GetSQLDriverQueryLogging() && sLog->GetSQLDriverQueryPrintErrors()) | |
{ | |
switch (transaction->GetSize()) | |
{ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment