From d0e4fc1718854d7185f91bff1c854794aed1aef7 Mon Sep 17 00:00:00 2001 From: john30 Date: Sat, 7 Jan 2017 17:06:07 +0100 Subject: [PATCH] added new facility "other" --- src/lib/utils/log.cpp | 29 ++++++++++++++++++++--------- src/lib/utils/log.h | 25 +++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/lib/utils/log.cpp b/src/lib/utils/log.cpp index 5f51796a..d5ab11f9 100644 --- a/src/lib/utils/log.cpp +++ b/src/lib/utils/log.cpp @@ -33,6 +33,7 @@ static const char *facilityNames[] = { "network", "bus", "update", + "other", "all", NULL }; @@ -73,6 +74,7 @@ bool setLogFacilities(const char* facilities) newFacilites |= 1<= level); } -void logWrite(const LogFacility facility, const LogLevel level, const char* message, ...) +void logWrite(const char* facility, const char* level, const char* message, va_list ap) { struct timespec ts; struct tm* tm; - clockGettime(&ts); tm = localtime(&ts.tv_sec); - char* buf; - va_list ap; - va_start(ap, message); - if (vasprintf(&buf, message, ap) >= 0 && buf) { 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_hour, tm->tm_min, tm->tm_sec, ts.tv_nsec/1000000, - facilityNames[facility], levelNames[level], buf); + facility, level, buf); fflush(s_logFile); } - - va_end(ap); if (buf) { free(buf); } } + +void logWrite(const LogFacility facility, const LogLevel level, const char* message, ...) +{ + va_list ap; + va_start(ap, message); + logWrite(facilityNames[facility], levelNames[level], message, ap); + va_end(ap); +} + +void logWrite(const char* facility, const LogLevel level, const char* message, ...) +{ + va_list ap; + va_start(ap, message); + logWrite(facility, levelNames[level], message, ap); + va_end(ap); +} diff --git a/src/lib/utils/log.h b/src/lib/utils/log.h index 091ff834..8cf9159f 100644 --- a/src/lib/utils/log.h +++ b/src/lib/utils/log.h @@ -27,11 +27,12 @@ enum LogFacility { lf_network, //!< network related lf_bus, //!< eBUS related lf_update, //!< updates found while listening to the bus - lf_COUNT=4 //!< number of available log facilities + lf_other, //!< all other log facilities + lf_COUNT=5 //!< number of available log facilities }; /** macro for enabling all log facilities. */ -#define LF_ALL ((1<