* Correctly implement database logging in WorldLog.
* This fixes LogDB.World config option. --HG-- branch : trunk
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
#include "WorldLog.h"
|
#include "WorldLog.h"
|
||||||
#include "Policies/SingletonImp.h"
|
#include "Policies/SingletonImp.h"
|
||||||
#include "Config/ConfigEnv.h"
|
#include "Config/ConfigEnv.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
#define CLASS_LOCK Trinity::ClassLevelLockable<WorldLog, ZThread::FastMutex>
|
#define CLASS_LOCK Trinity::ClassLevelLockable<WorldLog, ZThread::FastMutex>
|
||||||
INSTANTIATE_SINGLETON_2(WorldLog, CLASS_LOCK);
|
INSTANTIATE_SINGLETON_2(WorldLog, CLASS_LOCK);
|
||||||
@@ -32,6 +33,18 @@ INSTANTIATE_CLASS_MUTEX(WorldLog, ZThread::FastMutex);
|
|||||||
|
|
||||||
#define WORLD_LOG_FILE_STRING "world.log"
|
#define WORLD_LOG_FILE_STRING "world.log"
|
||||||
|
|
||||||
|
WorldLog::WorldLog() : i_file(NULL)
|
||||||
|
{
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
WorldLog::~WorldLog()
|
||||||
|
{
|
||||||
|
if( i_file != NULL )
|
||||||
|
fclose(i_file);
|
||||||
|
i_file = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/// Open the log file (if specified so in the configuration file)
|
/// Open the log file (if specified so in the configuration file)
|
||||||
void WorldLog::Initialize()
|
void WorldLog::Initialize()
|
||||||
{
|
{
|
||||||
@@ -48,6 +61,35 @@ void WorldLog::Initialize()
|
|||||||
{
|
{
|
||||||
i_file = fopen((logsDir+logname).c_str(), "w");
|
i_file = fopen((logsDir+logname).c_str(), "w");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_dbWorld = sConfig.GetBoolDefault("LogDB.World", false); // can be VERY heavy if enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldLog::outLog(char const *fmt, ...)
|
||||||
|
{
|
||||||
|
if( LogWorld() )
|
||||||
|
{
|
||||||
|
Guard guard(*this);
|
||||||
|
ASSERT(i_file);
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
vfprintf(i_file, fmt, args);
|
||||||
|
fprintf(i_file, "\n\n" );
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
fflush(i_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sLog.GetLogDB() && m_dbWorld)
|
||||||
|
{
|
||||||
|
va_list ap2;
|
||||||
|
va_start(ap2, fmt);
|
||||||
|
char nnew_str[MAX_QUERY_LEN];
|
||||||
|
vsnprintf(nnew_str, MAX_QUERY_LEN, fmt, ap2);
|
||||||
|
sLog.outDB(LOG_TYPE_WORLD, nnew_str);
|
||||||
|
va_end(ap2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define sWorldLog WorldLog::Instance()
|
#define sWorldLog WorldLog::Instance()
|
||||||
|
|||||||
+5
-22
@@ -35,42 +35,25 @@
|
|||||||
class TRINITY_DLL_DECL WorldLog : public Trinity::Singleton<WorldLog, Trinity::ClassLevelLockable<WorldLog, ZThread::FastMutex> >
|
class TRINITY_DLL_DECL WorldLog : public Trinity::Singleton<WorldLog, Trinity::ClassLevelLockable<WorldLog, ZThread::FastMutex> >
|
||||||
{
|
{
|
||||||
friend class Trinity::OperatorNew<WorldLog>;
|
friend class Trinity::OperatorNew<WorldLog>;
|
||||||
WorldLog() : i_file(NULL) { Initialize(); }
|
WorldLog();
|
||||||
WorldLog(const WorldLog &);
|
WorldLog(const WorldLog &);
|
||||||
WorldLog& operator=(const WorldLog &);
|
WorldLog& operator=(const WorldLog &);
|
||||||
typedef Trinity::ClassLevelLockable<WorldLog, ZThread::FastMutex>::Lock Guard;
|
typedef Trinity::ClassLevelLockable<WorldLog, ZThread::FastMutex>::Lock Guard;
|
||||||
|
|
||||||
/// Close the file in destructor
|
/// Close the file in destructor
|
||||||
~WorldLog()
|
~WorldLog();
|
||||||
{
|
|
||||||
if( i_file != NULL )
|
|
||||||
fclose(i_file);
|
|
||||||
i_file = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Initialize();
|
void Initialize();
|
||||||
/// Is the world logger active?
|
/// Is the world logger active?
|
||||||
bool LogWorld(void) const { return (i_file != NULL); }
|
bool LogWorld(void) const { return (i_file != NULL); }
|
||||||
/// %Log to the file
|
/// %Log to the file
|
||||||
void Log(char const *fmt, ...)
|
void outLog(char const *fmt, ...);
|
||||||
{
|
|
||||||
if( LogWorld() )
|
|
||||||
{
|
|
||||||
Guard guard(*this);
|
|
||||||
ASSERT(i_file);
|
|
||||||
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
vfprintf(i_file, fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
fflush(i_file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FILE *i_file;
|
FILE *i_file;
|
||||||
|
|
||||||
|
bool m_dbWorld;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define sWorldLog WorldLog::Instance()
|
#define sWorldLog WorldLog::Instance()
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ int WorldSocket::SendPacket (const WorldPacket& pct)
|
|||||||
// Dump outgoing packet.
|
// Dump outgoing packet.
|
||||||
if (sWorldLog.LogWorld ())
|
if (sWorldLog.LogWorld ())
|
||||||
{
|
{
|
||||||
sWorldLog.Log ("SERVER:\nSOCKET: %u\nLENGTH: %u\nOPCODE: %s (0x%.4X)\nDATA:\n",
|
sWorldLog.outLog ("SERVER:\nSOCKET: %u\nLENGTH: %u\nOPCODE: %s (0x%.4X)\nDATA:\n",
|
||||||
(uint32) get_handle (),
|
(uint32) get_handle (),
|
||||||
pct.size (),
|
pct.size (),
|
||||||
LookupOpcodeName (pct.GetOpcode ()),
|
LookupOpcodeName (pct.GetOpcode ()),
|
||||||
@@ -180,12 +180,12 @@ int WorldSocket::SendPacket (const WorldPacket& pct)
|
|||||||
while (p < pct.size ())
|
while (p < pct.size ())
|
||||||
{
|
{
|
||||||
for (uint32 j = 0; j < 16 && p < pct.size (); j++)
|
for (uint32 j = 0; j < 16 && p < pct.size (); j++)
|
||||||
sWorldLog.Log ("%.2X ", const_cast<WorldPacket&>(pct)[p++]);
|
sWorldLog.outLog ("%.2X ", const_cast<WorldPacket&>(pct)[p++]);
|
||||||
|
|
||||||
sWorldLog.Log ("\n");
|
sWorldLog.outLog ("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
sWorldLog.Log ("\n\n");
|
sWorldLog.outLog ("\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerPktHeader header(pct.size()+2, pct.GetOpcode());
|
ServerPktHeader header(pct.size()+2, pct.GetOpcode());
|
||||||
@@ -681,7 +681,7 @@ int WorldSocket::ProcessIncoming (WorldPacket* new_pct)
|
|||||||
// Dump received packet.
|
// Dump received packet.
|
||||||
if (sWorldLog.LogWorld ())
|
if (sWorldLog.LogWorld ())
|
||||||
{
|
{
|
||||||
sWorldLog.Log ("CLIENT:\nSOCKET: %u\nLENGTH: %u\nOPCODE: %s (0x%.4X)\nDATA:\n",
|
sWorldLog.outLog ("CLIENT:\nSOCKET: %u\nLENGTH: %u\nOPCODE: %s (0x%.4X)\nDATA:\n",
|
||||||
(uint32) get_handle (),
|
(uint32) get_handle (),
|
||||||
new_pct->size (),
|
new_pct->size (),
|
||||||
LookupOpcodeName (new_pct->GetOpcode ()),
|
LookupOpcodeName (new_pct->GetOpcode ()),
|
||||||
@@ -691,10 +691,10 @@ int WorldSocket::ProcessIncoming (WorldPacket* new_pct)
|
|||||||
while (p < new_pct->size ())
|
while (p < new_pct->size ())
|
||||||
{
|
{
|
||||||
for (uint32 j = 0; j < 16 && p < new_pct->size (); j++)
|
for (uint32 j = 0; j < 16 && p < new_pct->size (); j++)
|
||||||
sWorldLog.Log ("%.2X ", (*new_pct)[p++]);
|
sWorldLog.outLog ("%.2X ", (*new_pct)[p++]);
|
||||||
sWorldLog.Log ("\n");
|
sWorldLog.outLog ("\n");
|
||||||
}
|
}
|
||||||
sWorldLog.Log ("\n\n");
|
sWorldLog.outLog ("\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// like one switch ;)
|
// like one switch ;)
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Policies/SingletonImp.h"
|
#include "Policies/SingletonImp.h"
|
||||||
#include "Database/DatabaseEnv.h"
|
|
||||||
#include "Config/ConfigEnv.h"
|
#include "Config/ConfigEnv.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "Policies/Singleton.h"
|
#include "Policies/Singleton.h"
|
||||||
|
#include "Database/DatabaseEnv.h"
|
||||||
|
|
||||||
class Config;
|
class Config;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user