use "s_" for static variables

This commit is contained in:
john30
2016-12-04 17:58:58 +01:00
parent 5c0e92c1ee
commit b02007f826
+26 -21
View File
@@ -48,13 +48,13 @@ static const char* levelNames[] = {
}; };
/** the bit combination of currently active log facilities (1 << @a LogFacility). */ /** the bit combination of currently active log facilities (1 << @a LogFacility). */
static int logFacilites = LF_ALL; static int s_logFacilites = LF_ALL;
/** the current log level. */ /** the current log level. */
static LogLevel logLevel = ll_notice; static LogLevel s_logLevel = ll_notice;
/** the current log FILE. */ /** the current log FILE. */
static FILE* logFile = stdout; static FILE* s_logFile = stdout;
bool setLogFacilities(const char* facilities) bool setLogFacilities(const char* facilities)
{ {
@@ -67,26 +67,29 @@ bool setLogFacilities(const char* facilities)
free(input); free(input);
return false; return false;
} }
if (val == lf_COUNT) if (val == lf_COUNT) {
newFacilites = LF_ALL; newFacilites = LF_ALL;
else } else {
newFacilites |= 1<<val; newFacilites |= 1<<val;
} }
logFacilites = newFacilites; }
s_logFacilites = newFacilites;
free(input); free(input);
return true; return true;
} }
bool getLogFacilities(char* buffer) bool getLogFacilities(char* buffer)
{ {
if (logFacilites==LF_ALL) if (s_logFacilites==LF_ALL) {
return strcpy(buffer, facilityNames[lf_COUNT]) != NULL; return strcpy(buffer, facilityNames[lf_COUNT]) != NULL;
}
*buffer = 0; // for strcat to work *buffer = 0; // for strcat to work
bool found = false; bool found = false;
for (int val=0; val<lf_COUNT; val++) { for (int val=0; val<lf_COUNT; val++) {
if (logFacilites&(1<<val)) { if (s_logFacilites&(1<<val)) {
if (found) if (found) {
strcat(buffer, ","); strcat(buffer, ",");
}
found = true; found = true;
strcat(buffer, facilityNames[val]); strcat(buffer, facilityNames[val]);
} }
@@ -107,14 +110,14 @@ bool setLogLevel(const char* level)
} }
newLevel = val; newLevel = val;
} }
logLevel = (LogLevel)newLevel; s_logLevel = (LogLevel)newLevel;
free(input); free(input);
return true; return true;
} }
const char* getLogLevel() const char* getLogLevel()
{ {
return levelNames[logLevel]; return levelNames[s_logLevel];
} }
bool setLogFile(const char* filename) bool setLogFile(const char* filename)
@@ -124,23 +127,24 @@ bool setLogFile(const char* filename)
return false; return false;
closeLogFile(); closeLogFile();
logFile = newFile; s_logFile = newFile;
return true; return true;
} }
void closeLogFile() void closeLogFile()
{ {
if (logFile != NULL) { if (s_logFile != NULL) {
if (logFile != stdout) if (s_logFile != stdout) {
fclose(logFile); fclose(s_logFile);
logFile = NULL; }
s_logFile = NULL;
} }
} }
bool needsLog(const LogFacility facility, const LogLevel level) bool needsLog(const LogFacility facility, const LogLevel level)
{ {
return ((logFacilites & (1<<facility)) != 0) return ((s_logFacilites & (1<<facility)) != 0)
&& (logLevel >= level); && (s_logLevel >= level);
} }
void logWrite(const LogFacility facility, const LogLevel level, const char* message, ...) void logWrite(const LogFacility facility, const LogLevel level, const char* message, ...)
@@ -156,14 +160,15 @@ void logWrite(const LogFacility facility, const LogLevel level, const char* mess
va_start(ap, message); va_start(ap, message);
if (vasprintf(&buf, message, ap) >= 0 && buf) { if (vasprintf(&buf, message, ap) >= 0 && buf) {
fprintf(logFile, "%04d-%02d-%02d %02d:%02d:%02d.%03ld [%s %s] %s\n", fprintf(s_logFile, "%04d-%02d-%02d %02d:%02d:%02d.%03ld [%s %s] %s\n",
tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec, ts.tv_nsec/1000000, tm->tm_hour, tm->tm_min, tm->tm_sec, ts.tv_nsec/1000000,
facilityNames[facility], levelNames[level], buf); facilityNames[facility], levelNames[level], buf);
fflush(logFile); fflush(s_logFile);
} }
va_end(ap); va_end(ap);
if (buf) if (buf) {
free(buf); free(buf);
} }
}