mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-29 22:15:32 +00:00
Add LOG_APPEND method for writing to log without timestamp and level
This commit is contained in:
parent
f4744f8547
commit
2337a0becb
6 changed files with 36 additions and 26 deletions
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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<float> health;
|
||||
pl->CreatureStats()->mDead = true;
|
||||
health.readState(pl->CreatureStats()->mDynamic[0]);
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue