Skip to content
New issue

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

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

Already on GitHub? # to your account

fix logrotate file open #50

Merged
merged 2 commits into from
Sep 24, 2024
Merged
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
7 changes: 2 additions & 5 deletions src/SimpleLog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,6 @@ int SimpleLog::setLogFile(const char* logFilePath, unsigned long rotateMaxBytes,
pImpl->disableOutput = 1;
return 0;
}
if (rotateMaxFiles < 0) {
rotateMaxFiles = 1;
}
pImpl->rotateMaxBytes = rotateMaxBytes;
pImpl->rotateMaxFiles = rotateMaxFiles;
if (rotateNow) {
Expand Down Expand Up @@ -281,7 +278,7 @@ int SimpleLog::Impl::openLogFile()
if (rotateMaxFiles == 1) {
mode = "w";
}
fp = fopen(logFilePath.c_str(), "a");
fp = fopen(logFilePath.c_str(), mode);
if (fp == NULL) {
return -1;
}
Expand Down Expand Up @@ -355,7 +352,7 @@ void SimpleLog::Impl::rotate()
rotateIx.push_back(std::stoi(postfix));
}
}
free(dp);
closedir(dp);
}

// sort indexes in order
Expand Down
7 changes: 5 additions & 2 deletions test/testSimpleLog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
// helps to test e.g. command line parameters settings

#include <Common/SimpleLog.h>
#include <unistd.h>

int main()
{

SimpleLog theLog;
theLog.setLogFile("/tmp/test.log", 100, 4, 0);
theLog.info("test message");

for (int i=0; i<10; i++) {
theLog.info("test message %d",i);
}
//sleep(10);
return 0;
}

Loading