16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 00:49:19 +02:00

Console errors highlight

This commit is contained in:
2025-07-23 14:24:56 +02:00
parent c0437946c7
commit 1fba26c6cc
4 changed files with 15 additions and 21 deletions

View File

@@ -27,7 +27,7 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup") #pragma comment(linker, "/subsystem:console /ENTRY:mainCRTStartup")
#endif #endif
void export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic); void export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic);

View File

@@ -70,7 +70,7 @@ std::string filename_scenery() {
} }
// log service stacks // log service stacks
std::deque<std::string> InfoStack; std::deque < std::pair<std::string, bool>> InfoStack;
std::deque<std::string> ErrorStack; std::deque<std::string> ErrorStack;
// lock for log stacks // lock for log stacks
@@ -86,10 +86,12 @@ void LogService()
while (!InfoStack.empty()) while (!InfoStack.empty())
{ {
logMutex.lock(); logMutex.lock();
std::string msg = InfoStack.front(); std::string msg = InfoStack.front().first;
bool isError = InfoStack.front().second;
InfoStack.pop_front(); InfoStack.pop_front();
logMutex.unlock(); logMutex.unlock();
// log to file
if (Global.iWriteLogEnabled & 1) if (Global.iWriteLogEnabled & 1)
{ {
if (!output.is_open()) if (!output.is_open())
@@ -101,20 +103,18 @@ void LogService()
output.flush(); output.flush();
} }
// log to scrollback imgui
log_scrollback.emplace_back(msg); log_scrollback.emplace_back(msg);
if (log_scrollback.size() > 200) if (log_scrollback.size() > 200)
log_scrollback.pop_front(); log_scrollback.pop_front();
// log to console
if (Global.iWriteLogEnabled & 2) if (Global.iWriteLogEnabled & 2)
{ {
#ifdef _WIN32 if (isError)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY); printf("\033[1;37;41m%s\033[0m\n", msg.c_str());
DWORD wr = 0; else
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), msg.c_str(), (DWORD)msg.size(), &wr, NULL); printf("\033[32m%s\033[0m\n", msg.c_str());
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), endstring, (DWORD)strlen(endstring), &wr, NULL);
#else
printf("%s\n", msg.c_str());
#endif
} }
} }
@@ -146,14 +146,14 @@ void LogService()
} }
void WriteLog(const char *str, logtype const Type) void WriteLog(const char *str, logtype const Type, bool isError)
{ {
if (!str || *str == '\0') if (!str || *str == '\0')
return; return;
if (TestFlag(Global.DisabledLogTypes, static_cast<unsigned int>(Type))) if (TestFlag(Global.DisabledLogTypes, static_cast<unsigned int>(Type)))
return; return;
logMutex.lock(); logMutex.lock();
InfoStack.emplace_back(str); InfoStack.emplace_back(str, isError);
logMutex.unlock(); logMutex.unlock();
} }
@@ -187,7 +187,7 @@ void Error(const char *&asMessage, bool box)
void ErrorLog(const std::string &str, logtype const Type ) void ErrorLog(const std::string &str, logtype const Type )
{ {
ErrorLog( str.c_str(), Type ); ErrorLog( str.c_str(), Type );
WriteLog( str.c_str(), Type ); WriteLog( str.c_str(), Type, true );
} }
void WriteLog(const std::string &str, logtype const Type ) void WriteLog(const std::string &str, logtype const Type )

2
Logs.h
View File

@@ -24,7 +24,7 @@ enum class logtype : unsigned int {
powergrid = ( 1 << 10 ), powergrid = ( 1 << 10 ),
}; };
void LogService(); void LogService();
void WriteLog( const char *str, logtype const Type = logtype::generic ); void WriteLog( const char *str, logtype const Type = logtype::generic, bool isError = false );
void Error( const std::string &asMessage, bool box = false ); void Error( const std::string &asMessage, bool box = false );
void Error( const char* &asMessage, bool box = false ); void Error( const char* &asMessage, bool box = false );
void ErrorLog( const std::string &str, logtype const Type = logtype::generic ); void ErrorLog( const std::string &str, logtype const Type = logtype::generic );

View File

@@ -840,12 +840,6 @@ eu07_application::init_settings( int Argc, char *Argv[] ) {
Global.asVersion = VERSION_INFO; Global.asVersion = VERSION_INFO;
Global.LoadIniFile( "eu07.ini" ); Global.LoadIniFile( "eu07.ini" );
#ifdef _WIN32
if( ( Global.iWriteLogEnabled & 2 ) != 0 ) {
// show output console if requested
AllocConsole();
}
#endif
// process command line arguments // process command line arguments
for( int i = 1; i < Argc; ++i ) { for( int i = 1; i < Argc; ++i ) {