mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-24 02:46:33 +01:00
Core/Logging:
- Implement sLog.outSQLDriver that will log SQL driver related events (non-content related). - Queries will now be logged into this file as well instead of normal log file (requires debug build). - Don´t forget to update your authserver.conf and worldserver.conf Core/build: - Fix non-PCH build --HG-- branch : trunk
This commit is contained in:
@@ -39,6 +39,11 @@
|
||||
# Default: "realmd.log"
|
||||
# "" - Empty name disable creating log file
|
||||
#
|
||||
# SQLDriverLogFile
|
||||
# Log file of SQL driver events.
|
||||
# For effective query logging you need to build in debug configuration.
|
||||
# Default: "" - Empty name for disable
|
||||
#
|
||||
# LogTimestamp
|
||||
# Logfile with timestamp of server start in name
|
||||
# in form Logname_YYYY-MM-DD_HH-MM-SS.Ext for Logname.Ext
|
||||
@@ -123,6 +128,7 @@ BindIP = "0.0.0.0"
|
||||
PidFile = ""
|
||||
LogLevel = 0
|
||||
LogFile = "auth.log"
|
||||
SQLDriverLogFile = ""
|
||||
LogTimestamp = 0
|
||||
LogFileLevel = 0
|
||||
LogColors = ""
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "DatabaseEnv.h"
|
||||
#include "DatabaseWorker.h"
|
||||
#include "DatabaseWorkerPool.h"
|
||||
#include "MySQLConnection.h"
|
||||
#include "SQLOperation.h"
|
||||
@@ -38,7 +39,7 @@ DatabaseWorkerPool::~DatabaseWorkerPool()
|
||||
|
||||
bool DatabaseWorkerPool::Open(const std::string& infoString, uint8 num_threads)
|
||||
{
|
||||
sLog.outDebug("Creating bundled/master MySQL connection.");
|
||||
sLog.outSQLDriver("Creating bundled/master MySQL connection.");
|
||||
m_bundle_conn = new MySQLConnection();
|
||||
m_bundle_conn->Open(infoString);
|
||||
++m_connections;
|
||||
@@ -51,7 +52,7 @@ bool DatabaseWorkerPool::Open(const std::string& infoString, uint8 num_threads)
|
||||
m_async_connections[i] = new MySQLConnection(m_queue);
|
||||
m_async_connections[i]->Open(infoString);
|
||||
++m_connections;
|
||||
sLog.outDebug("Async database thread pool opened. Worker thread count: %u", num_threads);
|
||||
sLog.outSQLDriver("Async database thread pool opened. Worker thread count: %u", num_threads);
|
||||
}
|
||||
|
||||
m_infoString = infoString;
|
||||
@@ -60,7 +61,7 @@ bool DatabaseWorkerPool::Open(const std::string& infoString, uint8 num_threads)
|
||||
|
||||
void DatabaseWorkerPool::Close()
|
||||
{
|
||||
sLog.outStaticDebug("Closing down %u connections on this DatabaseWorkerPool", (uint32)m_connections.value());
|
||||
sLog.outSQLDriver("Closing down %u connections on this DatabaseWorkerPool", (uint32)m_connections.value());
|
||||
/// Shuts down worker threads for this connection pool.
|
||||
m_queue->queue()->deactivate();
|
||||
|
||||
@@ -73,14 +74,14 @@ void DatabaseWorkerPool::Close()
|
||||
delete m_bundle_conn;
|
||||
m_bundle_conn = NULL;
|
||||
--m_connections;
|
||||
sLog.outStaticDebug("Closed bundled connection.");
|
||||
sLog.outSQLDriver("Closed bundled connection.");
|
||||
|
||||
//- MySQL::Thread_End() should be called manually from the aborting calling threads
|
||||
sLog.outStaticDebug("Waiting for %u synchroneous database threads to exit.", (uint32)m_connections.value());
|
||||
sLog.outSQLDriver("Waiting for %u synchroneous database threads to exit.", (uint32)m_connections.value());
|
||||
while (!m_sync_connections.empty())
|
||||
{
|
||||
}
|
||||
sLog.outStaticDebug("Synchroneous database threads exited succesfuly.");
|
||||
sLog.outSQLDriver("Synchroneous database threads exited succesfuly.");
|
||||
}
|
||||
|
||||
/*! This function creates a new MySQL connection for every MapUpdate thread
|
||||
@@ -96,12 +97,12 @@ void DatabaseWorkerPool::Init_MySQL_Connection()
|
||||
ConnectionMap::const_iterator itr = m_sync_connections.find(ACE_Based::Thread::current());
|
||||
#ifdef _DEBUG
|
||||
if (itr != m_sync_connections.end())
|
||||
sLog.outError("Thread ["UI64FMTD"] already started a MySQL connection", (uint64)ACE_Based::Thread::currentId());
|
||||
sLog.outSQLDriver("Thread ["UI64FMTD"] already started a MySQL connection", (uint64)ACE_Based::Thread::currentId());
|
||||
#endif
|
||||
m_sync_connections[ACE_Based::Thread::current()] = conn;
|
||||
}
|
||||
|
||||
sLog.outDebug("Core thread with ID ["UI64FMTD"] initializing MySQL connection.",
|
||||
sLog.outSQLDriver("Core thread with ID ["UI64FMTD"] initializing MySQL connection.",
|
||||
(uint64)ACE_Based::Thread::currentId());
|
||||
|
||||
++m_connections;
|
||||
@@ -115,7 +116,7 @@ void DatabaseWorkerPool::End_MySQL_Connection()
|
||||
ConnectionMap::iterator itr = m_sync_connections.find(ACE_Based::Thread::current());
|
||||
#ifdef _DEBUG
|
||||
if (itr == m_sync_connections.end())
|
||||
sLog.outError("Thread ["UI64FMTD" already shut down their MySQL connection.", (uint64)ACE_Based::Thread::currentId());
|
||||
sLog.outSQLDriver("Thread ["UI64FMTD"] already shut down their MySQL connection.", (uint64)ACE_Based::Thread::currentId());
|
||||
#endif
|
||||
conn = itr->second;
|
||||
m_sync_connections.erase(itr);
|
||||
@@ -197,12 +198,12 @@ void DatabaseWorkerPool::CommitTransaction(SQLTransaction transaction)
|
||||
#ifdef _DEBUG
|
||||
if (transaction->GetSize() == 0)
|
||||
{
|
||||
sLog.outError("Transaction contains 0 queries");
|
||||
sLog.outSQLDriver("Transaction contains 0 queries. Not executing.");
|
||||
return;
|
||||
}
|
||||
if (transaction->GetSize() == 1)
|
||||
{
|
||||
sLog.outDetail("Warning: Transaction only holds 1 query, consider removing Transaction context in code.");
|
||||
sLog.outSQLDriver("Warning: Transaction only holds 1 query, consider removing Transaction context in code.");
|
||||
}
|
||||
#endif
|
||||
Enqueue(new TransactionTask(transaction));
|
||||
|
||||
@@ -120,13 +120,13 @@ bool MySQLConnection::Open(const std::string& infoString)
|
||||
if (m_Mysql)
|
||||
{
|
||||
sLog.outDetail("Connected to MySQL database at %s", host.c_str());
|
||||
sLog.outString("MySQL client library: %s", mysql_get_client_info());
|
||||
sLog.outString("MySQL server ver: %s ", mysql_get_server_info( m_Mysql));
|
||||
sLog.outSQLDriver("MySQL client library: %s", mysql_get_client_info());
|
||||
sLog.outSQLDriver("MySQL server ver: %s ", mysql_get_server_info( m_Mysql));
|
||||
|
||||
if (!mysql_autocommit(m_Mysql, 1))
|
||||
sLog.outDetail("AUTOCOMMIT SUCCESSFULLY SET TO 1");
|
||||
sLog.outSQLDriver("AUTOCOMMIT SUCCESSFULLY SET TO 1");
|
||||
else
|
||||
sLog.outDetail("AUTOCOMMIT NOT SET TO 1");
|
||||
sLog.outSQLDriver("AUTOCOMMIT NOT SET TO 1");
|
||||
|
||||
// set connection properties to UTF8 to properly handle locales for different
|
||||
// server configs - core sends data in UTF8, so MySQL must expect UTF8 too
|
||||
@@ -136,9 +136,9 @@ bool MySQLConnection::Open(const std::string& infoString)
|
||||
#if MYSQL_VERSION_ID >= 50003
|
||||
my_bool my_true = (my_bool)1;
|
||||
if (mysql_options(m_Mysql, MYSQL_OPT_RECONNECT, &my_true))
|
||||
sLog.outDetail("Failed to turn on MYSQL_OPT_RECONNECT.");
|
||||
sLog.outSQLDriver("Failed to turn on MYSQL_OPT_RECONNECT.");
|
||||
else
|
||||
sLog.outDetail("Successfully turned on MYSQL_OPT_RECONNECT.");
|
||||
sLog.outSQLDriver("Successfully turned on MYSQL_OPT_RECONNECT.");
|
||||
#else
|
||||
#warning "Your mySQL client lib version does not support reconnecting after a timeout.\nIf this causes you any trouble we advice you to upgrade your mySQL client libs to at least mySQL 5.0.13 to resolve this problem."
|
||||
#endif
|
||||
@@ -166,14 +166,14 @@ bool MySQLConnection::Execute(const char* sql)
|
||||
#endif
|
||||
if (mysql_query(m_Mysql, sql))
|
||||
{
|
||||
sLog.outErrorDb("SQL: %s", sql);
|
||||
sLog.outErrorDb("SQL ERROR: %s", mysql_error(m_Mysql));
|
||||
sLog.outSQLDriver("SQL: %s", sql);
|
||||
sLog.outSQLDriver("SQL ERROR: %s", mysql_error(m_Mysql));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef TRINITY_DEBUG
|
||||
sLog.outDebug("[%u ms] SQL: %s", getMSTimeDiff(_s, getMSTime()), sql);
|
||||
sLog.outSQLDriver("[%u ms] SQL: %s", getMSTimeDiff(_s, getMSTime()), sql);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -214,14 +214,14 @@ bool MySQLConnection::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD *
|
||||
#endif
|
||||
if (mysql_query(m_Mysql, sql))
|
||||
{
|
||||
sLog.outErrorDb("SQL: %s", sql);
|
||||
sLog.outErrorDb("query ERROR: %s", mysql_error(m_Mysql));
|
||||
sLog.outSQLDriver("SQL: %s", sql);
|
||||
sLog.outSQLDriver("query ERROR: %s", mysql_error(m_Mysql));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef TRINITY_DEBUG
|
||||
sLog.outDebug("[%u ms] SQL: %s", getMSTimeDiff(_s,getMSTime()), sql);
|
||||
sLog.outSQLDriver("[%u ms] SQL: %s", getMSTimeDiff(_s,getMSTime()), sql);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ bool TransactionTask::Execute()
|
||||
sql = queries.front();
|
||||
if (!m_conn->Execute(sql))
|
||||
{
|
||||
sLog.outSQLDriver("[Warning] Transaction aborted. %u queries not executed.", (uint32)queries.size());
|
||||
free((void*)const_cast<char*>(sql));
|
||||
queries.pop();
|
||||
m_conn->RollbackTransaction();
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
Log::Log() :
|
||||
raLogfile(NULL), logfile(NULL), gmLogfile(NULL), charLogfile(NULL),
|
||||
dberLogfile(NULL), chatLogfile(NULL), arenaLogFile(NULL),
|
||||
dberLogfile(NULL), chatLogfile(NULL), arenaLogFile(NULL), sqlLogFile(NULL),
|
||||
m_gmlog_per_account(false), m_enableLogDBLater(false),
|
||||
m_enableLogDB(false), m_colored(false)
|
||||
{
|
||||
@@ -64,6 +64,10 @@ Log::~Log()
|
||||
if (arenaLogFile != NULL)
|
||||
fclose(arenaLogFile);
|
||||
arenaLogFile = NULL;
|
||||
|
||||
if (sqlLogFile != NULL)
|
||||
fclose(sqlLogFile);
|
||||
sqlLogFile = NULL;
|
||||
}
|
||||
|
||||
void Log::SetLogLevel(char *Level)
|
||||
@@ -150,12 +154,12 @@ void Log::Initialize()
|
||||
}
|
||||
}
|
||||
|
||||
charLogfile = openLogFile("CharLogFile","CharLogTimestamp","a");
|
||||
|
||||
dberLogfile = openLogFile("DBErrorLogFile",NULL,"a");
|
||||
raLogfile = openLogFile("RaLogFile",NULL,"a");
|
||||
chatLogfile = openLogFile("ChatLogFile","ChatLogTimestamp","a");
|
||||
arenaLogFile = openLogFile("ArenaLogFile",NULL,"a");
|
||||
charLogfile = openLogFile("CharLogFile", "CharLogTimestamp", "a");
|
||||
dberLogfile = openLogFile("DBErrorLogFile", NULL, "a");
|
||||
raLogfile = openLogFile("RaLogFile", NULL, "a");
|
||||
chatLogfile = openLogFile("ChatLogFile", "ChatLogTimestamp", "a");
|
||||
arenaLogFile = openLogFile("ArenaLogFile", NULL,"a");
|
||||
sqlLogFile = openLogFile("SQLDriverLogFile", NULL, "a");
|
||||
|
||||
// Main log file settings
|
||||
m_logLevel = sConfig.GetIntDefault("LogLevel", LOGL_NORMAL);
|
||||
@@ -529,6 +533,30 @@ void Log::outArena(const char * str, ...)
|
||||
}
|
||||
}
|
||||
|
||||
void Log::outSQLDriver(const char* str, ...)
|
||||
{
|
||||
if (!str)
|
||||
return;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, str);
|
||||
vutf8printf(stdout, str, &ap);
|
||||
va_end(ap);
|
||||
|
||||
printf("\n");
|
||||
if (sqlLogFile)
|
||||
{
|
||||
outTimestamp(sqlLogFile);
|
||||
va_start(ap, str);
|
||||
vfprintf(sqlLogFile, str, ap);
|
||||
fprintf(sqlLogFile, "\n");
|
||||
va_end(ap);
|
||||
|
||||
fflush(sqlLogFile);
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void Log::outErrorDb(const char * err, ...)
|
||||
{
|
||||
if (!err)
|
||||
|
||||
@@ -112,6 +112,7 @@ class Log
|
||||
void outRemote( const char * str, ... ) ATTR_PRINTF(2,3);
|
||||
void outChat( const char * str, ... ) ATTR_PRINTF(2,3);
|
||||
void outArena( const char * str, ... ) ATTR_PRINTF(2,3);
|
||||
void outSQLDriver( const char* str, ... ) ATTR_PRINTF(2,3);
|
||||
void outCharDump( const char * str, uint32 account_id, uint32 guid, const char * name );
|
||||
|
||||
static void outTimestamp(FILE* file);
|
||||
@@ -141,6 +142,7 @@ class Log
|
||||
FILE* dberLogfile;
|
||||
FILE* chatLogfile;
|
||||
FILE* arenaLogFile;
|
||||
FILE* sqlLogFile;
|
||||
|
||||
// cache values for after initilization use (like gm log per account case)
|
||||
std::string m_logsDir;
|
||||
|
||||
@@ -412,6 +412,11 @@ CleanCharacterDB = 0
|
||||
# Log file of arena fights and arena team creations
|
||||
# Default: "" - do not create arena log file
|
||||
#
|
||||
# SQLDriverLogFile
|
||||
# Log file of SQL driver events.
|
||||
# For effective query logging you need to build in debug configuration.
|
||||
# Default: "" - Empty name for disable
|
||||
#
|
||||
# LogColors
|
||||
# Color for messages (format "normal basic detail debug")
|
||||
# Default: "" - no colors
|
||||
@@ -540,6 +545,7 @@ GmLogTimestamp = 0
|
||||
GmLogPerAccount = 0
|
||||
RaLogFile = "ra_commands.log"
|
||||
ArenaLogFile = ""
|
||||
SQLDriverLogFile = ""
|
||||
LogColors = ""
|
||||
EnableLogDB = 0
|
||||
DBLogLevel = 2
|
||||
|
||||
Reference in New Issue
Block a user