From 2337a0becb2bb536d8445b9f6176263ec2e7e661 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 18 Aug 2016 23:17:46 +0300 Subject: [PATCH] Add LOG_APPEND method for writing to log without timestamp and level --- apps/openmw-mp/Networking.cpp | 4 ++-- apps/openmw/mwmp/DedicatedPlayer.cpp | 8 ++++---- apps/openmw/mwmp/LocalPlayer.cpp | 4 +++- apps/openmw/mwmp/Networking.cpp | 12 ++++++------ components/openmw-mp/Log.cpp | 27 +++++++++++++++++---------- components/openmw-mp/Log.hpp | 7 ++++--- 6 files changed, 36 insertions(+), 26 deletions(-) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 9b7713813..8b9f451d6 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -155,7 +155,7 @@ void Networking::Update(RakNet::Packet *packet) { myPacket->Read(player); - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Moved to %s\n", + LOG_APPEND(Log::LOG_INFO, "- Moved to %s\n", player->GetCell()->getDescription().c_str()); myPacket->Send(player, true); //send to other clients @@ -163,7 +163,7 @@ void Networking::Update(RakNet::Packet *packet) } else { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Ignored because %s is dead\n", + LOG_APPEND(Log::LOG_INFO, "- Ignored because %s is dead\n", player->Npc()->mName.c_str()); } diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index 5e6121833..2b73bc0e9 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -43,7 +43,7 @@ MWWorld::Ptr DedicatedPlayer::getPtr() void Players::CreatePlayer(RakNet::RakNetGUID id) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Setting up character info\n"); + LOG_APPEND(Log::LOG_INFO, "- Setting up character info\n"); MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); @@ -74,7 +74,7 @@ void Players::CreatePlayer(RakNet::RakNetGUID id) if (_player->state == 0) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Creating new reference pointer for %s\n", + LOG_APPEND(Log::LOG_INFO, "- Creating new reference pointer for %s\n", _player->Npc()->mName.c_str()); MWWorld::Ptr tmp = world->placeObject(_player->reference->getPtr(), cellStore, _pos); @@ -87,7 +87,7 @@ void Players::CreatePlayer(RakNet::RakNetGUID id) } else { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Updating reference pointer for %s\n", + LOG_APPEND(Log::LOG_INFO, "- Updating reference pointer for %s\n", _player->Npc()->mName.c_str()); _player->ptr.getBase()->canChangeCell = true; @@ -268,7 +268,7 @@ void DedicatedPlayer::UpdatePtr(MWWorld::Ptr newPtr) DedicatedPlayer *Players::NewPlayer(RakNet::RakNetGUID guid) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Creating new DedicatedPlayer with guid %i\n", + LOG_APPEND(Log::LOG_INFO, "- Creating new DedicatedPlayer with guid %i\n", guid.ToUint32); players[guid] = new DedicatedPlayer(guid); diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index dd53f97eb..4a2b50d9a 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -383,7 +383,9 @@ void LocalPlayer::updateCell(bool forceUpdate) if (shouldUpdate) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Telling server I moved from %s to %s\n", + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_GAME_CELL to server\n"); + + LOG_APPEND(Log::LOG_INFO, "- Moved from %s to %s\n", GetCell()->getDescription().c_str(), _cell->getDescription().c_str()); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 7b81938cd..85d7161b0 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -190,27 +190,27 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) if (id == myid) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Packet was about my id\n"); + LOG_APPEND(Log::LOG_INFO, "- Packet was about my id\n"); if (packet->length == myPacket->headerSize()) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Requesting info"); + LOG_APPEND(Log::LOG_INFO, "- Requesting info"); myPacket->Send(getLocalPlayer(), serverAddr); } else { myPacket->Packet(&bsIn, getLocalPlayer(), false); - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Updating LocalPlayer\n"); + LOG_APPEND(Log::LOG_INFO, "- Updating LocalPlayer\n"); getLocalPlayer()->updateChar(); } } else { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Packet was about %s\n", pl == 0 ? "new player" : pl->Npc()->mName.c_str()); + LOG_APPEND(Log::LOG_INFO, "- Packet was about %s\n", pl == 0 ? "new player" : pl->Npc()->mName.c_str()); if (pl == 0) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Exchanging data with new player\n"); + LOG_APPEND(Log::LOG_INFO, "- Exchanging data with new player\n"); pl = Players::NewPlayer(id); } @@ -393,7 +393,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) } else if (pl != 0) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Packet was about %s\n", pl->Npc()->mName.c_str()); + LOG_APPEND(Log::LOG_INFO, "- Packet was about %s\n", pl->Npc()->mName.c_str()); MWMechanics::DynamicStat health; pl->CreatureStats()->mDead = true; health.readState(pl->CreatureStats()->mDynamic[0]); diff --git a/components/openmw-mp/Log.cpp b/components/openmw-mp/Log.cpp index 19f0de77e..5da974bb7 100644 --- a/components/openmw-mp/Log.cpp +++ b/components/openmw-mp/Log.cpp @@ -56,21 +56,25 @@ const char* getTime() return result; } -void Log::print(int level, const char *file, int line, const char *message, ...) const +void Log::print(int level, bool hasPrefix, const char *file, int line, const char *message, ...) const { if (level < logLevel) return; std::stringstream sstr; - sstr << "[" << getTime() << "] "; - if (file != 0 && line != 0) + if (hasPrefix) { - sstr << "[" << file << ":"; - sstr << line << "] "; - } - sstr << "["; - switch (level) - { + sstr << "[" << getTime() << "] "; + + if (file != 0 && line != 0) + { + sstr << "[" << file << ":"; + sstr << line << "] "; + } + + sstr << "["; + switch (level) + { case LOG_WARN: sstr << "WARN"; break; @@ -82,8 +86,11 @@ void Log::print(int level, const char *file, int line, const char *message, ...) break; default: sstr << "INFO"; + } + sstr << "]: "; + } - sstr << "]: "; + sstr << message; char back = *sstr.str().rbegin(); if (back != '\n') diff --git a/components/openmw-mp/Log.hpp b/components/openmw-mp/Log.hpp index 6cd9ffef2..f688bd17a 100644 --- a/components/openmw-mp/Log.hpp +++ b/components/openmw-mp/Log.hpp @@ -13,8 +13,9 @@ #else #define LOG_INIT(logLevel) Log::Create(logLevel) #define LOG_QUIT() Log::Delete() -#define LOG_MESSAGE(level, msg, ...) Log::Get().print((level), (__FILE__), (__LINE__), (msg), __VA_ARGS__) -#define LOG_MESSAGE_SIMPLE(level, msg, ...) Log::Get().print((level), (0), (0), (msg), __VA_ARGS__) +#define LOG_MESSAGE(level, msg, ...) Log::Get().print((level), (1), (__FILE__), (__LINE__), (msg), __VA_ARGS__) +#define LOG_MESSAGE_SIMPLE(level, msg, ...) Log::Get().print((level), (1), (0), (0), (msg), __VA_ARGS__) +#define LOG_APPEND(level, msg, ...) Log::Get().print((level), (0), (0), (0), (msg), __VA_ARGS__) #endif class Log @@ -32,7 +33,7 @@ class Log static void Delete(); static const Log &Get(); static void SetLevel(int level); - void print(int level, const char *file, int line, const char *message, ...) const; + void print(int level, bool hasPrefix, const char *file, int line, const char *message, ...) const; private: Log(int logLevel); /// Not implemented