diff --git a/src/SimpleLog.cxx b/src/SimpleLog.cxx index 95c8111..036d3fc 100644 --- a/src/SimpleLog.cxx +++ b/src/SimpleLog.cxx @@ -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) { @@ -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; } @@ -355,7 +352,7 @@ void SimpleLog::Impl::rotate() rotateIx.push_back(std::stoi(postfix)); } } - free(dp); + closedir(dp); } // sort indexes in order diff --git a/test/testSimpleLog.cxx b/test/testSimpleLog.cxx index b6a0044..32283d3 100644 --- a/test/testSimpleLog.cxx +++ b/test/testSimpleLog.cxx @@ -14,14 +14,17 @@ // helps to test e.g. command line parameters settings #include +#include 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; }