2021-11-18 14:58:01 +00:00
|
|
|
#include "log_browser.h"
|
|
|
|
#include "log_browser_dialog.h"
|
2022-10-18 09:35:04 +00:00
|
|
|
#include <QDir>
|
|
|
|
#include <QMetaType>
|
2018-04-07 08:44:39 +00:00
|
|
|
|
2020-11-09 10:46:06 +00:00
|
|
|
bool LogBrowser::m_enableOutputToFile = true;
|
2020-04-07 23:15:20 +00:00
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
LogBrowser::LogBrowser(QObject* parent)
|
|
|
|
: QObject(parent)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
|
|
|
qRegisterMetaType<QtMsgType>("QtMsgType");
|
|
|
|
m_browserDialog = new LogBrowserDialog;
|
2018-05-12 10:07:46 +00:00
|
|
|
connect(this, &LogBrowser::sendMessage, m_browserDialog, &LogBrowserDialog::outputMessage, Qt::QueuedConnection);
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2020-04-07 23:15:20 +00:00
|
|
|
if (m_enableOutputToFile) {
|
2021-11-18 14:58:01 +00:00
|
|
|
QString filePath = "application.log";
|
2020-04-07 23:15:20 +00:00
|
|
|
m_outputTo = fopen(filePath.toUtf8().constData(), "w");
|
|
|
|
}
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LogBrowser::~LogBrowser()
|
|
|
|
{
|
|
|
|
delete m_browserDialog;
|
2020-04-07 23:15:20 +00:00
|
|
|
if (m_outputTo)
|
|
|
|
fclose(m_outputTo);
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
|
2018-04-10 07:59:20 +00:00
|
|
|
void LogBrowser::showDialog()
|
|
|
|
{
|
|
|
|
m_browserDialog->show();
|
|
|
|
m_browserDialog->activateWindow();
|
|
|
|
m_browserDialog->raise();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogBrowser::hideDialog()
|
|
|
|
{
|
|
|
|
m_browserDialog->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LogBrowser::isDialogVisible()
|
|
|
|
{
|
|
|
|
return m_browserDialog->isVisible();
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
void LogBrowser::outputMessage(QtMsgType type, const QString& msg, const QString& source, int line)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
2020-04-07 23:15:20 +00:00
|
|
|
if (m_outputTo) {
|
|
|
|
fprintf(m_outputTo, "[%s:%d]: %s\n", source.toUtf8().constData(), line, msg.toUtf8().constData());
|
|
|
|
fflush(m_outputTo);
|
|
|
|
}
|
2018-05-12 10:07:46 +00:00
|
|
|
emit sendMessage(type, msg, source, line);
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|