80 lines
2.2 KiB
C++
80 lines
2.2 KiB
C++
#include <iostream>
|
|
#include <QObject>
|
|
#include <QCoreApplication>
|
|
#include <QDebug>
|
|
#include <QDateTime>
|
|
#include <qlogging.h>
|
|
#include "spdLogSupport.hpp"
|
|
#include <qthread.h>
|
|
#include "stdLogRediretor.hpp"
|
|
#include "qtLogRediretor.h"
|
|
#include <qobject.h>
|
|
static std::string logBasePath = "./Log/";
|
|
class logToQtWidget : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
void sendStdLogSignal(const QString& str)
|
|
{
|
|
emit stdLogSignal(str);
|
|
}
|
|
void sendQtLogSignal(const QString& str)
|
|
{
|
|
emit qtLogSignal(str);
|
|
}
|
|
void sendMainWindowStdLogSignal(const QString& str)
|
|
{
|
|
emit mainWindowStdLogSignal(str);
|
|
}
|
|
signals:
|
|
void mainWindowStdLogSignal(QString logMsg);
|
|
void stdLogSignal(QString logMsg);
|
|
void qtLogSignal(QString logMsg);
|
|
};
|
|
class logService : public QThread
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
qtRediretor* _qtRediretor;
|
|
stdConsoleRedirector* _stdConsoleRedirector;
|
|
logToQtWidget* _logToQtWidget;
|
|
//SpdLogger stdLogger;
|
|
SpdLogger* qtLogger;
|
|
logService()
|
|
//stdLogger(logBasePath,"stdLog"),
|
|
//qtLogger(logBasePath, "Log")
|
|
{
|
|
//spdlog::init_thread_pool(8192,1);
|
|
qtLogger = new SpdLogger(logBasePath, "Log");
|
|
_logToQtWidget = new logToQtWidget();
|
|
//_logService = this;
|
|
//STD��־
|
|
//_stdConsoleRedirector = new stdConsoleRedirector(std::cout);
|
|
//QT��־
|
|
_qtRediretor = new qtRediretor();
|
|
//STD��־��Qt��־���� Qt������ spdLog
|
|
//_stdConsoleRedirector->registerCallback([&](const std::string& output) {
|
|
// QString outPutMsg(QString::fromStdString(output));
|
|
// _logToQtWidget->sendStdLogSignal(outPutMsg);//Qt��־����
|
|
// _logToQtWidget->sendMainWindowStdLogSignal(outPutMsg);//Qt������
|
|
// _logService->qtLogger->LogDebug("[STD]" + output);//spdLog
|
|
// _stdConsoleRedirector->writeToConsle(output); // ����ַ�д�뻺����
|
|
// });
|
|
// QT��־�� spdLog Qt��־����
|
|
_qtRediretor->registerCallback([&](const QString& output) {
|
|
this->qtLogger->LogDebug(output.toStdString());
|
|
//_logToQtWidget->sendQtLogSignal(output);//Qt��־����
|
|
//_stdConsoleRedirector->writeToConsle(output.toStdString()); // ����ַ�д�뻺����
|
|
});
|
|
|
|
|
|
}
|
|
~logService()
|
|
{
|
|
delete _stdConsoleRedirector;
|
|
delete _qtRediretor;
|
|
}
|
|
};
|
|
|
|
|
|
#pragma once |