debug.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #include <stdio.h>
  3. #include <stdbool.h>
  4. #include <string.h>
  5. #ifdef _WIN32
  6. #include <windows.h>
  7. #else // Linux
  8. #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
  9. #define __FUNCTION__ __func__
  10. #endif
  11. #ifdef _WIN32
  12. #ifdef _UNICODE
  13. #define DebugPrint DebugPrintW
  14. #else
  15. #define DebugPrint DebugPrintA
  16. #endif
  17. #else // Linux
  18. // Linux ÏÂĬÈÏʹÓà UTF-8 Õ­×Ö·û
  19. #define DebugPrint DebugPrintA
  20. #endif
  21. void SetPrintLog(bool Enable);
  22. //extern BOOL dum_log_file;
  23. #define MAX_PATH 260
  24. #define ONE_LOG_MAX_SIZE (524288)
  25. #ifdef _DEBUG
  26. #define DebugPrintA(format,...) __DebugPrintA(__FILE__,__LINE__,__FUNCTION__,format,__VA_ARGS__)
  27. #define DebugPrintW(format,...) __DebugPrintW(__FILE__,__LINE__,__FUNCTION__,format,__VA_ARGS__)
  28. #else
  29. #define DebugPrintA(format,...) __ReleasePrintA(__FILE__,__LINE__,__FUNCTION__,format,__VA_ARGS__)
  30. #define DebugPrintW(format,...) __ReleasePrintW(__FILE__,__LINE__,__FUNCTION__,format,__VA_ARGS__)
  31. #endif
  32. //define project name before include debug.h
  33. #if defined _LISMSOCKET
  34. #define PROJECT_NAME "LISM_SOCKET"
  35. #elif defined _LISMSERVER
  36. #define PROJECT_NAME "LISM_SERVER"
  37. #elif defined _LISMCLIENT
  38. #define PROJECT_NAME "LISM_CLIENT"
  39. #elif defined _LISMCONSOLE
  40. #define PROJECT_NAME "LISM_CONSOLE"
  41. #elif defined _LISMDRIVERAPI
  42. #define PROJECT_NAME "LISM_DRIVERAPI"
  43. #elif defined _LISMDADTABASE
  44. #define PROJECT_NAME "LISM_DADTABASE"
  45. #elif 1
  46. #define PROJECT_NAME "UNKNOWN"
  47. #endif
  48. void __DebugPrintA(
  49. char* file,
  50. int line,
  51. char* function,
  52. char* format,
  53. ...
  54. );
  55. void __DebugPrintW(
  56. char* file,
  57. int line,
  58. char* function,
  59. wchar_t* format,
  60. ...
  61. );
  62. void __ReleasePrintA(
  63. char* file,
  64. int line,
  65. char* function,
  66. char* format,
  67. ...
  68. );
  69. void __ReleasePrintW(
  70. char* file,
  71. int line,
  72. char* function,
  73. wchar_t* format,
  74. ...
  75. );