HAL
logger_marshall.cpp
Go to the documentation of this file.
3 
4 #include <QTimer>
5 
6 #include <algorithm>
7 #include <functional>
8 #include <map>
9 
10 namespace hal
11 {
12  LoggerMarshall::LoggerMarshall(QPlainTextEdit* edit, QObject* parent) : QObject(parent), mEdit(edit)
13  {
14  mMaxLineCount = 1000;
15  mEdit->document()->setMaximumBlockCount(mMaxLineCount);
16  }
17 
18  void LoggerMarshall::appendLog(spdlog::level::level_enum t, const QString& msg)
19  {
20  static const QString beginHTML = "<p><font color=\"";
21  static const QString intermediateHTML = "\">";
22  static const QString endHTML = "</font></p>";
23 
24  QString html_ready_msg = msg.toHtmlEscaped().replace(" ", "&nbsp;");
25 
26  QString color;
27 
28  switch (t)
29  {
30  case spdlog::level::level_enum::trace:
32  break;
33  case spdlog::level::level_enum::debug:
35  break;
36  case spdlog::level::level_enum::info:
38  break;
39  case spdlog::level::level_enum::warn:
41  break;
42  case spdlog::level::level_enum::err:
44  break;
45  case spdlog::level::level_enum::critical:
47  break;
48  default:
50  break;
51  }
52 
53  mEdit->appendHtml(beginHTML + color + intermediateHTML + html_ready_msg + endHTML);
54  }
55 }
LoggerMarshall(QPlainTextEdit *edit, QObject *parent=nullptr)
void appendLog(spdlog::level::level_enum log_type, QString const &msg)
static LoggerQssAdapter * instance()
QString name() const const
void appendHtml(const QString &html)
QTextDocument * document() const const
QString & replace(int position, int n, QChar after)
QString toHtmlEscaped() const const
void setMaximumBlockCount(int maximum)