void CScriptDebugging::UpdateLogOutput( void ) { SLogLine line; while( m_DuplicateLineFilter.PopOutputLine( line ) ) { // Log it to the file if enough level if ( m_uiLogFileLevel >= line.uiMinimumDebugLevel ) { PrintLog ( line.strText ); } // Log to console CLogger::LogPrintf( "%s\n", line.strText.c_str () ); // Tell the players Broadcast ( CDebugEchoPacket ( line.strText, line.uiMinimumDebugLevel, line.ucRed, line.ucGreen, line.ucBlue ), line.uiMinimumDebugLevel ); } }
void CScriptDebugging::LogError ( SString strFile, int iLine, SString strMsg ) { SString strText = SString ( "ERROR: %s:%d: %s", strFile.c_str (), iLine, strMsg.c_str () ); if ( !m_bTriggeringOnDebugMessage ) { m_bTriggeringOnDebugMessage = true; // Prepare onDebugMessage CLuaArguments Arguments; Arguments.PushString ( strMsg.c_str ( ) ); Arguments.PushNumber ( 1 ); // Push the file name (if any) if ( strFile.length ( ) > 0 ) Arguments.PushString ( strFile.c_str ( ) ); else Arguments.PushNil ( ); // Push the line (if any) if ( iLine > -1 ) Arguments.PushNumber ( iLine ); else Arguments.PushNil ( ); // Call onDebugMessage g_pGame->GetMapManager ( )->GetRootElement ( )->CallEvent ( "onDebugMessage", Arguments ); m_bTriggeringOnDebugMessage = false; } // Log it to the file if enough level if ( m_uiLogFileLevel >= 1 ) { PrintLog ( strText ); } // Log to console CLogger::LogPrintf( "%s\n", strText.c_str () ); // Tell the players Broadcast ( CDebugEchoPacket ( strText, 1, 255, 255, 255 ), 1 ); }
void CScriptDebugging::LogString ( const char* szPrePend, lua_State * luaVM, const char* szMessage, unsigned int uiMinimumDebugLevel, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue ) { SString strText; lua_Debug debugInfo; // Initialize values for onDebugMessage SString strMsg = szMessage; SString strFile = ""; int iLine = -1; // Get a VM from somewhere if ( !luaVM && !m_LuaMainStack.empty () ) luaVM = m_LuaMainStack.back ()->GetVM (); for ( int level = 1; level < 3; level++ ) { if ( luaVM && lua_getstack ( luaVM, level, &debugInfo ) ) { lua_getinfo ( luaVM, "nlS", &debugInfo ); // Make sure this function isn't defined in a string (eg: from runcode) if ( debugInfo.source[0] == '@' ) { // Get and store the location of the debug message strFile = debugInfo.source + 1; iLine = debugInfo.currentline; // Populate a message to print/send (unless "info" type) if ( uiMinimumDebugLevel < 3 ) strText = SString ( "%s%s:%d: %s", szPrePend, strFile.c_str (), debugInfo.currentline, szMessage ); // if the file isn't empty, stop trying any other levels break; } else { strFile = debugInfo.short_src; if ( uiMinimumDebugLevel < 3 ) strText = SString ( "%s%s %s", szPrePend, szMessage, strFile.c_str () ); if ( strFile != "[string \"?\"]" ) // if the file isn't empty, stop trying any other levels break; } } else { strText = SString ( "%s%s%s", szPrePend, m_strLineAndFile.c_str(), szMessage ); // no point in trying other levels break; } } // Create a different message if type is "INFO" if ( uiMinimumDebugLevel > 2 ) strText = SString ( "%s%s", szPrePend, szMessage ); // Check whether onDebugMessage is currently being triggered if ( !m_bTriggeringOnDebugMessage ) { // Make sure the state of onDebugMessage being triggered can be retrieved later m_bTriggeringOnDebugMessage = true; // Prepare onDebugMessage CLuaArguments Arguments; Arguments.PushString ( strMsg.c_str ( ) ); Arguments.PushNumber ( uiMinimumDebugLevel ); // Push the file name (if any) if ( strFile.length ( ) > 0 ) Arguments.PushString ( strFile.c_str ( ) ); else Arguments.PushNil ( ); // Push the line (if any) if ( iLine > -1 ) Arguments.PushNumber ( iLine ); else Arguments.PushNil ( ); // Call onDebugMessage g_pGame->GetMapManager ( )->GetRootElement ( )->CallEvent ( "onDebugMessage", Arguments ); // Reset trigger state, so onDebugMessage can be called again at a later moment 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 () ); // Not sure what this is for, seems pretty useless if ( m_uiHtmlLogLevel >= uiMinimumDebugLevel ) { if ( luaVM ) { 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/>" ); } } } } // Tell the players Broadcast ( CDebugEchoPacket ( strText, uiMinimumDebugLevel, ucRed, ucGreen, ucBlue ), uiMinimumDebugLevel ); }
void CScriptDebugging::LogString ( const char* szPrePend, const SLuaDebugInfo& luaDebugInfo, const char* szMessage, unsigned int uiMinimumDebugLevel, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue ) { SString strText = ComposeErrorMessage( szPrePend, luaDebugInfo, szMessage ); // Create a different message if type is "INFO" if ( uiMinimumDebugLevel > 2 ) strText = SString ( "%s%s", szPrePend, szMessage ); // Check whether onDebugMessage is currently being triggered if ( !m_bTriggeringOnDebugMessage ) { // Make sure the state of onDebugMessage being triggered can be retrieved later m_bTriggeringOnDebugMessage = true; // Prepare onDebugMessage CLuaArguments Arguments; Arguments.PushString ( szMessage ); Arguments.PushNumber ( uiMinimumDebugLevel ); // Push the file name (if any) if ( !luaDebugInfo.strFile.empty() ) Arguments.PushString ( luaDebugInfo.strFile ); else Arguments.PushNil ( ); // Push the line (if any) if ( luaDebugInfo.iLine != INVALID_LINE_NUMBER ) Arguments.PushNumber ( luaDebugInfo.iLine ); else Arguments.PushNil ( ); // Call onDebugMessage g_pGame->GetMapManager ( )->GetRootElement ( )->CallEvent ( "onDebugMessage", Arguments ); // Reset trigger state, so onDebugMessage can be called again at a later moment 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 () ); #if 0 // Not sure what this is for, seems pretty useless if ( m_uiHtmlLogLevel >= uiMinimumDebugLevel ) { if ( luaVM ) { 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/>" ); } } } } #endif // Tell the players Broadcast ( CDebugEchoPacket ( strText, uiMinimumDebugLevel, ucRed, ucGreen, ucBlue ), uiMinimumDebugLevel ); }