Skip to content

Commit f238c25

Browse files
committed
Added duplicate log line filter for script debugging
1 parent ad27bf1 commit f238c25

File tree

11 files changed

+265
-41
lines changed

11 files changed

+265
-41
lines changed

MTA10/core/CClientVariables.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ void CClientVariables::LoadDefaults ( void )
326326
DEFAULT ( "browser_remote_websites", true ); // Load remote websites?
327327
DEFAULT ( "browser_remote_javascript", true ); // Execute javascript on remote websites?
328328
DEFAULT ( "browser_plugins", false ); // Enable browser plugins?
329+
DEFAULT ( "filter_duplicate_log_lines", true ); // Filter duplicate log lines for debug view and clientscript.log
329330

330331
if(!Exists("locale"))
331332
{

MTA10/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,7 @@ void CClientGame::DoPulses ( void )
10531053
#endif
10541054
m_pLatentTransferManager->DoPulse ();
10551055
m_pLuaManager->DoPulse ();
1056+
m_pScriptDebugging->UpdateLogOutput();
10561057

10571058
GetModelCacheManager ()->DoPulse ();
10581059

MTA10/mods/shared_logic/CScriptDebugging.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ CScriptDebugging::CScriptDebugging ( CLuaManager* pLuaManager )
3131

3232
CScriptDebugging::~CScriptDebugging ( void )
3333
{
34+
// Flush any pending duplicate loggings
35+
m_DuplicateLineFilter.Flush();
36+
UpdateLogOutput();
37+
3438
// Close the previously loaded file
3539
if ( m_pLogFile )
3640
{
@@ -403,11 +407,6 @@ void CScriptDebugging::LogString ( const char* szPrePend, const SLuaDebugInfo& l
403407
m_bTriggeringOnClientDebugMessage = false;
404408
}
405409

406-
// Log it to the file if enough level
407-
if ( m_uiLogFileLevel >= uiMinimumDebugLevel )
408-
{
409-
PrintLog ( strText );
410-
}
411410
switch ( uiMinimumDebugLevel )
412411
{
413412
case 1:
@@ -420,10 +419,30 @@ void CScriptDebugging::LogString ( const char* szPrePend, const SLuaDebugInfo& l
420419
ucRed = 0, ucGreen = 255, ucBlue = 0;
421420
break;
422421
}
423-
#ifdef MTA_DEBUG
424-
if ( !g_pCore->IsDebugVisible () ) return;
425-
#endif
426-
g_pCore->DebugEchoColor ( strText, ucRed, ucGreen, ucBlue );
422+
423+
m_DuplicateLineFilter.AddLine( strText, { uiMinimumDebugLevel, ucRed, ucGreen, ucBlue } );
424+
if ( g_pCore->GetCVars ()->GetValue < bool > ( "filter_duplicate_log_lines" ) == false )
425+
m_DuplicateLineFilter.Flush();
426+
UpdateLogOutput();
427+
}
428+
429+
430+
void CScriptDebugging::UpdateLogOutput( void )
431+
{
432+
SString strText;
433+
SLogData data;
434+
while( m_DuplicateLineFilter.PopOutputLine( strText, data ) )
435+
{
436+
// Log it to the file if enough level
437+
if ( m_uiLogFileLevel >= data.uiMinimumDebugLevel )
438+
{
439+
PrintLog ( strText );
440+
}
441+
#ifdef MTA_DEBUG
442+
if ( !g_pCore->IsDebugVisible () ) return;
443+
#endif
444+
g_pCore->DebugEchoColor ( strText, data.ucRed, data.ucGreen, data.ucBlue );
445+
}
427446
}
428447

429448

MTA10/mods/shared_logic/CScriptDebugging.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,19 @@
2222
#include <stdio.h>
2323

2424
#include "lua/LuaCommon.h"
25+
#include "CDuplicateLineFilter.h"
2526

2627
class CLuaManager;
2728

29+
struct SLogData
30+
{
31+
unsigned int uiMinimumDebugLevel;
32+
unsigned char ucRed;
33+
unsigned char ucGreen;
34+
unsigned char ucBlue;
35+
bool operator ==( const SLogData& other ) const { return uiMinimumDebugLevel == other.uiMinimumDebugLevel && ucRed == other.ucRed; }
36+
};
37+
2838
class CScriptDebugging
2939
{
3040
public:
@@ -52,6 +62,7 @@ class CScriptDebugging
5262
void PopLuaMain ( CLuaMain* pLuaMain );
5363
void OnLuaMainDestroy ( CLuaMain* pLuaMain );
5464
CLuaMain* GetTopLuaMain ( void );
65+
void UpdateLogOutput ( void );
5566

5667
private:
5768
SString ComposeErrorMessage ( const char* szPrePend, const SLuaDebugInfo& luaDebugInfo, const char* szMessage );
@@ -68,6 +79,7 @@ class CScriptDebugging
6879
SLuaDebugInfo m_SavedLuaDebugInfo;
6980
std::list < CLuaMain* > m_LuaMainStack;
7081
HANDLE m_flushTimerHandle;
82+
CDuplicateLineFilter < SLogData > m_DuplicateLineFilter;
7183
};
7284

7385
#endif

MTA10_Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ void CGame::DoPulse ( void )
484484
CLOCK_CALL1( m_pLatentTransferManager->DoPulse (); );
485485

486486
PrintLogOutputFromNetModule();
487+
m_pScriptDebugging->UpdateLogOutput();
487488

488489
// Unlock the critical section again
489490
Unlock();

MTA10_Server/mods/deathmatch/logic/CMainConfig.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,7 @@ const std::vector < SIntSetting >& CMainConfig::GetIntSettingList ( void )
14521452
{ true, true, 0, 0, 100, "server_logic_fps_limit", &m_iServerLogicFpsLimit, NULL },
14531453
{ true, true, 0, 1, 1, "bad_net_bullet_fix", &m_bBadNetBulletFixEnabled, NULL },
14541454
{ true, true, 0, 1, 1, "crash_dump_upload", &m_bCrashDumpUploadEnabled, NULL },
1455+
{ true, true, 0, 1, 1, "filter_duplicate_log_lines", &m_bFilterDuplicateLogLinesEnabled, NULL },
14551456
};
14561457

14571458
static std::vector < SIntSetting > settingsList;

MTA10_Server/mods/deathmatch/logic/CMainConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class CMainConfig: public CXMLConfig
126126
bool GetLoadstringLogEnabled ( void ) const { return !m_strLoadstringLogFilename.empty(); }
127127
bool GetBadNetBulletFixEnabled ( void ) const { return m_bBadNetBulletFixEnabled != 0; }
128128
bool GetCrashDumpUploadEnabled ( void ) const { return m_bCrashDumpUploadEnabled != 0; }
129+
bool GetFilterDuplicateLogLinesEnabled ( void ) const { return m_bFilterDuplicateLogLinesEnabled != 0; }
129130

130131
SString GetSetting ( const SString& configSetting );
131132
bool GetSetting ( const SString& configSetting, SString& strValue );
@@ -217,6 +218,7 @@ class CMainConfig: public CXMLConfig
217218
int m_iServerLogicFpsLimit;
218219
int m_bBadNetBulletFixEnabled;
219220
int m_bCrashDumpUploadEnabled;
221+
int m_bFilterDuplicateLogLinesEnabled;
220222
};
221223

222224
#endif

MTA10_Server/mods/deathmatch/logic/CScriptDebugging.cpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ CScriptDebugging::CScriptDebugging ( CLuaManager* pLuaManager )
2626
m_bTriggeringOnDebugMessage = false;
2727
}
2828

29+
CScriptDebugging::~CScriptDebugging ( void )
30+
{
31+
// Flush any pending duplicate loggings
32+
m_DuplicateLineFilter.Flush();
33+
UpdateLogOutput();
34+
35+
ClearPlayers ();
36+
}
2937

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

392-
// Log it to the file if enough level
393-
if ( m_uiLogFileLevel >= uiMinimumDebugLevel )
394-
{
395-
PrintLog ( strText );
396-
}
397-
398-
// Log to console
399-
CLogger::LogPrintf( "%s\n", strText.c_str () );
400+
m_DuplicateLineFilter.AddLine( strText, { uiMinimumDebugLevel, ucRed, ucGreen, ucBlue } );
401+
if ( g_pGame->GetConfig()->GetFilterDuplicateLogLinesEnabled() == false )
402+
m_DuplicateLineFilter.Flush();
403+
UpdateLogOutput();
404+
}
400405

401-
#if 0
402-
// Not sure what this is for, seems pretty useless
403-
if ( m_uiHtmlLogLevel >= uiMinimumDebugLevel )
406+
void CScriptDebugging::UpdateLogOutput( void )
407+
{
408+
SString strText;
409+
SLogData data;
410+
while( m_DuplicateLineFilter.PopOutputLine( strText, data ) )
404411
{
405-
if ( luaVM )
412+
// Log it to the file if enough level
413+
if ( m_uiLogFileLevel >= data.uiMinimumDebugLevel )
406414
{
407-
CLuaMain* pLuaMain = g_pGame->GetLuaManager()->GetVirtualMachine ( luaVM );
408-
if ( pLuaMain )
409-
{
410-
CResourceFile * file = pLuaMain->GetResourceFile();
411-
if ( file && file->GetType() == CResourceHTMLItem::RESOURCE_FILE_TYPE_HTML )
412-
{
413-
CResourceHTMLItem * html = (CResourceHTMLItem *)file;
414-
html->AppendToPageBuffer ( strText );
415-
html->AppendToPageBuffer ( "<br/>" );
416-
}
417-
}
415+
PrintLog ( strText );
418416
}
417+
// Log to console
418+
CLogger::LogPrintf( "%s\n", strText.c_str () );
419+
// Tell the players
420+
Broadcast ( CDebugEchoPacket ( strText, data.uiMinimumDebugLevel, data.ucRed, data.ucGreen, data.ucBlue ), data.uiMinimumDebugLevel );
419421
}
420-
#endif
421-
422-
// Tell the players
423-
Broadcast ( CDebugEchoPacket ( strText, uiMinimumDebugLevel, ucRed, ucGreen, ucBlue ), uiMinimumDebugLevel );
424422
}
425423

426-
427424
void CScriptDebugging::PrintLog ( const char* szText )
428425
{
429426
// Got a logfile?

MTA10_Server/mods/deathmatch/logic/CScriptDebugging.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,22 @@
1919
#include "packets/CPacket.h"
2020
#include <cstdio>
2121
#include <list>
22+
#include "CDuplicateLineFilter.h"
23+
24+
struct SLogData
25+
{
26+
unsigned int uiMinimumDebugLevel;
27+
unsigned char ucRed;
28+
unsigned char ucGreen;
29+
unsigned char ucBlue;
30+
bool operator ==( const SLogData& other ) const { return uiMinimumDebugLevel == other.uiMinimumDebugLevel && ucRed == other.ucRed; }
31+
};
2232

2333
class CScriptDebugging
2434
{
2535
public:
2636
CScriptDebugging ( CLuaManager* pLuaManager );
27-
inline ~CScriptDebugging ( void ) { ClearPlayers (); };
37+
~CScriptDebugging ( void );
2838

2939
bool AddPlayer ( class CPlayer& Player, unsigned int uiLevel );
3040
bool RemovePlayer ( class CPlayer& Player );
@@ -52,6 +62,7 @@ class CScriptDebugging
5262
void PopLuaMain ( CLuaMain* pLuaMain );
5363
void OnLuaMainDestroy ( CLuaMain* pLuaMain );
5464
CLuaMain* GetTopLuaMain ( void );
65+
void UpdateLogOutput ( void );
5566

5667
private:
5768
SString ComposeErrorMessage ( const char* szPrePend, const SLuaDebugInfo& luaDebugInfo, const char* szMessage );
@@ -68,6 +79,7 @@ class CScriptDebugging
6879
bool m_bTriggeringOnDebugMessage;
6980
SLuaDebugInfo m_SavedLuaDebugInfo;
7081
std::list < CLuaMain* > m_LuaMainStack;
82+
CDuplicateLineFilter < SLogData > m_DuplicateLineFilter;
7183
};
7284

7385
#endif

MTA10_Server/mods/deathmatch/mtaserver.conf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,17 @@
169169
<acl>acl.xml</acl>
170170

171171
<!-- Specifies the location and name of the debugscript log file. If left blank, server won't be saving this file. -->
172-
<scriptdebuglogfile>logs/scripts.log</scriptdebuglogfile>
173-
172+
<scriptdebuglogfile>logs/scripts.log</scriptdebuglogfile>
173+
174174
<!-- Specifies the level of the debugscript log file. Available values: 0, 1, 2, 3. When not set, defaults to 0. -->
175175
<scriptdebugloglevel>0</scriptdebugloglevel>
176-
176+
177177
<!-- Specifies the level of the html debug. Available values: 0, 1, 2, 3. When not set, defaults to 0. -->
178178
<htmldebuglevel>0</htmldebuglevel>
179179

180+
<!-- Specifies whether or not duplicate log lines should be filtered. Available values: 0 or 1, defaults to 1. -->
181+
<filter_duplicate_log_lines>1</filter_duplicate_log_lines>
182+
180183
<!-- Specifies the frame rate limit that will be applied to connecting clients.
181184
Available range: 25 to 100. Default: 36. -->
182185
<fpslimit>36</fpslimit>

0 commit comments

Comments
 (0)