Compare commits

...

2 Commits

Author SHA1 Message Date
朱子楚\zhuzi b4f2f68135 update 2023-12-04 21:25:44 +08:00
朱子楚\zhuzi 5d4cfa5286 fix bug 2023-12-04 21:18:19 +08:00
5 changed files with 84 additions and 2 deletions

View File

@ -0,0 +1,70 @@
#include "Log.h"
#include <QtCore/qdebug.h>
#include <QtCore/qfile.h>
#include <QtCore/qtextstream.h>
#include <iostream>
#include <framelesshelpercore_global.h>
#ifndef QT_ENDL
# if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
# define QT_ENDL Qt::endl
# else
# define QT_ENDL endl
# endif
#endif
static QString g_app = {};
static bool g_logError = false;
static std::unique_ptr<QFile> g_logFile = nullptr;
static std::unique_ptr<QTextStream> g_logStream = nullptr;
static inline void myMessageHandler(const QtMsgType type, const QMessageLogContext &context, const QString &message)
{
if (message.isEmpty()) {
return;
}
const QString finalMessage = qFormatLogMessage(type, context, message).trimmed();
if ((type == QtInfoMsg) || (type == QtDebugMsg)) {
std::cout << qUtf8Printable(finalMessage) << std::endl;
} else {
std::cerr << qUtf8Printable(finalMessage) << std::endl;
}
if (g_logError) {
return;
}
if (!g_logFile) {
g_logFile = std::make_unique<QFile>();
g_logFile->setFileName(FRAMELESSHELPER_STRING_LITERAL("debug-%1.log").arg(g_app));
if (!g_logFile->open(QFile::WriteOnly | QFile::Text | QFile::Append)) {
std::cerr << "Can't open file to write: " << qUtf8Printable(g_logFile->errorString()) << std::endl;
g_logFile.reset();
g_logError = true;
return;
}
}
if (!g_logStream) {
g_logStream = std::make_unique<QTextStream>();
g_logStream->setDevice(g_logFile.get());
}
(*g_logStream) << finalMessage << QT_ENDL;
}
void Log::setup(const QString &app)
{
Q_ASSERT(!app.isEmpty());
if (app.isEmpty()) {
return;
}
static bool once = false;
if (once) {
return;
}
once = true;
g_app = app;
qSetMessagePattern(FRAMELESSHELPER_STRING_LITERAL(
"[%{time yyyy/MM/dd hh:mm:ss.zzz}] <%{if-info}INFO%{endif}%{if-debug}DEBUG"
"%{endif}%{if-warning}WARNING%{endif}%{if-critical}CRITICAL%{endif}%{if-fatal}"
"FATAL%{endif}> %{if-category}%{category}: %{endif}%{message}"));
qInstallMessageHandler(myMessageHandler);
}

10
example/src/helper/Log.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef LOG_H
#define LOG_H
#include <QtCore/qstring.h>
namespace Log
{
void setup(const QString &app);
}
#endif // LOG_H

View File

@ -9,6 +9,7 @@
#include <QtQml/qqmlextensionplugin.h>
#include <QLoggingCategory>
#include "AppInfo.h"
#include "helper/Log.h"
#include "src/component/CircularReveal.h"
#include "src/component/FileWatcher.h"
#include "src/component/FpsItem.h"
@ -23,6 +24,7 @@ Q_IMPORT_QML_PLUGIN(FluentUIPlugin)
int main(int argc, char *argv[])
{
Log::setup("example");
QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

@ -1 +1 @@
Subproject commit 49c72fb4f85421f770a6a14657ba73a9912ee833
Subproject commit 27fcd913b4b21b51d5cca307e47e93d1ae75e1bb

View File

@ -24,7 +24,7 @@ FluApp::~FluApp(){
void FluApp::init(QObject *application){
this->_application = application;
FramelessHelper::Quick::initialize();
FramelessHelperQuickInitialize();
FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial);
FramelessConfig::instance()->set(Global::Option::CenterWindowBeforeShow);
QQmlEngine *engine = qmlEngine(_application);