Core/Commands: Enable SQL query logging by config and command )patch by leak)
Closes issue 4853. --HG-- branch : trunk
This commit is contained in:
@@ -70,13 +70,6 @@ else()
|
||||
message("* Use coreside debug : No (default)")
|
||||
endif()
|
||||
|
||||
if( WITH_SQLDEBUG )
|
||||
message("* Use SQL-query logging : Yes")
|
||||
add_definitions(-DSQLQUERY_LOG)
|
||||
else()
|
||||
message("* Use SQL-query logging : No (default)")
|
||||
endif()
|
||||
|
||||
if( WIN32 )
|
||||
if( USE_MYSQL_SOURCES )
|
||||
message("* Use MySQL sourcetree : Yes (default)")
|
||||
|
||||
@@ -677,6 +677,7 @@ INSERT INTO `command` VALUES
|
||||
('server set motd',3,'Syntax: .server set motd $MOTD\r\n\r\nSet server Message of the day.'),
|
||||
('server shutdown',3,'Syntax: .server shutdown #delay [#exit_code]\r\n\r\nShut the server down after #delay seconds. Use #exit_code or 0 as program exit code.'),
|
||||
('server shutdown cancel',3,'Syntax: .server shutdown cancel\r\n\r\nCancel the restart/shutdown timer if any.'),
|
||||
('server togglequerylog',4,'Toggle SQL driver query logging.'),
|
||||
('setskill',3,'Syntax: .setskill #skill #level [#max]\r\n\r\nSet a skill of id #skill with a current skill value of #level and a maximum value of #max (or equal current maximum if not provide) for the selected character. If no character is selected, you learn the skill.'),
|
||||
('showarea',3,'Syntax: .showarea #areaid\r\n\r\nReveal the area of #areaid to the selected character. If no character is selected, reveal this area to you.'),
|
||||
('start',0,'Syntax: .start\r\n\r\nTeleport you to the starting area of your character.'),
|
||||
@@ -27693,6 +27694,8 @@ INSERT INTO `trinity_string` (`entry`,`content_default`,`content_loc1`,`content_
|
||||
(1024, 'Character ''%s'' (GUID: %u Account %u) can''t be restored: account character list full!', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
(1025, 'Character ''%s'' (GUID: %u Account %u) can''t be restored: new name already used!', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
(1026, 'GUID: %u Name: %s Account: %s (%u) Date: %s', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
(1027, 'SQL driver query logging enabled.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
(1028, 'SQL driver query logging disabled.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
(1100, 'Account %s (Id: %u) have up to %u expansion allowed now.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
(1101, 'Message of the day changed to:\r\n%s', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
(1102, 'Message sent to %s: %s', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
DELETE FROM `command` WHERE `name` LIKE 'server togglequerylog';
|
||||
INSERT INTO `command` (`name`,`security`,`help`) VALUES
|
||||
('server togglequerylog',4,'Toggle SQL driver query logging.');
|
||||
@@ -0,0 +1,4 @@
|
||||
DELETE FROM `trinity_string` WHERE `entry` IN (1027, 1028);
|
||||
INSERT INTO `trinity_string` (`entry`, `content_default`) VALUES
|
||||
(1027, 'SQL driver query logging enabled.'),
|
||||
(1028, 'SQL driver query logging disabled.');
|
||||
@@ -301,17 +301,18 @@ ChatCommand * ChatHandler::getCommandTable()
|
||||
|
||||
static ChatCommand serverCommandTable[] =
|
||||
{
|
||||
{ "corpses", SEC_GAMEMASTER, true, OldHandler<&ChatHandler::HandleServerCorpsesCommand>, "", NULL },
|
||||
{ "exit", SEC_CONSOLE, true, OldHandler<&ChatHandler::HandleServerExitCommand>, "", NULL },
|
||||
{ "idlerestart", SEC_ADMINISTRATOR, true, NULL, "", serverIdleRestartCommandTable },
|
||||
{ "idleshutdown", SEC_ADMINISTRATOR, true, NULL, "", serverShutdownCommandTable },
|
||||
{ "info", SEC_PLAYER, true, OldHandler<&ChatHandler::HandleServerInfoCommand>, "", NULL },
|
||||
{ "motd", SEC_PLAYER, true, OldHandler<&ChatHandler::HandleServerMotdCommand>, "", NULL },
|
||||
{ "plimit", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleServerPLimitCommand>, "", NULL },
|
||||
{ "restart", SEC_ADMINISTRATOR, true, NULL, "", serverRestartCommandTable },
|
||||
{ "shutdown", SEC_ADMINISTRATOR, true, NULL, "", serverShutdownCommandTable },
|
||||
{ "set", SEC_ADMINISTRATOR, true, NULL, "", serverSetCommandTable },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
{ "corpses", SEC_GAMEMASTER, true, OldHandler<&ChatHandler::HandleServerCorpsesCommand>, "", NULL },
|
||||
{ "exit", SEC_CONSOLE, true, OldHandler<&ChatHandler::HandleServerExitCommand>, "", NULL },
|
||||
{ "idlerestart", SEC_ADMINISTRATOR, true, NULL, "", serverIdleRestartCommandTable },
|
||||
{ "idleshutdown", SEC_ADMINISTRATOR, true, NULL, "", serverShutdownCommandTable },
|
||||
{ "info", SEC_PLAYER, true, OldHandler<&ChatHandler::HandleServerInfoCommand>, "", NULL },
|
||||
{ "motd", SEC_PLAYER, true, OldHandler<&ChatHandler::HandleServerMotdCommand>, "", NULL },
|
||||
{ "plimit", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandleServerPLimitCommand>, "", NULL },
|
||||
{ "restart", SEC_ADMINISTRATOR, true, NULL, "", serverRestartCommandTable },
|
||||
{ "shutdown", SEC_ADMINISTRATOR, true, NULL, "", serverShutdownCommandTable },
|
||||
{ "set", SEC_ADMINISTRATOR, true, NULL, "", serverSetCommandTable },
|
||||
{ "togglequerylog", SEC_CONSOLE, true, OldHandler<&ChatHandler::HandleServerToggleQueryLogging>, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand unbanCommandTable[] =
|
||||
|
||||
@@ -236,6 +236,7 @@ class ChatHandler
|
||||
bool HandleServerShutDownCommand(const char* args);
|
||||
bool HandleServerShutDownCancelCommand(const char* args);
|
||||
bool HandleServerSetClosedCommand(const char* args);
|
||||
bool HandleServerToggleQueryLogging(const char* args);
|
||||
|
||||
bool HandleServerSetLogFileLevelCommand(const char* args);
|
||||
bool HandleServerSetDiffTimeCommand(const char* args);
|
||||
|
||||
@@ -760,7 +760,9 @@ enum TrinityStrings
|
||||
LANG_CHARACTER_DELETED_SKIP_FULL = 1024,
|
||||
LANG_CHARACTER_DELETED_SKIP_NAME = 1025,
|
||||
LANG_CHARACTER_DELETED_LIST_LINE_CHAT = 1026,
|
||||
// Room for more level 4 1027-1099 not used
|
||||
LANG_SQLDRIVER_QUERY_LOGGING_ENABLED = 1027,
|
||||
LANG_SQLDRIVER_QUERY_LOGGING_DISABLED = 1028,
|
||||
// Room for more level 4 1029-1099 not used
|
||||
|
||||
// Level 3 (continue)
|
||||
LANG_ACCOUNT_SETADDON = 1100,
|
||||
|
||||
@@ -254,17 +254,18 @@ class DatabaseWorkerPool
|
||||
|
||||
void CommitTransaction(SQLTransaction transaction)
|
||||
{
|
||||
#ifdef SQLQUERY_LOG
|
||||
if (transaction->GetSize() == 0)
|
||||
if (sLog.GetSQLDriverQueryLogging())
|
||||
{
|
||||
sLog.outSQLDriver("Transaction contains 0 queries. Not executing.");
|
||||
return;
|
||||
if (transaction->GetSize() == 0)
|
||||
{
|
||||
sLog.outSQLDriver("Transaction contains 0 queries. Not executing.");
|
||||
return;
|
||||
}
|
||||
if (transaction->GetSize() == 1)
|
||||
{
|
||||
sLog.outSQLDriver("Warning: Transaction only holds 1 query, consider removing Transaction context in code.");
|
||||
}
|
||||
}
|
||||
if (transaction->GetSize() == 1)
|
||||
{
|
||||
sLog.outSQLDriver("Warning: Transaction only holds 1 query, consider removing Transaction context in code.");
|
||||
}
|
||||
#endif
|
||||
Enqueue(new TransactionTask(transaction));
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "PreparedStatement.h"
|
||||
#include "DatabaseWorker.h"
|
||||
#include "Timer.h"
|
||||
#include "Log.h"
|
||||
|
||||
MySQLConnection::MySQLConnection(MySQLConnectionInfo& connInfo) :
|
||||
m_queue(NULL),
|
||||
@@ -154,20 +155,19 @@ bool MySQLConnection::Execute(const char* sql)
|
||||
return false;
|
||||
|
||||
{
|
||||
#ifdef SQLQUERY_LOG
|
||||
uint32 _s = getMSTime();
|
||||
#endif
|
||||
uint32 _s;
|
||||
if (sLog.GetSQLDriverQueryLogging())
|
||||
_s = getMSTime();
|
||||
|
||||
if (mysql_query(m_Mysql, sql))
|
||||
{
|
||||
sLog.outSQLDriver("SQL: %s", sql);
|
||||
sLog.outSQLDriver("SQL ERROR: %s", mysql_error(m_Mysql));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
else if (sLog.GetSQLDriverQueryLogging())
|
||||
{
|
||||
#ifdef SQLQUERY_LOG
|
||||
sLog.outSQLDriver("[%u ms] SQL: %s", getMSTimeDiff(_s, getMSTime()), sql);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,9 +191,10 @@ bool MySQLConnection::Execute(PreparedStatement* stmt)
|
||||
MYSQL_STMT* msql_STMT = m_mStmt->GetSTMT();
|
||||
MYSQL_BIND* msql_BIND = m_mStmt->GetBind();
|
||||
|
||||
#ifdef SQLQUERY_LOG
|
||||
uint32 _s = getMSTime();
|
||||
#endif
|
||||
uint32 _s;
|
||||
if (sLog.GetSQLDriverQueryLogging())
|
||||
_s = getMSTime();
|
||||
|
||||
if (mysql_stmt_bind_param(msql_STMT, msql_BIND))
|
||||
{
|
||||
sLog.outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error binding params: %s",
|
||||
@@ -209,11 +210,11 @@ bool MySQLConnection::Execute(PreparedStatement* stmt)
|
||||
m_mStmt->ClearParameters();
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef SQLQUERY_LOG
|
||||
sLog.outSQLDriver("[%u ms] Prepared SQL: %u on database `%s`",
|
||||
getMSTimeDiff(_s, getMSTime()), index, m_connectionInfo.database.c_str());
|
||||
#endif
|
||||
|
||||
if (sLog.GetSQLDriverQueryLogging())
|
||||
sLog.outSQLDriver("[%u ms] Prepared SQL: %u on database `%s`",
|
||||
getMSTimeDiff(_s, getMSTime()), index, m_connectionInfo.database.c_str());
|
||||
|
||||
m_mStmt->ClearParameters();
|
||||
return true;
|
||||
}
|
||||
@@ -236,9 +237,10 @@ bool MySQLConnection::_Query(PreparedStatement* stmt, MYSQL_RES **pResult, uint6
|
||||
MYSQL_STMT* msql_STMT = m_mStmt->GetSTMT();
|
||||
MYSQL_BIND* msql_BIND = m_mStmt->GetBind();
|
||||
|
||||
#ifdef SQLQUERY_LOG
|
||||
uint32 _s = getMSTime();
|
||||
#endif
|
||||
uint32 _s;
|
||||
if (sLog.GetSQLDriverQueryLogging())
|
||||
_s = getMSTime();
|
||||
|
||||
if (mysql_stmt_bind_param(msql_STMT, msql_BIND))
|
||||
{
|
||||
sLog.outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error binding params: %s",
|
||||
@@ -255,10 +257,10 @@ bool MySQLConnection::_Query(PreparedStatement* stmt, MYSQL_RES **pResult, uint6
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef SQLQUERY_LOG
|
||||
sLog.outSQLDriver("[%u ms] Prepared SQL: %u on database `%s`",
|
||||
getMSTimeDiff(_s, getMSTime()), index, m_connectionInfo.database.c_str());
|
||||
#endif
|
||||
if (sLog.GetSQLDriverQueryLogging())
|
||||
sLog.outSQLDriver("[%u ms] Prepared SQL: %u on database `%s`",
|
||||
getMSTimeDiff(_s, getMSTime()), index, m_connectionInfo.database.c_str());
|
||||
|
||||
m_mStmt->ClearParameters();
|
||||
|
||||
*pResult = mysql_stmt_result_metadata(msql_STMT);
|
||||
@@ -292,20 +294,19 @@ bool MySQLConnection::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD *
|
||||
return false;
|
||||
|
||||
{
|
||||
#ifdef SQLQUERY_LOG
|
||||
uint32 _s = getMSTime();
|
||||
#endif
|
||||
uint32 _s;
|
||||
if (sLog.GetSQLDriverQueryLogging())
|
||||
_s = getMSTime();
|
||||
|
||||
if (mysql_query(m_Mysql, sql))
|
||||
{
|
||||
sLog.outSQLDriver("SQL: %s", sql);
|
||||
sLog.outSQLDriver("query ERROR: %s", mysql_error(m_Mysql));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
else if (sLog.GetSQLDriverQueryLogging())
|
||||
{
|
||||
#ifdef SQLQUERY_LOG
|
||||
sLog.outSQLDriver("[%u ms] SQL: %s", getMSTimeDiff(_s,getMSTime()), sql);
|
||||
#endif
|
||||
}
|
||||
|
||||
*pResult = mysql_store_result(m_Mysql);
|
||||
|
||||
@@ -166,6 +166,7 @@ void Log::Initialize()
|
||||
m_logLevel = sConfig.GetIntDefault("LogLevel", LOGL_NORMAL);
|
||||
m_logFileLevel = sConfig.GetIntDefault("LogFileLevel", LOGL_NORMAL);
|
||||
m_dbLogLevel = sConfig.GetIntDefault("DBLogLevel", LOGL_NORMAL);
|
||||
m_sqlDriverQueryLogging = sConfig.GetBoolDefault("SQLDriverQueryLogging", false);
|
||||
|
||||
m_logFilter = 0;
|
||||
|
||||
|
||||
@@ -118,6 +118,7 @@ class Log
|
||||
void SetLogLevel(char * Level);
|
||||
void SetLogFileLevel(char * Level);
|
||||
void SetDBLogLevel(char * Level);
|
||||
void SetSQLDriverQueryLogging(bool newStatus) { m_sqlDriverQueryLogging = newStatus; }
|
||||
void SetRealmID(uint32 id) { realm = id; }
|
||||
|
||||
uint32 getLogFilter() const { return m_logFilter; }
|
||||
@@ -128,6 +129,7 @@ class Log
|
||||
bool GetLogDBLater() { return m_enableLogDBLater; }
|
||||
void SetLogDB(bool enable) { m_enableLogDB = enable; }
|
||||
void SetLogDBLater(bool value) { m_enableLogDBLater = value; }
|
||||
bool GetSQLDriverQueryLogging() { return m_sqlDriverQueryLogging; }
|
||||
private:
|
||||
FILE* openLogFile(char const* configFileName,char const* configTimeStampFlag, char const* mode);
|
||||
FILE* openGmlogPerAccount(uint32 account);
|
||||
@@ -157,6 +159,10 @@ class Log
|
||||
bool m_colored;
|
||||
ColorTypes m_colors[4];
|
||||
|
||||
// log levels:
|
||||
// false: errors only, true: full query logging
|
||||
bool m_sqlDriverQueryLogging;
|
||||
|
||||
// log levels:
|
||||
// 0 minimum/string, 1 basic/error, 2 detail, 3 full/debug
|
||||
uint8 m_dbLogLevel;
|
||||
|
||||
@@ -530,6 +530,18 @@ bool ChatHandler::HandleServerSetDiffTimeCommand(const char *args)
|
||||
return true;
|
||||
}
|
||||
|
||||
/// toggle sql driver query logging
|
||||
bool ChatHandler::HandleServerToggleQueryLogging(const char* /* args */)
|
||||
{
|
||||
sLog.SetSQLDriverQueryLogging(!sLog.GetSQLDriverQueryLogging());
|
||||
if(sLog.GetSQLDriverQueryLogging())
|
||||
PSendSysMessage(LANG_SQLDRIVER_QUERY_LOGGING_ENABLED);
|
||||
else
|
||||
PSendSysMessage(LANG_SQLDRIVER_QUERY_LOGGING_DISABLED);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
#ifdef linux
|
||||
|
||||
@@ -405,9 +405,14 @@ CleanCharacterDB = 0
|
||||
#
|
||||
# SQLDriverLogFile
|
||||
# Log file of SQL driver events.
|
||||
# For effective query logging you need to build in debug configuration.
|
||||
# For effective query logging you need to configure SQLDriverQueryLogging.
|
||||
# Default: "" - Empty name for disable
|
||||
#
|
||||
# SQLDriverQueryLogging
|
||||
# Log SQL queries to the SQLDriverLogFile and console
|
||||
# Default: 0 - disabled (Query errors only)
|
||||
# 1 - enabled (Full query logging - may have performance impact)
|
||||
#
|
||||
# LogColors
|
||||
# Color for messages (format "normal basic detail debug")
|
||||
# Default: "" - no colors
|
||||
@@ -538,6 +543,7 @@ RaLogFile = "ra_commands.log"
|
||||
ArenaLogFile = ""
|
||||
ArenaLog.ExtendedInfo = 0
|
||||
SQLDriverLogFile = ""
|
||||
SQLDriverQueryLogging = 0
|
||||
LogColors = ""
|
||||
EnableLogDB = 0
|
||||
DBLogLevel = 2
|
||||
|
||||
Reference in New Issue
Block a user