log.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef _LOG_MYLOG_H_
  2. #define _LOG_MYLOG_H_
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <getopt.h>
  7. #include <unistd.h>
  8. #include <errno.h>
  9. #include <time.h>
  10. #include <set>
  11. using namespace std;
  12. #define RED "\x1B[31m"
  13. #define GRN "\x1B[32m"
  14. #define YEL "\x1B[33m"
  15. #define BLU "\x1B[34m"
  16. #define MAG "\x1B[35m"
  17. #define CYN "\x1B[36m"
  18. #define WHT "\x1B[37m"
  19. #define RESET "\x1B[0m"
  20. const int log_never = 0;
  21. const int log_fatal = 1;
  22. const int log_error = 2;
  23. const int log_warn = 3;
  24. const int log_info = 4;
  25. const int log_debug = 5;
  26. const int log_trace = 6;
  27. const int log_end = 7;
  28. const char log_text[][20] = {"NEVER", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE", ""};
  29. const char log_color[][20] = {RED, RED, RED, YEL, GRN, MAG, ""};
  30. extern int log_level;
  31. extern int enable_log_position;
  32. extern int enable_log_color;
  33. #ifdef MY_DEBUG
  34. #define mylog(__first_argu__dummy_abcde__, ...) printf(__VA_ARGS__)
  35. #else
  36. #define mylog(...) log0(__FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
  37. #endif
  38. //#define mylog(__first_argu__dummy_abcde__,...) {;}
  39. void log0(const char* file, const char* function, int line, int level, const char* str, ...);
  40. void log_bare(int level, const char* str, ...);
  41. #endif