63 lines
1.6 KiB
C++
63 lines
1.6 KiB
C++
#include <qtLogger.h>
|
|
#include <stdLogger.hpp>
|
|
#include <iostream>
|
|
static std::string logBasePath = "./Log";
|
|
class logToQtWidget : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
void sendStdLogSignal(std::string str)
|
|
{
|
|
emit stdLogSignal(QString::fromStdString(str));
|
|
}
|
|
void sendQtLogSignal(std::string str)
|
|
{
|
|
emit qtLogSignal(QString::fromStdString(str));
|
|
}
|
|
void sendMainWindowStdLogSignal(std::string str)
|
|
{
|
|
emit mainWindowStdLogSignal(QString::fromStdString(str));
|
|
}
|
|
signals:
|
|
void mainWindowStdLogSignal(QString logMsg);
|
|
void stdLogSignal(QString logMsg);
|
|
void qtLogSignal(QString logMsg);
|
|
};
|
|
class logService
|
|
{
|
|
public:
|
|
stdConsoleRedirector* _stdConsoleRedirector;
|
|
FileLogger* stdFileLogger;
|
|
logToQtWidget _logToQtWidget;
|
|
logService()
|
|
{
|
|
//STD日志
|
|
|
|
_stdConsoleRedirector = new stdConsoleRedirector(std::cout);
|
|
|
|
//STD日志储存到文件
|
|
stdFileLogger = new FileLogger(logBasePath);
|
|
_stdConsoleRedirector->registerCallback([&](const std::string& output) {
|
|
stdFileLogger->processOutput(output);
|
|
});
|
|
//STD日志到Qt界面
|
|
_stdConsoleRedirector->registerCallback([&](const std::string& output) {
|
|
_logToQtWidget.sendStdLogSignal(output);
|
|
});
|
|
//STD日志到Qt主界面
|
|
_stdConsoleRedirector->registerCallback([&](const std::string& output) {
|
|
_logToQtWidget.sendMainWindowStdLogSignal(output);
|
|
});
|
|
//QT日志
|
|
LogMsg::Create(LogMsg::LogMsgType::DebugMsg, logBasePath);
|
|
qtLogCallbacks.push_back(([&](const std::string& output) {
|
|
_logToQtWidget.sendQtLogSignal(output);
|
|
}));
|
|
}
|
|
~logService()
|
|
{
|
|
delete _stdConsoleRedirector;
|
|
delete stdFileLogger;
|
|
}
|
|
};
|
|
#pragma once |