Skip to content

Commit

Permalink
Added duplicate log line filter for script debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ccw808 committed Jan 23, 2016
1 parent ad27bf1 commit f238c25
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 41 deletions.
1 change: 1 addition & 0 deletions MTA10/core/CClientVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ void CClientVariables::LoadDefaults ( void )
DEFAULT ( "browser_remote_websites", true ); // Load remote websites?
DEFAULT ( "browser_remote_javascript", true ); // Execute javascript on remote websites?
DEFAULT ( "browser_plugins", false ); // Enable browser plugins?
DEFAULT ( "filter_duplicate_log_lines", true ); // Filter duplicate log lines for debug view and clientscript.log

if(!Exists("locale"))
{
Expand Down
1 change: 1 addition & 0 deletions MTA10/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ void CClientGame::DoPulses ( void )
#endif
m_pLatentTransferManager->DoPulse ();
m_pLuaManager->DoPulse ();
m_pScriptDebugging->UpdateLogOutput();

GetModelCacheManager ()->DoPulse ();

Expand Down
37 changes: 28 additions & 9 deletions MTA10/mods/shared_logic/CScriptDebugging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ CScriptDebugging::CScriptDebugging ( CLuaManager* pLuaManager )

CScriptDebugging::~CScriptDebugging ( void )
{
// Flush any pending duplicate loggings
m_DuplicateLineFilter.Flush();
UpdateLogOutput();

// Close the previously loaded file
if ( m_pLogFile )
{
Expand Down Expand Up @@ -403,11 +407,6 @@ void CScriptDebugging::LogString ( const char* szPrePend, const SLuaDebugInfo& l
m_bTriggeringOnClientDebugMessage = false;
}

// Log it to the file if enough level
if ( m_uiLogFileLevel >= uiMinimumDebugLevel )
{
PrintLog ( strText );
}
switch ( uiMinimumDebugLevel )
{
case 1:
Expand All @@ -420,10 +419,30 @@ void CScriptDebugging::LogString ( const char* szPrePend, const SLuaDebugInfo& l
ucRed = 0, ucGreen = 255, ucBlue = 0;
break;
}
#ifdef MTA_DEBUG
if ( !g_pCore->IsDebugVisible () ) return;
#endif
g_pCore->DebugEchoColor ( strText, ucRed, ucGreen, ucBlue );

m_DuplicateLineFilter.AddLine( strText, { uiMinimumDebugLevel, ucRed, ucGreen, ucBlue } );
if ( g_pCore->GetCVars ()->GetValue < bool > ( "filter_duplicate_log_lines" ) == false )
m_DuplicateLineFilter.Flush();
UpdateLogOutput();
}


void CScriptDebugging::UpdateLogOutput( void )
{
SString strText;
SLogData data;
while( m_DuplicateLineFilter.PopOutputLine( strText, data ) )
{
// Log it to the file if enough level
if ( m_uiLogFileLevel >= data.uiMinimumDebugLevel )
{
PrintLog ( strText );
}
#ifdef MTA_DEBUG
if ( !g_pCore->IsDebugVisible () ) return;
#endif
g_pCore->DebugEchoColor ( strText, data.ucRed, data.ucGreen, data.ucBlue );
}
}


Expand Down
12 changes: 12 additions & 0 deletions MTA10/mods/shared_logic/CScriptDebugging.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,19 @@
#include <stdio.h>

#include "lua/LuaCommon.h"
#include "CDuplicateLineFilter.h"

class CLuaManager;

struct SLogData
{
unsigned int uiMinimumDebugLevel;
unsigned char ucRed;
unsigned char ucGreen;
unsigned char ucBlue;
bool operator ==( const SLogData& other ) const { return uiMinimumDebugLevel == other.uiMinimumDebugLevel && ucRed == other.ucRed; }
};

class CScriptDebugging
{
public:
Expand Down Expand Up @@ -52,6 +62,7 @@ class CScriptDebugging
void PopLuaMain ( CLuaMain* pLuaMain );
void OnLuaMainDestroy ( CLuaMain* pLuaMain );
CLuaMain* GetTopLuaMain ( void );
void UpdateLogOutput ( void );

private:
SString ComposeErrorMessage ( const char* szPrePend, const SLuaDebugInfo& luaDebugInfo, const char* szMessage );
Expand All @@ -68,6 +79,7 @@ class CScriptDebugging
SLuaDebugInfo m_SavedLuaDebugInfo;
std::list < CLuaMain* > m_LuaMainStack;
HANDLE m_flushTimerHandle;
CDuplicateLineFilter < SLogData > m_DuplicateLineFilter;
};

#endif
1 change: 1 addition & 0 deletions MTA10_Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ void CGame::DoPulse ( void )
CLOCK_CALL1( m_pLatentTransferManager->DoPulse (); );

PrintLogOutputFromNetModule();
m_pScriptDebugging->UpdateLogOutput();

// Unlock the critical section again
Unlock();
Expand Down
1 change: 1 addition & 0 deletions MTA10_Server/mods/deathmatch/logic/CMainConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,7 @@ const std::vector < SIntSetting >& CMainConfig::GetIntSettingList ( void )
{ true, true, 0, 0, 100, "server_logic_fps_limit", &m_iServerLogicFpsLimit, NULL },
{ true, true, 0, 1, 1, "bad_net_bullet_fix", &m_bBadNetBulletFixEnabled, NULL },
{ true, true, 0, 1, 1, "crash_dump_upload", &m_bCrashDumpUploadEnabled, NULL },
{ true, true, 0, 1, 1, "filter_duplicate_log_lines", &m_bFilterDuplicateLogLinesEnabled, NULL },
};

static std::vector < SIntSetting > settingsList;
Expand Down
2 changes: 2 additions & 0 deletions MTA10_Server/mods/deathmatch/logic/CMainConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class CMainConfig: public CXMLConfig
bool GetLoadstringLogEnabled ( void ) const { return !m_strLoadstringLogFilename.empty(); }
bool GetBadNetBulletFixEnabled ( void ) const { return m_bBadNetBulletFixEnabled != 0; }
bool GetCrashDumpUploadEnabled ( void ) const { return m_bCrashDumpUploadEnabled != 0; }
bool GetFilterDuplicateLogLinesEnabled ( void ) const { return m_bFilterDuplicateLogLinesEnabled != 0; }

SString GetSetting ( const SString& configSetting );
bool GetSetting ( const SString& configSetting, SString& strValue );
Expand Down Expand Up @@ -217,6 +218,7 @@ class CMainConfig: public CXMLConfig
int m_iServerLogicFpsLimit;
int m_bBadNetBulletFixEnabled;
int m_bCrashDumpUploadEnabled;
int m_bFilterDuplicateLogLinesEnabled;
};

#endif
53 changes: 25 additions & 28 deletions MTA10_Server/mods/deathmatch/logic/CScriptDebugging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ CScriptDebugging::CScriptDebugging ( CLuaManager* pLuaManager )
m_bTriggeringOnDebugMessage = false;
}

CScriptDebugging::~CScriptDebugging ( void )
{
// Flush any pending duplicate loggings
m_DuplicateLineFilter.Flush();
UpdateLogOutput();

ClearPlayers ();
}

bool CScriptDebugging::AddPlayer ( CPlayer& Player, unsigned int uiLevel )
{
Expand Down Expand Up @@ -389,41 +397,30 @@ void CScriptDebugging::LogString ( const char* szPrePend, const SLuaDebugInfo& l
m_bTriggeringOnDebugMessage = false;
}

// Log it to the file if enough level
if ( m_uiLogFileLevel >= uiMinimumDebugLevel )
{
PrintLog ( strText );
}

// Log to console
CLogger::LogPrintf( "%s\n", strText.c_str () );
m_DuplicateLineFilter.AddLine( strText, { uiMinimumDebugLevel, ucRed, ucGreen, ucBlue } );
if ( g_pGame->GetConfig()->GetFilterDuplicateLogLinesEnabled() == false )
m_DuplicateLineFilter.Flush();
UpdateLogOutput();
}

#if 0
// Not sure what this is for, seems pretty useless
if ( m_uiHtmlLogLevel >= uiMinimumDebugLevel )
void CScriptDebugging::UpdateLogOutput( void )
{
SString strText;
SLogData data;
while( m_DuplicateLineFilter.PopOutputLine( strText, data ) )
{
if ( luaVM )
// Log it to the file if enough level
if ( m_uiLogFileLevel >= data.uiMinimumDebugLevel )
{
CLuaMain* pLuaMain = g_pGame->GetLuaManager()->GetVirtualMachine ( luaVM );
if ( pLuaMain )
{
CResourceFile * file = pLuaMain->GetResourceFile();
if ( file && file->GetType() == CResourceHTMLItem::RESOURCE_FILE_TYPE_HTML )
{
CResourceHTMLItem * html = (CResourceHTMLItem *)file;
html->AppendToPageBuffer ( strText );
html->AppendToPageBuffer ( "<br/>" );
}
}
PrintLog ( strText );
}
// Log to console
CLogger::LogPrintf( "%s\n", strText.c_str () );
// Tell the players
Broadcast ( CDebugEchoPacket ( strText, data.uiMinimumDebugLevel, data.ucRed, data.ucGreen, data.ucBlue ), data.uiMinimumDebugLevel );
}
#endif

// Tell the players
Broadcast ( CDebugEchoPacket ( strText, uiMinimumDebugLevel, ucRed, ucGreen, ucBlue ), uiMinimumDebugLevel );
}


void CScriptDebugging::PrintLog ( const char* szText )
{
// Got a logfile?
Expand Down
14 changes: 13 additions & 1 deletion MTA10_Server/mods/deathmatch/logic/CScriptDebugging.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@
#include "packets/CPacket.h"
#include <cstdio>
#include <list>
#include "CDuplicateLineFilter.h"

struct SLogData
{
unsigned int uiMinimumDebugLevel;
unsigned char ucRed;
unsigned char ucGreen;
unsigned char ucBlue;
bool operator ==( const SLogData& other ) const { return uiMinimumDebugLevel == other.uiMinimumDebugLevel && ucRed == other.ucRed; }
};

class CScriptDebugging
{
public:
CScriptDebugging ( CLuaManager* pLuaManager );
inline ~CScriptDebugging ( void ) { ClearPlayers (); };
~CScriptDebugging ( void );

bool AddPlayer ( class CPlayer& Player, unsigned int uiLevel );
bool RemovePlayer ( class CPlayer& Player );
Expand Down Expand Up @@ -52,6 +62,7 @@ class CScriptDebugging
void PopLuaMain ( CLuaMain* pLuaMain );
void OnLuaMainDestroy ( CLuaMain* pLuaMain );
CLuaMain* GetTopLuaMain ( void );
void UpdateLogOutput ( void );

private:
SString ComposeErrorMessage ( const char* szPrePend, const SLuaDebugInfo& luaDebugInfo, const char* szMessage );
Expand All @@ -68,6 +79,7 @@ class CScriptDebugging
bool m_bTriggeringOnDebugMessage;
SLuaDebugInfo m_SavedLuaDebugInfo;
std::list < CLuaMain* > m_LuaMainStack;
CDuplicateLineFilter < SLogData > m_DuplicateLineFilter;
};

#endif
9 changes: 6 additions & 3 deletions MTA10_Server/mods/deathmatch/mtaserver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,17 @@
<acl>acl.xml</acl>

<!-- Specifies the location and name of the debugscript log file. If left blank, server won't be saving this file. -->
<scriptdebuglogfile>logs/scripts.log</scriptdebuglogfile>
<scriptdebuglogfile>logs/scripts.log</scriptdebuglogfile>

<!-- Specifies the level of the debugscript log file. Available values: 0, 1, 2, 3. When not set, defaults to 0. -->
<scriptdebugloglevel>0</scriptdebugloglevel>

<!-- Specifies the level of the html debug. Available values: 0, 1, 2, 3. When not set, defaults to 0. -->
<htmldebuglevel>0</htmldebuglevel>

<!-- Specifies whether or not duplicate log lines should be filtered. Available values: 0 or 1, defaults to 1. -->
<filter_duplicate_log_lines>1</filter_duplicate_log_lines>

<!-- Specifies the frame rate limit that will be applied to connecting clients.
Available range: 25 to 100. Default: 36. -->
<fpslimit>36</fpslimit>
Expand Down
Loading

0 comments on commit f238c25

Please sign in to comment.