chore: 格式化ElaWidgetTools代码
This commit is contained in:
@@ -5,69 +5,53 @@
|
||||
#include <QFile>
|
||||
#include <QMutex>
|
||||
#ifndef QT_NO_DEBUG
|
||||
#include <iostream>
|
||||
#include <iostream>
|
||||
#endif
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
#include <QTextStream>
|
||||
#include <QTextStream>
|
||||
#endif
|
||||
#include "ElaLog.h"
|
||||
Q_GLOBAL_STATIC(QMutex, messageLogMutex)
|
||||
Q_GLOBAL_STATIC(QString, logFileNameTime)
|
||||
ElaLogPrivate::ElaLogPrivate(QObject* parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
}
|
||||
ElaLogPrivate::ElaLogPrivate(QObject *parent) : QObject{parent} {}
|
||||
|
||||
ElaLogPrivate::~ElaLogPrivate()
|
||||
{
|
||||
}
|
||||
ElaLogPrivate::~ElaLogPrivate() {}
|
||||
|
||||
void ElaLogPrivate::_messageLogHander(QtMsgType type, const QMessageLogContext& ctx, const QString& msg)
|
||||
{
|
||||
if (type > QtCriticalMsg)
|
||||
{
|
||||
void ElaLogPrivate::_messageLogHander(QtMsgType type, const QMessageLogContext &ctx, const QString &msg) {
|
||||
if (type > QtCriticalMsg) {
|
||||
return;
|
||||
}
|
||||
QString logInfo;
|
||||
QString logTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
|
||||
switch (type)
|
||||
{
|
||||
case QtDebugMsg:
|
||||
{
|
||||
switch (type) {
|
||||
case QtDebugMsg: {
|
||||
logInfo = QString("[信息-%1](函数: %2 , 行数: %3) -> %4").arg(logTime, ctx.function, QString::number(ctx.line), msg);
|
||||
break;
|
||||
}
|
||||
case QtWarningMsg:
|
||||
{
|
||||
case QtWarningMsg: {
|
||||
logInfo = QString("[警告-%1](函数: %2 , 行数: %3) -> %4").arg(logTime, ctx.function, QString::number(ctx.line), msg);
|
||||
break;
|
||||
}
|
||||
case QtCriticalMsg:
|
||||
{
|
||||
case QtCriticalMsg: {
|
||||
logInfo = QString("[错误-%1](函数: %2 , 行数: %3) -> %4").arg(logTime, ctx.function, QString::number(ctx.line), msg);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
qCritical("发生致命错误!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
qDebug() << logInfo;
|
||||
ElaLog* log = ElaLog::getInstance();
|
||||
ElaLog *log = ElaLog::getInstance();
|
||||
Q_EMIT log->logMessage(logInfo);
|
||||
messageLogMutex->lock();
|
||||
QFile logfile;
|
||||
if (log->getIsLogFileNameWithTime())
|
||||
{
|
||||
if (log->getIsLogFileNameWithTime()) {
|
||||
logfile.setFileName(log->getLogSavePath() + "\\" + log->getLogFileName() + *logFileNameTime + ".txt");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
logfile.setFileName(log->getLogSavePath() + "\\" + log->getLogFileName() + ".txt");
|
||||
}
|
||||
if (logfile.open(QIODevice::WriteOnly | QIODevice::Append))
|
||||
{
|
||||
if (logfile.open(QIODevice::WriteOnly | QIODevice::Append)) {
|
||||
QTextStream logFileStream(&logfile);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
logFileStream << logInfo << Qt::endl;
|
||||
@@ -79,23 +63,17 @@ void ElaLogPrivate::_messageLogHander(QtMsgType type, const QMessageLogContext&
|
||||
messageLogMutex->unlock();
|
||||
}
|
||||
|
||||
void ElaLogPrivate::_clearLogFile()
|
||||
{
|
||||
if (_pIsLogFileNameWithTime)
|
||||
{
|
||||
void ElaLogPrivate::_clearLogFile() {
|
||||
if (_pIsLogFileNameWithTime) {
|
||||
QString logTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh-mm-ss");
|
||||
logTime.prepend("_");
|
||||
logTime.replace(" ", "_");
|
||||
logFileNameTime->clear();
|
||||
logFileNameTime->append(logTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
QFile file(_pLogSavePath + "\\" + _pLogFileName + ".txt");
|
||||
if (file.exists())
|
||||
{
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text | QFile::Truncate))
|
||||
{
|
||||
if (file.exists()) {
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text | QFile::Truncate)) {
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user