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:
@@ -381,36 +381,31 @@ void ReportOutput::restoreFont()
|
||||
setFont(serifFont);
|
||||
}
|
||||
|
||||
void ReportOutput::Warning(const char * s)
|
||||
void ReportOutput::SendLog(const std::string& msg, Base::LogStyle level)
|
||||
{
|
||||
// Send the event to itself to allow thread-safety. Qt will delete it when done.
|
||||
CustomReportEvent* ev = new CustomReportEvent(ReportHighlighter::Warning, QString::fromUtf8(s));
|
||||
QApplication::postEvent(this, ev);
|
||||
}
|
||||
|
||||
void ReportOutput::Message(const char * s)
|
||||
{
|
||||
// Send the event to itself to allow thread-safety. Qt will delete it when done.
|
||||
CustomReportEvent* ev = new CustomReportEvent(ReportHighlighter::Message, QString::fromUtf8(s));
|
||||
QApplication::postEvent(this, ev);
|
||||
}
|
||||
|
||||
void ReportOutput::Error (const char * s)
|
||||
{
|
||||
// Send the event to itself to allow thread-safety. Qt will delete it when done.
|
||||
CustomReportEvent* ev = new CustomReportEvent(ReportHighlighter::Error, QString::fromUtf8(s));
|
||||
QApplication::postEvent(this, ev);
|
||||
}
|
||||
|
||||
void ReportOutput::Log (const char * s)
|
||||
{
|
||||
QString msg = QString::fromUtf8(s);
|
||||
if(messageSize>0 && msg.size()>messageSize) {
|
||||
msg.truncate(messageSize);
|
||||
msg += QString::fromLatin1("...\n");
|
||||
ReportHighlighter::Paragraph style = ReportHighlighter::LogText;
|
||||
switch(level){
|
||||
case Base::LogStyle::Warning:
|
||||
style = ReportHighlighter::Warning;
|
||||
break;
|
||||
case Base::LogStyle::Message:
|
||||
style = ReportHighlighter::Message;
|
||||
break;
|
||||
case Base::LogStyle::Error:
|
||||
style = ReportHighlighter::Error;
|
||||
break;
|
||||
case Base::LogStyle::Log:
|
||||
style = ReportHighlighter::LogText;
|
||||
break;
|
||||
}
|
||||
// This truncates messages that are too long
|
||||
QString qMsg = QString::fromUtf8(msg.c_str());
|
||||
if(messageSize > 0 && qMsg.size()>messageSize) {
|
||||
qMsg.truncate(messageSize);
|
||||
qMsg += QString::fromLatin1("...\n");
|
||||
}
|
||||
// Send the event to itself to allow thread-safety. Qt will delete it when done.
|
||||
CustomReportEvent* ev = new CustomReportEvent(ReportHighlighter::LogText, msg);
|
||||
CustomReportEvent* ev = new CustomReportEvent(style, qMsg);
|
||||
QApplication::postEvent(this, ev);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user