Skip to content

Commit 5d87a7b

Browse files
akshay-joshidpage
authored andcommitted
Avoid spamming stderr unnecessarily if we can't open the log file
1 parent 40cfda9 commit 5d87a7b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

unix.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <fstream>
2020

2121
static boost::mutex s_loggerLock;
22+
bool printFileErrorMsg = true;
2223

2324
using namespace std;
2425

@@ -51,8 +52,14 @@ void LogMessage(const std::string &msg, const int &level)
5152
out.open((const char *)log_file.c_str(), ios::out | ios::app);
5253
if (!out.is_open())
5354
{
54-
fprintf(stderr, "Can not open the logfile!");
55+
if (printFileErrorMsg)
56+
{
57+
fprintf(stderr, "Can not open the logfile '%s'", log_file.c_str());
58+
printFileErrorMsg = false;
59+
}
5560
return;
61+
} else {
62+
printFileErrorMsg = true;
5663
}
5764
}
5865
else

0 commit comments

Comments
 (0)