fix: 修改日志生成位置
This commit is contained in:
@@ -145,10 +145,10 @@ install(DIRECTORY ${CMAKE_SOURCE_DIR}/bin/platforms/
|
||||
set(CPACK_PACKAGE_NAME "Viewer")
|
||||
set(CPACK_PACKAGE_VENDOR "Lorenzo Zhao")
|
||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Depth Camera Control System")
|
||||
set(CPACK_PACKAGE_VERSION "0.3.2")
|
||||
set(CPACK_PACKAGE_VERSION "0.3.3")
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR "0")
|
||||
set(CPACK_PACKAGE_VERSION_MINOR "3")
|
||||
set(CPACK_PACKAGE_VERSION_PATCH "2")
|
||||
set(CPACK_PACKAGE_VERSION_PATCH "3")
|
||||
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Viewer")
|
||||
|
||||
# WiX生成器配置(用于MSI)
|
||||
|
||||
@@ -283,4 +283,4 @@ d330viewer/
|
||||
- 使用Qt6信号槽机制进行模块间通信
|
||||
- OpenCL kernel代码内联在C++源文件中
|
||||
- 配置使用QSettings持久化
|
||||
- 日志输出到 `bin/d330viewer.log`
|
||||
- 日志输出到 `%LOCALAPPDATA%/Viewer/Viewer/viewer.log`(例如 `C:/Users/<用户名>/AppData/Local/Viewer/Viewer/viewer.log`)
|
||||
|
||||
24
src/main.cpp
24
src/main.cpp
@@ -1,12 +1,15 @@
|
||||
#include <QApplication>
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "gui/MainWindow.h"
|
||||
#include "core/Logger.h"
|
||||
|
||||
// Custom message handler to redirect qDebug output to Logger
|
||||
// Redirect Qt log output to file logger.
|
||||
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
Logger *logger = Logger::instance();
|
||||
|
||||
switch (type) {
|
||||
@@ -30,27 +33,30 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
// 设置应用程序信息
|
||||
app.setOrganizationName("Viewer");
|
||||
app.setApplicationName("Viewer");
|
||||
app.setApplicationVersion("0.3.2");
|
||||
app.setApplicationVersion("0.3.3");
|
||||
|
||||
// 初始化Logger(在可执行文件同目录下)
|
||||
QString logPath = QCoreApplication::applicationDirPath() + "/viewer.log";
|
||||
// Prefer LocalAppData so MSI installs under Program Files can always write logs.
|
||||
QString logDir = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
|
||||
if (logDir.isEmpty()) {
|
||||
logDir = QCoreApplication::applicationDirPath();
|
||||
}
|
||||
QDir().mkpath(logDir);
|
||||
|
||||
const QString logPath = QDir(logDir).filePath("viewer.log");
|
||||
Logger::instance()->setLogFile(logPath);
|
||||
Logger::instance()->setMaxLines(10000); // 保留最新10000行
|
||||
Logger::instance()->setMaxLines(10000);
|
||||
|
||||
// 安装消息处理器
|
||||
qInstallMessageHandler(messageHandler);
|
||||
|
||||
qDebug() << "Viewer started";
|
||||
qDebug() << "Log file:" << logPath;
|
||||
|
||||
// 创建并显示主窗口
|
||||
MainWindow mainWindow;
|
||||
mainWindow.show();
|
||||
|
||||
int result = app.exec();
|
||||
const int result = app.exec();
|
||||
|
||||
qDebug() << "Viewer exiting";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user