mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-02-09 00:05:39 +08:00
update log
This commit is contained in:
parent
bd8a561590
commit
c1ffce06aa
@ -155,6 +155,11 @@ set_target_properties(example PROPERTIES
|
|||||||
WIN32_EXECUTABLE TRUE
|
WIN32_EXECUTABLE TRUE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(example
|
||||||
|
PRIVATE
|
||||||
|
QT_MESSAGELOGCONTEXT
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries(example PRIVATE
|
target_link_libraries(example PRIVATE
|
||||||
Qt${QT_VERSION_MAJOR}::Quick
|
Qt${QT_VERSION_MAJOR}::Quick
|
||||||
Qt${QT_VERSION_MAJOR}::Svg
|
Qt${QT_VERSION_MAJOR}::Svg
|
||||||
|
@ -2,9 +2,17 @@
|
|||||||
#include <QtCore/qdebug.h>
|
#include <QtCore/qdebug.h>
|
||||||
#include <QtCore/qfile.h>
|
#include <QtCore/qfile.h>
|
||||||
#include <QtCore/qtextstream.h>
|
#include <QtCore/qtextstream.h>
|
||||||
|
#include <QGuiApplication>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <QDateTime>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include "Version.h"
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <process.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef QT_ENDL
|
#ifndef QT_ENDL
|
||||||
# if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
# if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||||
@ -23,10 +31,45 @@ static std::unique_ptr<QTextStream> g_logStream = nullptr;
|
|||||||
|
|
||||||
static inline void myMessageHandler(const QtMsgType type, const QMessageLogContext &context, const QString &message)
|
static inline void myMessageHandler(const QtMsgType type, const QMessageLogContext &context, const QString &message)
|
||||||
{
|
{
|
||||||
if (message.isEmpty()) {
|
if (context.file && !message.isEmpty()) {
|
||||||
return;
|
std::string strFileTmp = context.file;
|
||||||
|
const char* ptr = strrchr(strFileTmp.c_str(), '/');
|
||||||
|
if (nullptr != ptr) {
|
||||||
|
char fn[512] = {0};
|
||||||
|
sprintf(fn, "%s", ptr + 1);
|
||||||
|
strFileTmp = fn;
|
||||||
}
|
}
|
||||||
const QString finalMessage = qFormatLogMessage(type, context, message).trimmed();
|
const char* ptrTmp = strrchr(strFileTmp.c_str(), '\\');
|
||||||
|
if (nullptr != ptrTmp) {
|
||||||
|
char fn[512] = {0};
|
||||||
|
sprintf(fn, "%s", ptrTmp + 1);
|
||||||
|
strFileTmp = fn;
|
||||||
|
}
|
||||||
|
QString levelName;
|
||||||
|
switch (type) {
|
||||||
|
case QtDebugMsg:
|
||||||
|
levelName = QStringLiteral("Debug");
|
||||||
|
break;
|
||||||
|
case QtInfoMsg:
|
||||||
|
levelName = QStringLiteral("Info");
|
||||||
|
break;
|
||||||
|
case QtWarningMsg:
|
||||||
|
levelName = QStringLiteral("Warning");
|
||||||
|
break;
|
||||||
|
case QtCriticalMsg:
|
||||||
|
levelName = QStringLiteral("Critical");
|
||||||
|
break;
|
||||||
|
case QtFatalMsg:
|
||||||
|
levelName = QStringLiteral("Fatal");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const QString finalMessage = QString::fromStdString("[%1] <%2> [ %3:%4 ] %5").arg(
|
||||||
|
QDateTime::currentDateTime().toString("yyyy/MM/dd hh:mm:ss.zzz"),
|
||||||
|
levelName,
|
||||||
|
QString::fromStdString(strFileTmp),
|
||||||
|
QString::number(context.line),
|
||||||
|
message
|
||||||
|
);
|
||||||
if ((type == QtInfoMsg) || (type == QtDebugMsg)) {
|
if ((type == QtInfoMsg) || (type == QtDebugMsg)) {
|
||||||
std::cout << qPrintable(finalMessage) << std::endl;
|
std::cout << qPrintable(finalMessage) << std::endl;
|
||||||
} else {
|
} else {
|
||||||
@ -49,6 +92,8 @@ static inline void myMessageHandler(const QtMsgType type, const QMessageLogConte
|
|||||||
g_logStream->setDevice(g_logFile.get());
|
g_logStream->setDevice(g_logFile.get());
|
||||||
}
|
}
|
||||||
(*g_logStream) << finalMessage << QT_ENDL;
|
(*g_logStream) << finalMessage << QT_ENDL;
|
||||||
|
g_logStream->flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::setup(const QString &app)
|
void Log::setup(const QString &app)
|
||||||
@ -63,17 +108,28 @@ void Log::setup(const QString &app)
|
|||||||
}
|
}
|
||||||
once = true;
|
once = true;
|
||||||
g_app = app;
|
g_app = app;
|
||||||
const QString logFileName = QString("debug-%1.log").arg(g_app);
|
const QString logFileName = QString("%1-%2.log").arg(g_app,QString::number(QDateTime::currentMSecsSinceEpoch()));
|
||||||
const QString logDirPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
|
const QString logDirPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)+"/log";
|
||||||
const QDir logDir(logDirPath);
|
const QDir logDir(logDirPath);
|
||||||
if(!logDir.exists()){
|
if(!logDir.exists()){
|
||||||
logDir.mkpath(logDirPath);
|
logDir.mkpath(logDirPath);
|
||||||
}
|
}
|
||||||
g_file_path = logDir.filePath(logFileName);
|
g_file_path = logDir.filePath(logFileName);
|
||||||
qSetMessagePattern(QString(
|
|
||||||
"[%{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);
|
qInstallMessageHandler(myMessageHandler);
|
||||||
qDebug()<<"Application log file path->"<<g_file_path;
|
qDebug()<<logDirPath;
|
||||||
|
qInfo()<<"===================================================";
|
||||||
|
qInfo()<<"[AppName] FluentUI Example";
|
||||||
|
qInfo()<<"[AppVersion] "<<APPLICATION_VERSION;
|
||||||
|
#ifdef WIN32
|
||||||
|
qInfo()<<"[ProcessId] "<<QString::number(_getpid());
|
||||||
|
#else
|
||||||
|
qInfo()<<"[ProcessId] "<<QString::number(getpid());
|
||||||
|
#endif
|
||||||
|
qInfo()<<"[GitHashCode] "<<COMMIT_HASH;
|
||||||
|
qInfo()<<"[DeviceInfo]";
|
||||||
|
qInfo()<<" [DeviceId] "<<QSysInfo::machineUniqueId();
|
||||||
|
qInfo()<<" [Manufacturer] "<<QSysInfo::prettyProductName();
|
||||||
|
qInfo()<<" [CPU_ABI] "<<QSysInfo::currentCpuArchitecture();
|
||||||
|
qInfo()<<"[LOG_PATH] "<<g_file_path;
|
||||||
|
qInfo()<<"===================================================";
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,5 @@ void SettingsHelper::init(char *argv[]){
|
|||||||
const QFileInfo fileInfo(applicationPath);
|
const QFileInfo fileInfo(applicationPath);
|
||||||
const QString iniFileName = fileInfo.completeBaseName() + ".ini";
|
const QString iniFileName = fileInfo.completeBaseName() + ".ini";
|
||||||
const QString iniFilePath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/" + iniFileName;
|
const QString iniFilePath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/" + iniFileName;
|
||||||
qDebug()<<"Application configuration file path->"<<iniFilePath;
|
|
||||||
m_settings.reset(new QSettings(iniFilePath, QSettings::IniFormat));
|
m_settings.reset(new QSettings(iniFilePath, QSettings::IniFormat));
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,13 @@ Q_IMPORT_QML_PLUGIN(FluentUIPlugin)
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
Log::setup("example");
|
qputenv("QT_QUICK_CONTROLS_STYLE","Basic");
|
||||||
|
QGuiApplication::setOrganizationName("ZhuZiChu");
|
||||||
|
QGuiApplication::setOrganizationDomain("https://zhuzichu520.github.io");
|
||||||
|
QGuiApplication::setApplicationName("FluentUI");
|
||||||
QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
|
QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
|
||||||
|
SettingsHelper::getInstance()->init(argv);
|
||||||
|
Log::setup("example");
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
@ -33,11 +38,6 @@ int main(int argc, char *argv[])
|
|||||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
qputenv("QT_QUICK_CONTROLS_STYLE","Basic");
|
|
||||||
QGuiApplication::setOrganizationName("ZhuZiChu");
|
|
||||||
QGuiApplication::setOrganizationDomain("https://zhuzichu520.github.io");
|
|
||||||
QGuiApplication::setApplicationName("FluentUI");
|
|
||||||
SettingsHelper::getInstance()->init(argv);
|
|
||||||
if(SettingsHelper::getInstance()->getRender()=="software"){
|
if(SettingsHelper::getInstance()->getRender()=="software"){
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||||
QQuickWindow::setGraphicsApi(QSGRendererInterface::Software);
|
QQuickWindow::setGraphicsApi(QSGRendererInterface::Software);
|
||||||
@ -55,7 +55,6 @@ int main(int argc, char *argv[])
|
|||||||
#ifdef FLUENTUI_BUILD_STATIC_LIB
|
#ifdef FLUENTUI_BUILD_STATIC_LIB
|
||||||
FluentUI::getInstance()->registerTypes(&engine);
|
FluentUI::getInstance()->registerTypes(&engine);
|
||||||
#endif
|
#endif
|
||||||
qDebug()<<engine.importPathList();
|
|
||||||
qmlRegisterType<CircularReveal>("example", 1, 0, "CircularReveal");
|
qmlRegisterType<CircularReveal>("example", 1, 0, "CircularReveal");
|
||||||
qmlRegisterType<FileWatcher>("example", 1, 0, "FileWatcher");
|
qmlRegisterType<FileWatcher>("example", 1, 0, "FileWatcher");
|
||||||
qmlRegisterType<FpsItem>("example", 1, 0, "FpsItem");
|
qmlRegisterType<FpsItem>("example", 1, 0, "FpsItem");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user