2025-06-19 16:20:01 +08:00
|
|
|
#include "LogControl.h"
|
2025-06-15 14:31:54 +08:00
|
|
|
|
|
|
|
|
#include <QDateTime>
|
2025-06-19 16:20:01 +08:00
|
|
|
#include <QListWidgetItem>
|
2025-06-15 14:31:54 +08:00
|
|
|
#include <QStandardItem>
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
#include "ui_LogControl.h"
|
|
|
|
|
|
|
|
|
|
LogPrint::LogPrint(QWidget* parent) : QWidget(parent), ui(new Ui::LogPrint)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
InitControl();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LogPrint::InitControl()
|
|
|
|
|
{
|
2025-06-20 15:08:37 +08:00
|
|
|
ui->pedText->setReadOnly(true);
|
2025-06-15 14:31:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LogPrint::now_str()
|
|
|
|
|
{
|
|
|
|
|
auto now = std::chrono::system_clock::now();
|
|
|
|
|
auto time_t_now = std::chrono::system_clock::to_time_t(now);
|
|
|
|
|
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
|
|
|
|
|
|
|
|
|
|
std::ostringstream timestamp;
|
|
|
|
|
timestamp << std::put_time(std::localtime(&time_t_now), "%H:%M:%S") << "." << std::setfill('0') << std::setw(3)
|
|
|
|
|
<< milliseconds.count() << " ";
|
|
|
|
|
|
|
|
|
|
return timestamp.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LogPrint::~LogPrint()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LogPrint::Info(const QString& message)
|
|
|
|
|
{
|
|
|
|
|
Print(message, Qt::black);
|
|
|
|
|
}
|
|
|
|
|
void LogPrint::Warn(const QString& message)
|
|
|
|
|
{
|
2025-06-15 20:37:25 +08:00
|
|
|
Print(message, Qt::gray);
|
2025-06-15 14:31:54 +08:00
|
|
|
}
|
|
|
|
|
void LogPrint::Error(const QString& message)
|
|
|
|
|
{
|
|
|
|
|
Print(message, Qt::red);
|
|
|
|
|
}
|
|
|
|
|
void LogPrint::Debug(const QString& message)
|
|
|
|
|
{
|
|
|
|
|
Print(message, Qt::blue);
|
|
|
|
|
}
|
|
|
|
|
void LogPrint::Print(const QString& message, const QBrush& color)
|
|
|
|
|
{
|
2025-06-20 15:08:37 +08:00
|
|
|
QString timeStr = QString("%1%2").arg(QString::fromStdString(now_str())).arg(message);
|
|
|
|
|
|
|
|
|
|
QString coloredLog = QString("<span style='color:%1;'>%2</span>")
|
|
|
|
|
.arg(color.color().name())
|
|
|
|
|
.arg(timeStr.toHtmlEscaped());
|
|
|
|
|
ui->pedText->appendHtml(coloredLog);
|
2025-06-15 14:31:54 +08:00
|
|
|
}
|