mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
support log file in release mode
This commit is contained in:
parent
d1395b9ac2
commit
db9903b906
62
src/main.cpp
62
src/main.cpp
@ -5,37 +5,87 @@
|
|||||||
#include <QLibraryInfo>
|
#include <QLibraryInfo>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
#include <QFileInfo>
|
||||||
#include "utils/vutils.h"
|
#include "utils/vutils.h"
|
||||||
#include "vsingleinstanceguard.h"
|
#include "vsingleinstanceguard.h"
|
||||||
#include "vconfigmanager.h"
|
#include "vconfigmanager.h"
|
||||||
|
|
||||||
VConfigManager vconfig;
|
VConfigManager vconfig;
|
||||||
|
static QFile g_logFile;
|
||||||
|
|
||||||
void VLogger(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
void VLogger(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||||
{
|
{
|
||||||
QByteArray localMsg = msg.toUtf8();
|
QByteArray localMsg = msg.toUtf8();
|
||||||
|
QString header;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case QtDebugMsg:
|
case QtDebugMsg:
|
||||||
fprintf(stderr, "Debug:%s (%s:%u)\n", localMsg.constData(), context.file, context.line);
|
header = "Debug:";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QtInfoMsg:
|
case QtInfoMsg:
|
||||||
fprintf(stderr, "Info:%s (%s:%u)\n", localMsg.constData(), context.file, context.line);
|
header = "Info:";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QtWarningMsg:
|
case QtWarningMsg:
|
||||||
fprintf(stderr, "Warning:%s (%s:%u)\n", localMsg.constData(), context.file, context.line);
|
header = "Warning:";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QtCriticalMsg:
|
case QtCriticalMsg:
|
||||||
fprintf(stderr, "Critical:%s (%s:%u)\n", localMsg.constData(), context.file, context.line);
|
header = "Critical:";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QtFatalMsg:
|
case QtFatalMsg:
|
||||||
fprintf(stderr, "Fatal:%s (%s:%u)\n", localMsg.constData(), context.file, context.line);
|
header = "Fatal:";
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(QT_NO_DEBUG)
|
||||||
|
QTextStream stream(&g_logFile);
|
||||||
|
stream << header << localMsg << "\n";
|
||||||
|
g_logFile.flush();
|
||||||
|
|
||||||
|
if (type == QtFatalMsg) {
|
||||||
|
g_logFile.close();
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
std::string fileStr = QFileInfo(context.file).fileName().toStdString();
|
||||||
|
const char *file = fileStr.c_str();
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case QtDebugMsg:
|
||||||
|
fprintf(stderr, "%s(%s:%u) %s\n",
|
||||||
|
header.toStdString().c_str(), file, context.line, localMsg.constData());
|
||||||
|
break;
|
||||||
|
case QtInfoMsg:
|
||||||
|
fprintf(stderr, "%s(%s:%u) %s\n",
|
||||||
|
header.toStdString().c_str(), file, context.line, localMsg.constData());
|
||||||
|
break;
|
||||||
|
case QtWarningMsg:
|
||||||
|
fprintf(stderr, "%s(%s:%u) %s\n",
|
||||||
|
header.toStdString().c_str(), file, context.line, localMsg.constData());
|
||||||
|
break;
|
||||||
|
case QtCriticalMsg:
|
||||||
|
fprintf(stderr, "%s(%s:%u) %s\n",
|
||||||
|
header.toStdString().c_str(), file, context.line, localMsg.constData());
|
||||||
|
break;
|
||||||
|
case QtFatalMsg:
|
||||||
|
fprintf(stderr, "%s(%s:%u) %s\n",
|
||||||
|
header.toStdString().c_str(), file, context.line, localMsg.constData());
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
//qInstallMessageHandler(VLogger);
|
#if defined(QT_NO_DEBUG)
|
||||||
|
g_logFile.setFileName(VConfigManager::getLogFilePath());
|
||||||
|
g_logFile.open(QIODevice::WriteOnly);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
qInstallMessageHandler(VLogger);
|
||||||
|
|
||||||
VSingleInstanceGuard guard;
|
VSingleInstanceGuard guard;
|
||||||
if (!guard.tryRun()) {
|
if (!guard.tryRun()) {
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
#include <QStandardPaths>
|
||||||
#include "utils/vutils.h"
|
#include "utils/vutils.h"
|
||||||
#include "vstyleparser.h"
|
#include "vstyleparser.h"
|
||||||
|
|
||||||
@ -276,6 +277,21 @@ bool VConfigManager::deleteDirectoryConfig(const QString &path)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString VConfigManager::getLogFilePath()
|
||||||
|
{
|
||||||
|
static QString logPath;
|
||||||
|
|
||||||
|
if (logPath.isEmpty()) {
|
||||||
|
QString location = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||||
|
V_ASSERT(!location.isEmpty());
|
||||||
|
QDir dir(location);
|
||||||
|
dir.mkdir("VNote");
|
||||||
|
logPath = dir.filePath("VNote/vnote.log");
|
||||||
|
}
|
||||||
|
|
||||||
|
return logPath;
|
||||||
|
}
|
||||||
|
|
||||||
void VConfigManager::updateMarkdownEditStyle()
|
void VConfigManager::updateMarkdownEditStyle()
|
||||||
{
|
{
|
||||||
static const QString defaultCurrentLineBackground = "#C5CAE9";
|
static const QString defaultCurrentLineBackground = "#C5CAE9";
|
||||||
|
@ -39,6 +39,8 @@ public:
|
|||||||
static bool directoryConfigExist(const QString &path);
|
static bool directoryConfigExist(const QString &path);
|
||||||
static bool deleteDirectoryConfig(const QString &path);
|
static bool deleteDirectoryConfig(const QString &path);
|
||||||
|
|
||||||
|
static QString getLogFilePath();
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
static const QString orgName;
|
static const QString orgName;
|
||||||
static const QString appName;
|
static const QString appName;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user