Created
March 25, 2016 02:45
-
-
Save waveacme/01cb09c4f6edd1f1c11f to your computer and use it in GitHub Desktop.
a macro logger for c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "logger.h" | |
int DebugLevel = DEBUG_WARN; | |
int main(void) | |
{ | |
DBGPRINT(DEBUG_WARN, ("hello,debug=%s\n", "aaa")); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef LOGGER_H | |
#define LOGGER_H | |
#include <stdio.h> | |
//want to enable debug | |
#ifndef DBG | |
#define DBG | |
#endif | |
// Debug information verbosity: lower values indicate higher urgency | |
#define DEBUG_OFF 0 | |
#define DEBUG_ERROR 1 | |
#define DEBUG_WARN 2 | |
#define DEBUG_TRACE 3 | |
#define DEBUG_INFO 4 | |
#define DEBUG_VERB 5 | |
#ifdef DBG | |
extern int DebugLevel; | |
#define DBGPRINT_RAW(Level, Fmt) \ | |
do { \ | |
if (Level <= DebugLevel) \ | |
{ \ | |
printf Fmt; \ | |
} \ | |
} while(0) | |
#define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt) | |
#define DBGPRINT_ERR(Fmt) \ | |
{ \ | |
printf("ERROR!!! "); \ | |
printf Fmt; \ | |
} | |
#else | |
#define DBGPRINT(Level, Fmt) | |
#define DBGPRINT_RAW(Level, Fmt) | |
#define DBGPRINT_ERR(Fmt) | |
#endif | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment