[9836] Make log output code more consistent for diff build modes.

* Make possible have debug output if build in release mode.
* But preserver current optimization in avoid debug output args
  calculation if debug ouput disabled if done using DEBUG_LOG
* Implement in same way BASIC_LOG, DETAIL_LOG. Recommended use
  its instead explicit access to sLog
* Use variadic macros for DEBUG_LOG and other new defines.
  All supported VS/GCC have its support as C++ extension.
* Add DEBUG_FILTER_LOG and semilar defines for filered log output and use its.
* Also move recent added debug output for transport events under LOG_FILTER_TRANSPORT_MOVES
This commit is contained in:
VladimirMangos 2010-05-04 20:59:50 +04:00
parent 6726a08b48
commit 6dec6c8a9f
12 changed files with 168 additions and 179 deletions

View file

@ -616,10 +616,7 @@ void AchievementMgr::SendAchievementEarned(AchievementEntry const* achievement)
if(GetPlayer()->GetSession()->PlayerLoading())
return;
#ifdef MANGOS_DEBUG
if((sLog.getLogFilter() & LOG_FILTER_ACHIEVEMENT_UPDATES)==0)
sLog.outDebug("AchievementMgr::SendAchievementEarned(%u)", achievement->ID);
#endif
DEBUG_FILTER_LOG(LOG_FILTER_ACHIEVEMENT_UPDATES, "AchievementMgr::SendAchievementEarned(%u)", achievement->ID);
if(Guild* guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId()))
{

View file

@ -65,10 +65,7 @@ VisibleNotifier::Notify()
{
i_player.m_clientGUIDs.erase(*itr);
#ifdef MANGOS_DEBUG
if((sLog.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES)==0)
sLog.outDebug("%s is out of range (no in active cells set) now for player %u",itr->GetString().c_str(),i_player.GetGUIDLow());
#endif
DEBUG_FILTER_LOG(LOG_FILTER_VISIBILITY_CHANGES, "%s is out of range (no in active cells set) now for player %u",itr->GetString().c_str(),i_player.GetGUIDLow());
}
// send update to other players (except player updates that already sent using SendUpdateToPlayer)

View file

@ -864,10 +864,7 @@ Map::CreatureRelocation(Creature *creature, float x, float y, float z, float ang
// delay creature move for grid/cell to grid/cell moves
if (old_cell.DiffCell(new_cell) || old_cell.DiffGrid(new_cell))
{
#ifdef MANGOS_DEBUG
if ((sLog.getLogFilter() & LOG_FILTER_CREATURE_MOVES) == 0)
sLog.outDebug("Creature (GUID: %u Entry: %u) added to moving list from grid[%u,%u]cell[%u,%u] to grid[%u,%u]cell[%u,%u].", creature->GetGUIDLow(), creature->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY());
#endif
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Creature (GUID: %u Entry: %u) added to moving list from grid[%u,%u]cell[%u,%u] to grid[%u,%u]cell[%u,%u].", creature->GetGUIDLow(), creature->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY());
// do move or do move to respawn or remove creature if previous all fail
if(CreatureCellRelocation(creature,new_cell))
@ -885,10 +882,7 @@ Map::CreatureRelocation(Creature *creature, float x, float y, float z, float ang
if(!CreatureRespawnRelocation(creature))
{
// ... or unload (if respawn grid also not loaded)
#ifdef MANGOS_DEBUG
if((sLog.getLogFilter() & LOG_FILTER_CREATURE_MOVES)==0)
sLog.outDebug("Creature (GUID: %u Entry: %u ) can't be move to unloaded respawn grid.",creature->GetGUIDLow(),creature->GetEntry());
#endif
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Creature (GUID: %u Entry: %u ) can't be move to unloaded respawn grid.",creature->GetGUIDLow(),creature->GetEntry());
creature->SetNeedNotify();
}
}
@ -910,10 +904,7 @@ bool Map::CreatureCellRelocation(Creature *c, Cell new_cell)
// if in same cell then none do
if(old_cell.DiffCell(new_cell))
{
#ifdef MANGOS_DEBUG
if((sLog.getLogFilter() & LOG_FILTER_CREATURE_MOVES)==0)
sLog.outDebug("Creature (GUID: %u Entry: %u) moved in grid[%u,%u] from cell[%u,%u] to cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.CellX(), new_cell.CellY());
#endif
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Creature (GUID: %u Entry: %u) moved in grid[%u,%u] from cell[%u,%u] to cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.CellX(), new_cell.CellY());
if( !old_cell.DiffGrid(new_cell) )
{
@ -924,10 +915,7 @@ bool Map::CreatureCellRelocation(Creature *c, Cell new_cell)
}
else
{
#ifdef MANGOS_DEBUG
if((sLog.getLogFilter() & LOG_FILTER_CREATURE_MOVES)==0)
sLog.outDebug("Creature (GUID: %u Entry: %u) move in same grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY());
#endif
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Creature (GUID: %u Entry: %u) move in same grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY());
}
return true;
@ -938,10 +926,7 @@ bool Map::CreatureCellRelocation(Creature *c, Cell new_cell)
{
EnsureGridLoadedAtEnter(new_cell);
#ifdef MANGOS_DEBUG
if((sLog.getLogFilter() & LOG_FILTER_CREATURE_MOVES)==0)
sLog.outDebug("Active creature (GUID: %u Entry: %u) moved from grid[%u,%u]cell[%u,%u] to grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY());
#endif
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Active creature (GUID: %u Entry: %u) moved from grid[%u,%u]cell[%u,%u] to grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY());
RemoveFromGrid(c,getNGrid(old_cell.GridX(), old_cell.GridY()),old_cell);
AddToGrid(c,getNGrid(new_cell.GridX(), new_cell.GridY()),new_cell);
@ -952,10 +937,7 @@ bool Map::CreatureCellRelocation(Creature *c, Cell new_cell)
// in diff. loaded grid normal creature
if(loaded(GridPair(new_cell.GridX(), new_cell.GridY())))
{
#ifdef MANGOS_DEBUG
if((sLog.getLogFilter() & LOG_FILTER_CREATURE_MOVES)==0)
sLog.outDebug("Creature (GUID: %u Entry: %u) moved from grid[%u,%u]cell[%u,%u] to grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY());
#endif
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Creature (GUID: %u Entry: %u) moved from grid[%u,%u]cell[%u,%u] to grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY());
RemoveFromGrid(c,getNGrid(old_cell.GridX(), old_cell.GridY()),old_cell);
{
@ -967,10 +949,7 @@ bool Map::CreatureCellRelocation(Creature *c, Cell new_cell)
}
// fail to move: normal creature attempt move to unloaded grid
#ifdef MANGOS_DEBUG
if((sLog.getLogFilter() & LOG_FILTER_CREATURE_MOVES)==0)
sLog.outDebug("Creature (GUID: %u Entry: %u) attempt move from grid[%u,%u]cell[%u,%u] to unloaded grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY());
#endif
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Creature (GUID: %u Entry: %u) attempt move from grid[%u,%u]cell[%u,%u] to unloaded grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY());
return false;
}
@ -985,10 +964,7 @@ bool Map::CreatureRespawnRelocation(Creature *c)
c->CombatStop();
c->GetMotionMaster()->Clear();
#ifdef MANGOS_DEBUG
if((sLog.getLogFilter() & LOG_FILTER_CREATURE_MOVES)==0)
sLog.outDebug("Creature (GUID: %u Entry: %u) will moved from grid[%u,%u]cell[%u,%u] to respawn grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), c->GetCurrentCell().GridX(), c->GetCurrentCell().GridY(), c->GetCurrentCell().CellX(), c->GetCurrentCell().CellY(), resp_cell.GridX(), resp_cell.GridY(), resp_cell.CellX(), resp_cell.CellY());
#endif
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Creature (GUID: %u Entry: %u) will moved from grid[%u,%u]cell[%u,%u] to respawn grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), c->GetCurrentCell().GridX(), c->GetCurrentCell().GridY(), c->GetCurrentCell().CellX(), c->GetCurrentCell().CellY(), resp_cell.GridX(), resp_cell.GridY(), resp_cell.CellX(), resp_cell.CellY());
// teleport it to respawn point (like normal respawn if player see)
if(CreatureCellRelocation(c,resp_cell))

View file

@ -17132,7 +17132,7 @@ void Player::_SaveStats()
void Player::outDebugValues() const
{
if(!sLog.IsOutDebug()) // optimize disabled debug output
if(!sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG)) // optimize disabled debug output
return;
sLog.outDebug("HP is: \t\t\t%u\t\tMP is: \t\t\t%u",GetMaxHealth(), GetMaxPower(POWER_MANA));
@ -17963,10 +17963,7 @@ void Player::HandleStealthedUnitsDetection()
(*i)->SendCreateUpdateToPlayer(this);
m_clientGUIDs.insert(i_guid);
#ifdef MANGOS_DEBUG
if((sLog.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES)==0)
sLog.outDebug("%s is detected in stealth by player %u. Distance = %f",i_guid.GetString().c_str(),GetGUIDLow(),GetDistance(*i));
#endif
DEBUG_FILTER_LOG(LOG_FILTER_VISIBILITY_CHANGES, "%s is detected in stealth by player %u. Distance = %f",i_guid.GetString().c_str(),GetGUIDLow(),GetDistance(*i));
// target aura duration for caster show only if target exist at caster client
// send data at target visibility change (adding to client)
@ -19145,10 +19142,7 @@ void Player::UpdateVisibilityOf(WorldObject const* viewPoint, WorldObject* targe
target->DestroyForPlayer(this);
m_clientGUIDs.erase(t_guid);
#ifdef MANGOS_DEBUG
if((sLog.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES)==0)
sLog.outDebug("%s out of range for player %u. Distance = %f",t_guid.GetString().c_str(),GetGUIDLow(),GetDistance(target));
#endif
DEBUG_FILTER_LOG(LOG_FILTER_VISIBILITY_CHANGES, "%s out of range for player %u. Distance = %f",t_guid.GetString().c_str(),GetGUIDLow(),GetDistance(target));
}
}
else
@ -19159,10 +19153,7 @@ void Player::UpdateVisibilityOf(WorldObject const* viewPoint, WorldObject* targe
if(target->GetTypeId()!=TYPEID_GAMEOBJECT||!((GameObject*)target)->IsTransport())
m_clientGUIDs.insert(target->GetObjectGuid());
#ifdef MANGOS_DEBUG
if((sLog.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES)==0)
sLog.outDebug("Object %u (Type: %u) is visible now for player %u. Distance = %f",target->GetGUIDLow(),target->GetTypeId(),GetGUIDLow(),GetDistance(target));
#endif
DEBUG_FILTER_LOG(LOG_FILTER_VISIBILITY_CHANGES, "Object %u (Type: %u) is visible now for player %u. Distance = %f",target->GetGUIDLow(),target->GetTypeId(),GetGUIDLow(),GetDistance(target));
// target aura duration for caster show only if target exist at caster client
// send data at target visibility change (adding to client)
@ -19202,10 +19193,7 @@ void Player::UpdateVisibilityOf(WorldObject const* viewPoint, T* target, UpdateD
target->BuildOutOfRangeUpdateBlock(&data);
m_clientGUIDs.erase(t_guid);
#ifdef MANGOS_DEBUG
if((sLog.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES)==0)
sLog.outDebug("%s is out of range for %s. Distance = %f",t_guid.GetString().c_str(),GetObjectGuid().GetString().c_str(),GetDistance(target));
#endif
DEBUG_FILTER_LOG(LOG_FILTER_VISIBILITY_CHANGES, "%s is out of range for %s. Distance = %f", t_guid.GetString().c_str(), GetObjectGuid().GetString().c_str(), GetDistance(target));
}
}
else
@ -19216,10 +19204,7 @@ void Player::UpdateVisibilityOf(WorldObject const* viewPoint, T* target, UpdateD
target->BuildCreateUpdateBlockForPlayer(&data, this);
UpdateVisibilityOf_helper(m_clientGUIDs,target);
#ifdef MANGOS_DEBUG
if((sLog.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES)==0)
sLog.outDebug("%s is visible now for %s. Distance = %f",target->GetObjectGuid().GetString().c_str(),GetObjectGuid().GetString().c_str(),GetDistance(target));
#endif
DEBUG_FILTER_LOG(LOG_FILTER_VISIBILITY_CHANGES, "%s is visible now for %s. Distance = %f", target->GetObjectGuid().GetString().c_str(), GetObjectGuid().GetString().c_str(), GetDistance(target));
}
}
}

View file

@ -566,7 +566,7 @@ void Transport::DoEventIfAny(WayPointMap::value_type const& node, bool departure
{
if (uint32 eventid = departure ? node.second.departureEventID : node.second.arrivalEventID)
{
DEBUG_LOG("Taxi %s event %u of node %u of %s (%s) path", departure ? "departure" : "arrival", eventid, node.first, GetName(), GetObjectGuid().GetString().c_str());
DEBUG_FILTER_LOG(LOG_FILTER_TRANSPORT_MOVES, "Taxi %s event %u of node %u of %s (%s) path", departure ? "departure" : "arrival", eventid, node.first, GetName(), GetObjectGuid().GetString().c_str());
GetMap()->ScriptsStart(sEventScripts, eventid, this, this);
}
}

View file

@ -186,7 +186,7 @@ bool WorldSession::Update(uint32 /*diff*/)
else if(_player->IsInWorld())
{
(this->*opHandle.handler)(*packet);
if (sLog.IsOutDebug() && packet->rpos() < packet->wpos())
if (packet->rpos() < packet->wpos() && sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG))
LogUnprocessedTail(packet);
}
// lag can cause STATUS_LOGGEDIN opcodes to arrive after the player started a transfer
@ -200,7 +200,7 @@ bool WorldSession::Update(uint32 /*diff*/)
{
// not expected _player or must checked in packet hanlder
(this->*opHandle.handler)(*packet);
if (sLog.IsOutDebug() && packet->rpos() < packet->wpos())
if (packet->rpos() < packet->wpos() && sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG))
LogUnprocessedTail(packet);
}
break;
@ -212,7 +212,7 @@ bool WorldSession::Update(uint32 /*diff*/)
else
{
(this->*opHandle.handler)(*packet);
if (sLog.IsOutDebug() && packet->rpos() < packet->wpos())
if (packet->rpos() < packet->wpos() && sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG))
LogUnprocessedTail(packet);
}
break;
@ -230,7 +230,7 @@ bool WorldSession::Update(uint32 /*diff*/)
m_playerRecentlyLogout = false;
(this->*opHandle.handler)(*packet);
if (sLog.IsOutDebug() && packet->rpos() < packet->wpos())
if (packet->rpos() < packet->wpos() && sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG))
LogUnprocessedTail(packet);
break;
case STATUS_NEVER:
@ -254,7 +254,7 @@ bool WorldSession::Update(uint32 /*diff*/)
{
sLog.outError("WorldSession::Update ByteBufferException occured while parsing a packet (opcode: %u) from client %s, accountid=%i.",
packet->GetOpcode(), GetRemoteAddress().c_str(), GetAccountId());
if(sLog.IsOutDebug())
if (sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG))
{
sLog.outDebug("Dumping error causing packet:");
packet->hexlike();

View file

@ -718,7 +718,7 @@ int WorldSocket::ProcessIncoming (WorldPacket* new_pct)
{
sLog.outError("WorldSocket::ProcessIncoming ByteBufferException occured while parsing an instant handled packet (opcode: %u) from client %s, accountid=%i.",
opcode, GetRemoteAddress().c_str(), m_Session?m_Session->GetAccountId():-1);
if(sLog.IsOutDebug())
if (sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG))
{
sLog.outDebug("Dumping error-causing packet:");
new_pct->hexlike();

View file

@ -278,7 +278,7 @@ WorldSocketMgr::StartNetwork (ACE_UINT16 port, std::string& address)
m_addr = address;
m_port = port;
if (!sLog.IsOutDebug ())
if (!sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG))
ACE_Log_Msg::instance ()->priority_mask (LM_ERROR, ACE_Log_Msg::PROCESS);
if (StartReactiveIO (port, address.c_str()) == -1)

View file

@ -412,7 +412,7 @@ class ByteBuffer
void print_storage() const
{
if(!sLog.IsOutDebug()) // optimize disabled debug output
if (!sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG)) // optimize disabled debug output
return;
sLog.outDebug("STORAGE_SIZE: %lu", (unsigned long)size() );
@ -423,7 +423,7 @@ class ByteBuffer
void textlike() const
{
if(!sLog.IsOutDebug()) // optimize disabled debug output
if (!sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG)) // optimize disabled debug output
return;
sLog.outDebug("STORAGE_SIZE: %lu", (unsigned long)size() );
@ -434,13 +434,13 @@ class ByteBuffer
void hexlike() const
{
if(!sLog.IsOutDebug()) // optimize disabled debug output
if (!sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG)) // optimize disabled debug output
return;
uint32 j = 1, k = 1;
sLog.outDebug("STORAGE_SIZE: %lu", (unsigned long)size() );
if(sLog.IsIncludeTime())
if (sLog.IsIncludeTime())
sLog.outDebugInLine(" ");
for(uint32 i = 0; i < size(); ++i)

View file

@ -46,7 +46,7 @@ Log::Log() :
void Log::InitColors(const std::string& str)
{
if(str.empty())
if (str.empty())
{
m_colored = false;
return;
@ -159,33 +159,41 @@ void Log::ResetColor(bool stdout_stream)
#endif
}
void Log::SetLogLevel(char *Level)
void Log::SetLogLevel(char* level)
{
int32 NewLevel =atoi((char*)Level);
if ( NewLevel <0 )
NewLevel = 0;
m_logLevel = NewLevel;
int32 newLevel =atoi((char*)level);
printf( "LogLevel is %u\n",m_logLevel );
if (newLevel < LOG_LVL_MINIMAL)
newLevel = LOG_LVL_MINIMAL;
else if (newLevel > LOG_LVL_DEBUG)
newLevel = LOG_LVL_DEBUG;
m_logLevel = LogLevel(newLevel);
printf("LogLevel is %u\n", m_logLevel);
}
void Log::SetLogFileLevel(char *Level)
void Log::SetLogFileLevel(char* level)
{
int32 NewLevel =atoi((char*)Level);
if ( NewLevel <0 )
NewLevel = 0;
m_logFileLevel = NewLevel;
int32 newLevel =atoi((char*)level);
printf( "LogFileLevel is %u\n",m_logFileLevel );
if (newLevel < LOG_LVL_MINIMAL)
newLevel = LOG_LVL_MINIMAL;
else if (newLevel > LOG_LVL_DEBUG)
newLevel = LOG_LVL_DEBUG;
m_logFileLevel = LogLevel(newLevel);
printf("LogFileLevel is %u\n", m_logFileLevel);
}
void Log::Initialize()
{
/// Common log files data
m_logsDir = sConfig.GetStringDefault("LogsDir","");
if(!m_logsDir.empty())
if (!m_logsDir.empty())
{
if((m_logsDir.at(m_logsDir.length()-1)!='/') && (m_logsDir.at(m_logsDir.length()-1)!='\\'))
if ((m_logsDir.at(m_logsDir.length()-1)!='/') && (m_logsDir.at(m_logsDir.length()-1)!='\\'))
m_logsDir.append("/");
}
@ -195,20 +203,20 @@ void Log::Initialize()
logfile = openLogFile("LogFile","LogTimestamp","w");
m_gmlog_per_account = sConfig.GetBoolDefault("GmLogPerAccount",false);
if(!m_gmlog_per_account)
if (!m_gmlog_per_account)
gmLogfile = openLogFile("GMLogFile","GmLogTimestamp","a");
else
{
// GM log settings for per account case
m_gmlog_filename_format = sConfig.GetStringDefault("GMLogFile", "");
if(!m_gmlog_filename_format.empty())
if (!m_gmlog_filename_format.empty())
{
bool m_gmlog_timestamp = sConfig.GetBoolDefault("GmLogTimestamp",false);
size_t dot_pos = m_gmlog_filename_format.find_last_of(".");
if(dot_pos!=m_gmlog_filename_format.npos)
if (dot_pos!=m_gmlog_filename_format.npos)
{
if(m_gmlog_timestamp)
if (m_gmlog_timestamp)
m_gmlog_filename_format.insert(dot_pos,m_logsTimestamp);
m_gmlog_filename_format.insert(dot_pos,"_#%u");
@ -217,7 +225,7 @@ void Log::Initialize()
{
m_gmlog_filename_format += "_#%u";
if(m_gmlog_timestamp)
if (m_gmlog_timestamp)
m_gmlog_filename_format += m_logsTimestamp;
}
@ -232,19 +240,19 @@ void Log::Initialize()
// Main log file settings
m_includeTime = sConfig.GetBoolDefault("LogTime", false);
m_logLevel = sConfig.GetIntDefault("LogLevel", 0);
m_logFileLevel = sConfig.GetIntDefault("LogFileLevel", 0);
m_logLevel = LogLevel(sConfig.GetIntDefault("LogLevel", 0));
m_logFileLevel = LogLevel(sConfig.GetIntDefault("LogFileLevel", 0));
InitColors(sConfig.GetStringDefault("LogColors", ""));
m_logFilter = 0;
if(sConfig.GetBoolDefault("LogFilter_TransportMoves", true))
if (sConfig.GetBoolDefault("LogFilter_TransportMoves", true))
m_logFilter |= LOG_FILTER_TRANSPORT_MOVES;
if(sConfig.GetBoolDefault("LogFilter_CreatureMoves", true))
if (sConfig.GetBoolDefault("LogFilter_CreatureMoves", true))
m_logFilter |= LOG_FILTER_CREATURE_MOVES;
if(sConfig.GetBoolDefault("LogFilter_VisibilityChanges", true))
if (sConfig.GetBoolDefault("LogFilter_VisibilityChanges", true))
m_logFilter |= LOG_FILTER_VISIBILITY_CHANGES;
if(sConfig.GetBoolDefault("LogFilter_AchievementUpdates", true))
if (sConfig.GetBoolDefault("LogFilter_AchievementUpdates", true))
m_logFilter |= LOG_FILTER_ACHIEVEMENT_UPDATES;
// Char log settings
@ -254,13 +262,13 @@ void Log::Initialize()
FILE* Log::openLogFile(char const* configFileName,char const* configTimeStampFlag, char const* mode)
{
std::string logfn=sConfig.GetStringDefault(configFileName, "");
if(logfn.empty())
if (logfn.empty())
return NULL;
if(configTimeStampFlag && sConfig.GetBoolDefault(configTimeStampFlag,false))
if (configTimeStampFlag && sConfig.GetBoolDefault(configTimeStampFlag,false))
{
size_t dot_pos = logfn.find_last_of(".");
if(dot_pos!=logfn.npos)
if (dot_pos!=logfn.npos)
logfn.insert(dot_pos,m_logsTimestamp);
else
logfn += m_logsTimestamp;
@ -271,7 +279,7 @@ FILE* Log::openLogFile(char const* configFileName,char const* configTimeStampFla
FILE* Log::openGmlogPerAccount(uint32 account)
{
if(m_gmlog_filename_format.empty())
if (m_gmlog_filename_format.empty())
return NULL;
char namebuf[MANGOS_PATH_MAX];
@ -322,20 +330,20 @@ std::string Log::GetTimestampStr()
void Log::outTitle( const char * str)
{
if( !str )
if (!str)
return;
if(m_colored)
if (m_colored)
SetColor(true,WHITE);
// not expected utf8 and then send as-is
printf("%s", str);
if(m_colored)
if (m_colored)
ResetColor(true);
printf("\n");
if(logfile)
if (logfile)
{
fprintf(logfile, "%s", str);
fprintf(logfile, "\n" );
@ -347,27 +355,28 @@ void Log::outTitle( const char * str)
void Log::outString()
{
if(m_includeTime)
if (m_includeTime)
outTime();
printf( "\n" );
if(logfile)
if (logfile)
{
outTimestamp(logfile);
fprintf(logfile, "\n" );
fflush(logfile);
}
fflush(stdout);
}
void Log::outString( const char * str, ... )
{
if( !str )
if (!str)
return;
if(m_colored)
if (m_colored)
SetColor(true,m_colors[LogNormal]);
if(m_includeTime)
if (m_includeTime)
outTime();
va_list ap;
@ -376,11 +385,12 @@ void Log::outString( const char * str, ... )
vutf8printf(stdout, str, &ap);
va_end(ap);
if(m_colored)
if (m_colored)
ResetColor(true);
printf( "\n" );
if(logfile)
if (logfile)
{
outTimestamp(logfile);
@ -391,18 +401,19 @@ void Log::outString( const char * str, ... )
fflush(logfile);
}
fflush(stdout);
}
void Log::outError( const char * err, ... )
{
if( !err )
if (!err)
return;
if(m_colored)
if (m_colored)
SetColor(false,m_colors[LogError]);
if(m_includeTime)
if (m_includeTime)
outTime();
va_list ap;
@ -411,11 +422,11 @@ void Log::outError( const char * err, ... )
vutf8printf(stderr, err, &ap);
va_end(ap);
if(m_colored)
if (m_colored)
ResetColor(false);
fprintf( stderr, "\n" );
if(logfile)
if (logfile)
{
outTimestamp(logfile);
fprintf(logfile, "ERROR:" );
@ -427,18 +438,19 @@ void Log::outError( const char * err, ... )
fprintf(logfile, "\n" );
fflush(logfile);
}
fflush(stderr);
}
void Log::outErrorDb( const char * err, ... )
{
if( !err )
if (!err)
return;
if(m_colored)
if (m_colored)
SetColor(false,m_colors[LogError]);
if(m_includeTime)
if (m_includeTime)
outTime();
va_list ap;
@ -447,12 +459,12 @@ void Log::outErrorDb( const char * err, ... )
vutf8printf(stderr, err, &ap);
va_end(ap);
if(m_colored)
if (m_colored)
ResetColor(false);
fprintf( stderr, "\n" );
if(logfile)
if (logfile)
{
outTimestamp(logfile);
fprintf(logfile, "ERROR:" );
@ -465,7 +477,7 @@ void Log::outErrorDb( const char * err, ... )
fflush(logfile);
}
if(dberLogfile)
if (dberLogfile)
{
outTimestamp(dberLogfile);
@ -477,20 +489,21 @@ void Log::outErrorDb( const char * err, ... )
fprintf(dberLogfile, "\n" );
fflush(dberLogfile);
}
fflush(stderr);
}
void Log::outBasic( const char * str, ... )
{
if( !str )
if (!str)
return;
if( m_logLevel > 0 )
if (m_logLevel >= LOG_LVL_BASIC)
{
if(m_colored)
if (m_colored)
SetColor(true,m_colors[LogDetails]);
if(m_includeTime)
if (m_includeTime)
outTime();
va_list ap;
@ -498,13 +511,13 @@ void Log::outBasic( const char * str, ... )
vutf8printf(stdout, str, &ap);
va_end(ap);
if(m_colored)
if (m_colored)
ResetColor(true);
printf( "\n" );
}
if(logfile && m_logFileLevel > 0)
if (logfile && m_logFileLevel >= LOG_LVL_BASIC)
{
va_list ap;
outTimestamp(logfile);
@ -514,21 +527,22 @@ void Log::outBasic( const char * str, ... )
va_end(ap);
fflush(logfile);
}
fflush(stdout);
}
void Log::outDetail( const char * str, ... )
{
if( !str )
if (!str)
return;
if( m_logLevel > 1 )
if (m_logLevel >= LOG_LVL_DETAIL)
{
if(m_colored)
if (m_colored)
SetColor(true,m_colors[LogDetails]);
if(m_includeTime)
if (m_includeTime)
outTime();
va_list ap;
@ -536,12 +550,13 @@ void Log::outDetail( const char * str, ... )
vutf8printf(stdout, str, &ap);
va_end(ap);
if(m_colored)
if (m_colored)
ResetColor(true);
printf( "\n" );
}
if(logfile && m_logFileLevel > 1)
if (logfile && m_logFileLevel >= LOG_LVL_DETAIL)
{
outTimestamp(logfile);
@ -559,11 +574,12 @@ void Log::outDetail( const char * str, ... )
void Log::outDebugInLine( const char * str, ... )
{
if( !str )
if (!str)
return;
if( m_logLevel > 2 )
if (m_logLevel >= LOG_LVL_DEBUG)
{
if(m_colored)
if (m_colored)
SetColor(true,m_colors[LogDebug]);
va_list ap;
@ -571,10 +587,11 @@ void Log::outDebugInLine( const char * str, ... )
vutf8printf(stdout, str, &ap);
va_end(ap);
if(m_colored)
if (m_colored)
ResetColor(true);
}
if(logfile && m_logFileLevel > 2)
if (logfile && m_logFileLevel >= LOG_LVL_DEBUG)
{
va_list ap;
va_start(ap, str);
@ -585,14 +602,15 @@ void Log::outDebugInLine( const char * str, ... )
void Log::outDebug( const char * str, ... )
{
if( !str )
if (!str)
return;
if( m_logLevel > 2 )
if (m_logLevel >= LOG_LVL_DEBUG)
{
if(m_colored)
if (m_colored)
SetColor(true,m_colors[LogDebug]);
if(m_includeTime)
if (m_includeTime)
outTime();
va_list ap;
@ -600,12 +618,13 @@ void Log::outDebug( const char * str, ... )
vutf8printf(stdout, str, &ap);
va_end(ap);
if(m_colored)
if (m_colored)
ResetColor(true);
printf( "\n" );
}
if(logfile && m_logFileLevel > 2)
if (logfile && m_logFileLevel >= LOG_LVL_DEBUG)
{
outTimestamp(logfile);
@ -617,20 +636,21 @@ void Log::outDebug( const char * str, ... )
fprintf(logfile, "\n" );
fflush(logfile);
}
fflush(stdout);
}
void Log::outCommand( uint32 account, const char * str, ... )
{
if( !str )
if (!str)
return;
if( m_logLevel > 1 )
if (m_logLevel >= LOG_LVL_DETAIL)
{
if(m_colored)
if (m_colored)
SetColor(true,m_colors[LogDetails]);
if(m_includeTime)
if (m_includeTime)
outTime();
va_list ap;
@ -638,12 +658,13 @@ void Log::outCommand( uint32 account, const char * str, ... )
vutf8printf(stdout, str, &ap);
va_end(ap);
if(m_colored)
if (m_colored)
ResetColor(true);
printf( "\n" );
}
if(logfile && m_logFileLevel > 1)
if (logfile && m_logFileLevel >= LOG_LVL_DETAIL)
{
va_list ap;
outTimestamp(logfile);
@ -687,7 +708,7 @@ void Log::outChar(const char * str, ... )
if (!str)
return;
if(charLogfile)
if (charLogfile)
{
va_list ap;
outTimestamp(charLogfile);
@ -725,7 +746,7 @@ void Log::outWorldPacketDump( uint32 socket, uint32 opcode, char const* opcodeNa
void Log::outCharDump( const char * str, uint32 account_id, uint32 guid, const char * name )
{
if(charLogfile)
if (charLogfile)
{
fprintf(charLogfile, "== START DUMP == (account: %u guid: %u name: %s )\n%s\n== END DUMP ==\n",account_id,guid,name,str );
fflush(charLogfile);
@ -734,12 +755,12 @@ void Log::outCharDump( const char * str, uint32 account_id, uint32 guid, const c
void Log::outMenu( const char * str, ... )
{
if( !str )
if (!str)
return;
SetColor(true,m_colors[LogNormal]);
if(m_includeTime)
if (m_includeTime)
outTime();
va_list ap;
@ -750,7 +771,7 @@ void Log::outMenu( const char * str, ... )
ResetColor(true);
if(logfile)
if (logfile)
{
outTimestamp(logfile);
@ -766,11 +787,12 @@ void Log::outMenu( const char * str, ... )
void Log::outRALog( const char * str, ... )
{
if( !str )
if (!str)
return;
va_list ap;
if (raLogfile)
{
va_list ap;
outTimestamp(raLogfile);
va_start(ap, str);
vfprintf(raLogfile, str, ap);
@ -778,12 +800,13 @@ void Log::outRALog( const char * str, ... )
va_end(ap);
fflush(raLogfile);
}
fflush(stdout);
}
void outstring_log(const char * str, ...)
{
if( !str )
if (!str)
return;
char buf[256];
@ -797,7 +820,7 @@ void outstring_log(const char * str, ...)
void detail_log(const char * str, ...)
{
if( !str )
if (!str)
return;
char buf[256];
@ -811,7 +834,7 @@ void detail_log(const char * str, ...)
void debug_log(const char * str, ...)
{
if( !str )
if (!str)
return;
char buf[256];
@ -825,7 +848,7 @@ void debug_log(const char * str, ...)
void error_log(const char * str, ...)
{
if( !str )
if (!str)
return;
char buf[256];
@ -839,7 +862,7 @@ void error_log(const char * str, ...)
void error_db_log(const char * str, ...)
{
if( !str )
if (!str)
return;
char buf[256];

View file

@ -25,13 +25,21 @@
class Config;
class ByteBuffer;
enum LogLevel
{
LOG_LVL_MINIMAL = 0, // unconditional and errors
LOG_LVL_BASIC = 1,
LOG_LVL_DETAIL = 2,
LOG_LVL_DEBUG = 3
};
// bitmask
enum LogFilters
{
LOG_FILTER_TRANSPORT_MOVES = 1,
LOG_FILTER_CREATURE_MOVES = 2,
LOG_FILTER_VISIBILITY_CHANGES = 4,
LOG_FILTER_ACHIEVEMENT_UPDATES= 8
LOG_FILTER_TRANSPORT_MOVES = 0x01,
LOG_FILTER_CREATURE_MOVES = 0x02,
LOG_FILTER_VISIBILITY_CHANGES = 0x04,
LOG_FILTER_ACHIEVEMENT_UPDATES= 0x08
};
enum Color
@ -123,7 +131,7 @@ class Log : public MaNGOS::Singleton<Log, MaNGOS::ClassLevelLockable<Log, ACE_Th
static void outTimestamp(FILE* file);
static std::string GetTimestampStr();
uint32 getLogFilter() const { return m_logFilter; }
bool IsOutDebug() const { return m_logLevel > 2 || (m_logFileLevel > 2 && logfile); }
bool HasLogLevelOrHigher(LogLevel loglvl) const { return m_logLevel >= loglvl || (m_logFileLevel >= loglvl && logfile); }
bool IsOutCharDump() const { return m_charLog_Dump; }
bool IsIncludeTime() const { return m_includeTime; }
private:
@ -138,8 +146,8 @@ class Log : public MaNGOS::Singleton<Log, MaNGOS::ClassLevelLockable<Log, ACE_Th
FILE* worldLogfile;
// log/console control
uint32 m_logLevel;
uint32 m_logFileLevel;
LogLevel m_logLevel;
LogLevel m_logFileLevel;
bool m_colored;
bool m_includeTime;
Color m_colors[4];
@ -159,11 +167,14 @@ class Log : public MaNGOS::Singleton<Log, MaNGOS::ClassLevelLockable<Log, ACE_Th
#define sLog MaNGOS::Singleton<Log>::Instance()
#ifdef MANGOS_DEBUG
#define DEBUG_LOG sLog.outDebug
#else
#define DEBUG_LOG
#endif
#define BASIC_LOG(...) if (sLog.HasLogLevelOrHigher(LOG_LVL_BASIC)) sLog.outBasic(__VA_ARGS__)
#define BASIC_FILTER_LOG(F,...) if (sLog.HasLogLevelOrHigher(LOG_LVL_BASIC) && (sLog.getLogFilter() & (F))==0) sLog.outBasic(__VA_ARGS__)
#define DETAIL_LOG(...) if (sLog.HasLogLevelOrHigher(LOG_LVL_DETAIL)) sLog.outDebug(__VA_ARGS__)
#define DETAIL_FILTER_LOG(F,...) if (sLog.HasLogLevelOrHigher(LOG_LVL_DETAIL) && (sLog.getLogFilter() & (F))==0) sLog.outDetail(__VA_ARGS__)
#define DEBUG_LOG(...) if (sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG)) sLog.outDebug( __VA_ARGS__)
#define DEBUG_FILTER_LOG(F,...) if (sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG) && (sLog.getLogFilter() & (F))==0) sLog.outDetail(__VA_ARGS__)
// primary for script library
void MANGOS_DLL_SPEC outstring_log(const char * str, ...) ATTR_PRINTF(1,2);

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9835"
#define REVISION_NR "9836"
#endif // __REVISION_NR_H__