diff --git a/src/lib/utils/log.cpp b/src/lib/utils/log.cpp index 59d7cfa8..41fa2827 100644 --- a/src/lib/utils/log.cpp +++ b/src/lib/utils/log.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "clock.h" using namespace std; @@ -57,38 +58,65 @@ static FILE* logFile = stdout; bool setLogFacilities(const char* facilities) { - char *opt = (char*)facilities, *value = NULL; + char *input = strdup(facilities); + char *opt = (char*)input, *value = NULL; int newFacilites = 0; while (*opt) { int val = getsubopt(&opt, (char *const *)facilityNames, &value); - if (val < 0 || val > lf_COUNT || value) + if (val < 0 || val > lf_COUNT || value) { + free(input); return false; - if (val == lf_COUNT) { - newFacilites = LF_ALL; - break; } - newFacilites |= 1<= ll_COUNT || value || *opt) + if (val < 0 || val >= ll_COUNT || value || *opt) { + free(input); return false; + } newLevel = val; } - logLevel = (LogLevel)newLevel; + free(input); return true; } +const char* getLogLevel() +{ + return levelNames[logLevel]; +} + bool setLogFile(const char* filename) { FILE* newFile = fopen(filename, "a"); diff --git a/src/lib/utils/log.h b/src/lib/utils/log.h index 8c740e7b..091ff834 100644 --- a/src/lib/utils/log.h +++ b/src/lib/utils/log.h @@ -50,6 +50,13 @@ enum LogLevel { */ bool setLogFacilities(const char* facilities); +/** + * Get the log facilities. + * @param buffer the buffer into which the facilities are written to (separated by comma, buffer needs to be at last 32 characters long). + * @return true on success, false on error. + */ +bool getLogFacilities(char* buffer); + /** * Parse the log level from the string. * @param level the level as string. @@ -57,6 +64,12 @@ bool setLogFacilities(const char* facilities); */ bool setLogLevel(const char* level); +/** + * Get the log level. + * @return the level as string. + */ +const char* getLogLevel(); + /** * Set the log file to use. * @param filename the name of the log file to use.