Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Create directory containing log file before opening the file
Browse files Browse the repository at this point in the history
  • Loading branch information
SamVanheer committed Jan 26, 2023
1 parent 9cb4e81 commit ad0f2f8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/hlam/application/ToolApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,23 @@

const QString LogBaseFileName{QStringLiteral("HLAM-Log.txt")};

QString LogFileName = LogBaseFileName;
QString LogDirectory;
QString LogFileName;

static void SetLogFileName(const QString& logFileName)
{
const QFileInfo info{logFileName};

LogDirectory = info.absolutePath();
LogFileName = info.absoluteFilePath();
}

const QtMessageHandler DefaultMessageHandler = qInstallMessageHandler(nullptr);

void AssetManagerMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
QDir{LogDirectory}.mkpath(".");

QFile logFile{LogFileName};

if (!logFile.open(QFile::WriteOnly | QFile::Append))
Expand Down Expand Up @@ -117,8 +128,7 @@ int ToolApplication::Run(int argc, char* argv[])

connect(&app, &QApplication::aboutToQuit, this, &ToolApplication::OnExit);

LogFileName = QFileInfo{settings->fileName()}.absolutePath() + QDir::separator()
+ LogBaseFileName;
SetLogFileName(QFileInfo{settings->fileName()}.absolutePath() + QDir::separator() + LogBaseFileName);

QFile::remove(LogFileName);

Expand Down

0 comments on commit ad0f2f8

Please sign in to comment.