aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game/WorldLog.cpp42
-rw-r--r--src/game/WorldLog.h27
-rw-r--r--src/game/WorldSocket.cpp16
-rw-r--r--src/shared/Log.cpp1
-rw-r--r--src/shared/Log.h1
5 files changed, 56 insertions, 31 deletions
diff --git a/src/game/WorldLog.cpp b/src/game/WorldLog.cpp
index 7a10986f749..8e870585e9d 100644
--- a/src/game/WorldLog.cpp
+++ b/src/game/WorldLog.cpp
@@ -25,6 +25,7 @@
#include "WorldLog.h"
#include "Policies/SingletonImp.h"
#include "Config/ConfigEnv.h"
+#include "Log.h"
#define CLASS_LOCK Trinity::ClassLevelLockable<WorldLog, ZThread::FastMutex>
INSTANTIATE_SINGLETON_2(WorldLog, CLASS_LOCK);
@@ -32,6 +33,18 @@ INSTANTIATE_CLASS_MUTEX(WorldLog, ZThread::FastMutex);
#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)
void WorldLog::Initialize()
{
@@ -48,6 +61,35 @@ void WorldLog::Initialize()
{
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()
diff --git a/src/game/WorldLog.h b/src/game/WorldLog.h
index 97374ddc5f5..4ba651809ee 100644
--- a/src/game/WorldLog.h
+++ b/src/game/WorldLog.h
@@ -35,42 +35,25 @@
class TRINITY_DLL_DECL WorldLog : public Trinity::Singleton<WorldLog, Trinity::ClassLevelLockable<WorldLog, ZThread::FastMutex> >
{
friend class Trinity::OperatorNew<WorldLog>;
- WorldLog() : i_file(NULL) { Initialize(); }
+ WorldLog();
WorldLog(const WorldLog &);
WorldLog& operator=(const WorldLog &);
typedef Trinity::ClassLevelLockable<WorldLog, ZThread::FastMutex>::Lock Guard;
/// Close the file in destructor
- ~WorldLog()
- {
- if( i_file != NULL )
- fclose(i_file);
- i_file = NULL;
- }
+ ~WorldLog();
public:
void Initialize();
/// Is the world logger active?
bool LogWorld(void) const { return (i_file != NULL); }
/// %Log to the file
- void Log(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);
- }
- }
+ void outLog(char const *fmt, ...);
private:
FILE *i_file;
+
+ bool m_dbWorld;
};
#define sWorldLog WorldLog::Instance()
diff --git a/src/game/WorldSocket.cpp b/src/game/WorldSocket.cpp
index 077c7a0d7e9..0f975cf776f 100644
--- a/src/game/WorldSocket.cpp
+++ b/src/game/WorldSocket.cpp
@@ -170,7 +170,7 @@ int WorldSocket::SendPacket (const WorldPacket& pct)
// Dump outgoing packet.
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 (),
pct.size (),
LookupOpcodeName (pct.GetOpcode ()),
@@ -180,12 +180,12 @@ int WorldSocket::SendPacket (const WorldPacket& pct)
while (p < pct.size ())
{
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());
@@ -681,7 +681,7 @@ int WorldSocket::ProcessIncoming (WorldPacket* new_pct)
// Dump received packet.
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 (),
new_pct->size (),
LookupOpcodeName (new_pct->GetOpcode ()),
@@ -691,10 +691,10 @@ int WorldSocket::ProcessIncoming (WorldPacket* new_pct)
while (p < new_pct->size ())
{
for (uint32 j = 0; j < 16 && p < new_pct->size (); j++)
- sWorldLog.Log ("%.2X ", (*new_pct)[p++]);
- sWorldLog.Log ("\n");
+ sWorldLog.outLog ("%.2X ", (*new_pct)[p++]);
+ sWorldLog.outLog ("\n");
}
- sWorldLog.Log ("\n\n");
+ sWorldLog.outLog ("\n\n");
}
// like one switch ;)
diff --git a/src/shared/Log.cpp b/src/shared/Log.cpp
index 480532cc5a6..4028f71e4c7 100644
--- a/src/shared/Log.cpp
+++ b/src/shared/Log.cpp
@@ -21,7 +21,6 @@
#include "Common.h"
#include "Log.h"
#include "Policies/SingletonImp.h"
-#include "Database/DatabaseEnv.h"
#include "Config/ConfigEnv.h"
#include "Util.h"
diff --git a/src/shared/Log.h b/src/shared/Log.h
index 56140b73c70..85670e706e6 100644
--- a/src/shared/Log.h
+++ b/src/shared/Log.h
@@ -23,6 +23,7 @@
#include "Common.h"
#include "Policies/Singleton.h"
+#include "Database/DatabaseEnv.h"
class Config;