Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the log file path error when using system environment variables in log.conf #75

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/log4qt/binaryfileappender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ BinaryFileAppender::~BinaryFileAppender()
closeInternal();
}

void BinaryFileAppender::setFile(const QString &fileName)
{
QMutexLocker locker(&mObjectGuard);
mFileName = fileName;

#ifdef Q_OS_WIN
// Let windows resolve any environment variables included in the file path
wchar_t buffer[MAX_PATH];
if (ExpandEnvironmentStringsW(mFileName.toStdWString().c_str(), buffer, MAX_PATH))
mFileName = QString::fromWCharArray(buffer);
#endif

}

void BinaryFileAppender::activateOptions()
{
QMutexLocker locker(&mObjectGuard);
Expand Down Expand Up @@ -187,13 +201,6 @@ void BinaryFileAppender::openFile()
parent_dir.mkdir(name);
}

#ifdef Q_OS_WIN
// Let windows resolve any environment variables included in the file path
wchar_t buffer[MAX_PATH];
if (ExpandEnvironmentStringsW(mFileName.toStdWString().c_str(), buffer, MAX_PATH))
mFileName = QString::fromWCharArray(buffer);
#endif

mFile = new QFile(mFileName);
QFile::OpenMode mode = QIODevice::WriteOnly | QIODevice::Text;
if (mAppendFile)
Expand Down
5 changes: 0 additions & 5 deletions src/log4qt/binaryfileappender.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ inline void BinaryFileAppender::setBufferedIo(bool buffered)
mBufferedIo = buffered;
}

inline void BinaryFileAppender::setFile(const QString &fileName)
{
QMutexLocker locker(&mObjectGuard);
mFileName = fileName;
}

inline QDataStream::ByteOrder BinaryFileAppender::byteOrder() const
{
Expand Down
20 changes: 13 additions & 7 deletions src/log4qt/fileappender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ FileAppender::~FileAppender()
closeInternal();
}

void FileAppender::setFile(const QString &fileName)
{
QMutexLocker locker(&mObjectGuard);
mFileName = fileName;

#ifdef Q_OS_WIN
// Let windows resolve any environment variables included in the file path
wchar_t buffer[MAX_PATH];
if (ExpandEnvironmentStringsW(mFileName.toStdWString().c_str(), buffer, MAX_PATH))
mFileName = QString::fromWCharArray(buffer);
#endif
}

void FileAppender::activateOptions()
{
QMutexLocker locker(&mObjectGuard);
Expand Down Expand Up @@ -177,13 +190,6 @@ void FileAppender::openFile()
parent_dir.mkdir(name);
}

#ifdef Q_OS_WIN
// Let windows resolve any environment variables included in the file path
wchar_t buffer[MAX_PATH];
if (ExpandEnvironmentStringsW(mFileName.toStdWString().c_str(), buffer, MAX_PATH))
mFileName = QString::fromWCharArray(buffer);
#endif

mFile = new QFile(mFileName);
QFile::OpenMode mode = QIODevice::WriteOnly | QIODevice::Text;
if (mAppendFile)
Expand Down
5 changes: 0 additions & 5 deletions src/log4qt/fileappender.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,6 @@ inline void FileAppender::setBufferedIo(bool buffered)
mBufferedIo = buffered;
}

inline void FileAppender::setFile(const QString &fileName)
{
QMutexLocker locker(&mObjectGuard);
mFileName = fileName;
}


} // namespace Log4Qt
Expand Down