I have kept non-packaged libraries to a min in my application so far (I have one). The application is in C sorry I didn't mention that. Boost has some great capabilities though. I could possibly emulate some of those maybe?
Code:
int DEBUG_THIS_TRACE = 0;
int DEBUG_THIS_DEBUG = 0;
int DEBUG_THIS_INFO = 0;
int DEBUG_THIS_WARNING = 0;
int DEBUG_THIS_ERROR = 0;
int DEBUG_THIS_FATAL = 0;
int mylogger(int debug, char *message) {
if(debug) {
writetomylog(message);
}
}
int main(int, char*[]){
mylogger(DEBUG_THIS_INFO, "log this");
}
Another idea is to use a single variable with a bitmask? Im not even sure how to do this but if ALL is logged then any error level is logged or you should be able to enable them individually.
Code:
#define LOG_OFF 0 \\ Logging Level 0
#define LOG_FATAL 1 \\ Logging Level 1
#define LOG_ERROR 2 \\ Logging Level 2
#define LOG_WARN 4 \\ Logging Level 3
#define LOG_DEBUG 8 \\ Logging Level 4
#define LOG_INFO 16 \\ Logging Level 5
#define LOG_TRACE 32 \\ Logging Level 6
#define LOG_ALL 64 \\ Logging Level 7
int LOG_LEVEL = LOG_WARN; \\ Default log everything up to WARN messages (regardless of individual component setting).
int DEBUG_THIS = LOG_INFO; \\ Specific logging option.
int mylogger(int level, int debug, char *message) {
if((level >= LOG_LEVEL) || ((level & debug) >= level)) {
writetomylog(message);
}
}
int main(int, char*[]){
mylogger(LOG_INFO,DEBUG_THIS, "[info] about something");
}