Refactor and rename ConsoleObserver...
...Renamed to "ILogger", to designate that this is an Interface for a Logger. This "Interface" is pure virtual, so that it cannot be instantiated directly. This makes it clear that it is intended to be derived. Finally, got rid of all the individual log-style methods and replaced with SendLog. The idea here is that day-to-day users will only interact with ILogger through ConsoleSingleton (or, likely, LoggerSingleton in the future). This singleton will manage an arbirtary collection of ILogger, and call SendLog with the appropriate parameters based on what the user requests. Therefore, the singleton itself will have the individual Log, Message, Error, etc... methods, while stil allowing us to simplify the code base of ILogger and its derived classes.
This commit is contained in:
@@ -84,30 +84,27 @@ GUIConsole::~GUIConsole (void)
|
||||
FreeConsole();
|
||||
}
|
||||
|
||||
void GUIConsole::Message(const char *sMsg)
|
||||
void GUIConsole::SendLog(const std::string& msg, Base::LogStyle level)
|
||||
{
|
||||
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN);
|
||||
printf("%s",sMsg);
|
||||
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
|
||||
}
|
||||
int color = -1;
|
||||
switch(level){
|
||||
case Base::LogStyle::Warning:
|
||||
color = FOREGROUND_RED | FOREGROUND_GREEN;
|
||||
break;
|
||||
case Base::LogStyle::Message:
|
||||
color = FOREGROUND_GREEN;
|
||||
break;
|
||||
case Base::LogStyle::Error:
|
||||
color = FOREGROUND_RED;
|
||||
break;
|
||||
case Base::LogStyle::Log:
|
||||
color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
||||
break;
|
||||
}
|
||||
|
||||
void GUIConsole::Warning(const char *sWarn)
|
||||
{
|
||||
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN);
|
||||
printf("%s",sWarn);
|
||||
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
|
||||
}
|
||||
|
||||
void GUIConsole::Error (const char *sErr)
|
||||
{
|
||||
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED );
|
||||
printf("%s",sErr);
|
||||
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
|
||||
}
|
||||
|
||||
void GUIConsole::Log (const char *sLog)
|
||||
{
|
||||
printf("%s",sLog);
|
||||
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), color);
|
||||
printf("%s", msg.c_str());
|
||||
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
|
||||
}
|
||||
|
||||
#else /* FC_OS_LINUX */
|
||||
@@ -115,9 +112,22 @@ void GUIConsole::Log (const char *sLog)
|
||||
// safely ignore GUIConsole::s_nMaxLines and GUIConsole::s_nRefCount
|
||||
GUIConsole::GUIConsole (void) {}
|
||||
GUIConsole::~GUIConsole (void) {}
|
||||
void GUIConsole::Message(const char *sMsg) { std::cout<<sMsg; }
|
||||
void GUIConsole::Warning(const char *sWarn){ std::cerr<<"Warning: "<<sWarn; }
|
||||
void GUIConsole::Error (const char *sErr) { std::cerr<<"Error: "<<sErr;}
|
||||
void GUIConsole::Log (const char *sLog) { std::clog<<sLog;}
|
||||
void GUIConsole::SendLog(const std::string& msg, Base::LogStyle level)
|
||||
{
|
||||
switch(level){
|
||||
case Base::LogStyle::Warning:
|
||||
std::cerr << "Warning: " << msg;
|
||||
break;
|
||||
case Base::LogStyle::Message:
|
||||
std::cout << msg;
|
||||
break;
|
||||
case Base::LogStyle::Error:
|
||||
std::cerr << "Error: " << msg;
|
||||
break;
|
||||
case Base::LogStyle::Log:
|
||||
std::clog << msg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* FC_OS_LINUX */
|
||||
|
||||
Reference in New Issue
Block a user