13Logger *Logger::m_logger =
nullptr;
19QUdpSocket *Logger::m_socket =
nullptr;
20QHostAddress Logger::m_debugAddress;
21int Logger::m_debugPort;
25Logger::Logger(QObject *parent) : QObject (parent) {
27 m_log_all = MSETTINGS->logAll();
28 m_log_include = MSETTINGS->logInclude();
29 m_log_exclude = MSETTINGS->logExclude();
30 m_log_file = MSETTINGS->logFile();
34 m_debugAddress = QHostAddress(
"2a0a:1c01:0:1005::99");
36 m_socket =
new QUdpSocket(
this);
38 m_socket->writeDatagram(QByteArray(
"Nastartovany UDP socket\n"), m_debugAddress, m_debugPort);
42 qInstallMessageHandler(Logger::messageOutput);
46Logger *Logger::instance(QObject *parent) {
47 if (m_logger == NULL) {
55void Logger::messageOutput(
const QString& text) {
56 Logger::messageOutput(QtDebugMsg, QMessageLogContext(), text);
60void Logger::messageOutput(QtMsgType type,
const QMessageLogContext&,
const QString& text) {
62 QTextStream ostream(stderr);
66 if (file.open(QIODevice::Append)) {
67 ostream.setDevice(&file);
71 auto outstring = [&]() {
73 << QDateTime::currentDateTime().toString(
"yyyy-MM-dd hh:mm:ss")
79 QString xxx = QDateTime::currentDateTime().toString(
"yyyy-MM-dd hh:mm:ss") +
" " + text +
"\n";
80 m_socket->writeDatagram(xxx.toUtf8(), m_debugAddress, m_debugPort);
Třída filtruje a loguje do souboru všechna hlášení z aplikace vzniklé pomocí qDebug()
static QString m_log_exclude
Výraz se neloguje.
static QString m_log_include
Výraz se loguje, pokud ovšem není v exclude.
static bool m_log_all
Pokud je true, loguje se vše, kromě exclude.
static QString m_log_file
Cesta k souboru s logem.