small cleanup in logging

pull/3122/head
Isaac Connor 2020-12-31 09:14:03 -05:00
parent 6d036629d3
commit 48dcb23af0
1 changed files with 9 additions and 20 deletions

View File

@ -522,8 +522,10 @@ void Logger::logPrint(bool hex, const char * const filepath, const int line, con
puts(logString); puts(logString);
fflush(stdout); fflush(stdout);
} }
if ( level <= mFileLevel ) { if ( level <= mFileLevel ) {
if ( !mLogFileFP ) { if ( !mLogFileFP ) {
// We do this here so that we only create the file if we ever write to it.
log_mutex.unlock(); log_mutex.unlock();
openFile(); openFile();
log_mutex.lock(); log_mutex.lock();
@ -535,15 +537,9 @@ void Logger::logPrint(bool hex, const char * const filepath, const int line, con
} else { } else {
puts("Logging to file, but failed to open it\n"); puts("Logging to file, but failed to open it\n");
} }
#if 0 } // end if level <= mFileLevel
} else {
printf("Not writing to log file because level %d %s <= mFileLevel %d %s\nstring: %s\n",
level, smCodes[level].c_str(), mFileLevel, smCodes[mFileLevel].c_str(), logString);
#endif
}
*syslogEnd = '\0';
if ( level <= mDatabaseLevel ) {
if ( level <= mDatabaseLevel ) {
if ( !db_mutex.trylock() ) { if ( !db_mutex.trylock() ) {
char escapedString[(strlen(syslogStart)*2)+1]; char escapedString[(strlen(syslogStart)*2)+1];
mysql_real_escape_string(&dbconn, escapedString, syslogStart, strlen(syslogStart)); mysql_real_escape_string(&dbconn, escapedString, syslogStart, strlen(syslogStart));
@ -570,29 +566,22 @@ void Logger::logPrint(bool hex, const char * const filepath, const int line, con
databaseLevel(tempDatabaseLevel); databaseLevel(tempDatabaseLevel);
} }
db_mutex.unlock(); db_mutex.unlock();
///} else { } // end if level <= mDatabaseLevel
///Level tempDatabaseLevel = mDatabaseLevel;
///databaseLevel(NOLOG);
///Error("Can't insert log entry: sql(%s) error(db is locked)", logString);
///databaseLevel(tempDatabaseLevel);
///}
}
if ( level <= mSyslogLevel ) { if ( level <= mSyslogLevel ) {
int priority = smSyslogPriorities[level]; *syslogEnd = '\0';
//priority |= LOG_DAEMON; syslog(smSyslogPriorities[level], "%s [%s] [%s]", classString, mId.c_str(), syslogStart);
syslog(priority, "%s [%s] [%s]", classString, mId.c_str(), syslogStart);
} }
free(filecopy); free(filecopy);
log_mutex.unlock();
if ( level <= FATAL ) { if ( level <= FATAL ) {
log_mutex.unlock();
logTerm(); logTerm();
zmDbClose(); zmDbClose();
if ( level <= PANIC ) if ( level <= PANIC )
abort(); abort();
exit(-1); exit(-1);
} }
log_mutex.unlock();
} // end logPrint } // end logPrint
void logInit(const char *name, const Logger::Options &options) { void logInit(const char *name, const Logger::Options &options) {