@@ -36,6 +36,7 @@ class SimpleLog::Impl
3636 int formatOptions;
3737 int fdStdout;
3838 int fdStderr;
39+ bool disableOutput = 0 ; // when set, messages completely dropped (logfile=/dev/null)
3940
4041 // log rotation settings
4142 unsigned long rotateMaxBytes = 0 ;
@@ -65,6 +66,11 @@ SimpleLog::Impl::~Impl()
6566
6667int SimpleLog::Impl::logV (SimpleLog::Impl::Severity s, const char * message, va_list ap)
6768{
69+ // immediate return if output disabled
70+ if (disableOutput) {
71+ return 0 ;
72+ }
73+
6874 char buffer[1024 ] = " " ;
6975 size_t len = sizeof (buffer) - 2 ;
7076 size_t ix = 0 ;
@@ -167,21 +173,25 @@ SimpleLog::~SimpleLog()
167173int SimpleLog::setLogFile (const char * logFilePath, unsigned long rotateMaxBytes, unsigned int rotateMaxFiles, unsigned int rotateNow)
168174{
169175 pImpl->closeLogFile ();
176+ pImpl->logFilePath = " " ;
177+ pImpl->rotateMaxFiles = 0 ;
178+ pImpl->rotateMaxBytes = 0 ;
179+ pImpl->logFileSize = 0 ;
180+ pImpl->disableOutput = 0 ;
170181 if (logFilePath != NULL ) {
182+ pImpl->logFilePath = logFilePath;
183+ if (!strcmp (logFilePath, " /dev/null" )) {
184+ pImpl->disableOutput = 1 ;
185+ return 0 ;
186+ }
171187 pImpl->rotateMaxBytes = rotateMaxBytes;
172188 pImpl->rotateMaxFiles = rotateMaxFiles;
173- pImpl->logFilePath = logFilePath;
174189 if (rotateNow) {
175190 pImpl->rotate ();
176191 }
177192 if (pImpl->openLogFile ()) {
178193 return -1 ;
179194 }
180- } else {
181- pImpl->logFilePath = " " ;
182- pImpl->rotateMaxFiles = 0 ;
183- pImpl->rotateMaxBytes = 0 ;
184- pImpl->logFileSize = 0 ;
185195 }
186196 return 0 ;
187197}
0 commit comments