Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.5 KiB

  1. //=======================================================================
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: log.h
  6. //
  7. // Original Author: Yan Leshinsky
  8. //
  9. // Description:
  10. //
  11. // Logging support
  12. //
  13. //=======================================================================
  14. #pragma once
  15. #include <stdio.h>
  16. #if 1
  17. #ifndef LOGGING_LEVEL
  18. #define LOGGING_LEVEL 0
  19. #endif
  20. const DWORD MAX_FORMATTED_STRING = 1024;
  21. class CLogger
  22. {
  23. public:
  24. CLogger(const char* szBlockName = 0, int nLoggingLevel = 0, const char* szFileName = 0, int nLine = 0);
  25. ~CLogger();
  26. void __cdecl out(const char *szFormat, ...);
  27. void __cdecl error(const char *szFormat, ...);
  28. static void __cdecl out1(const char *szFormat, ...);
  29. private:
  30. void v_out( const char* szFormat, va_list va);
  31. bool m_fOut;
  32. char m_szBlockName[64];
  33. DWORD m_dwStartTick;
  34. static FILE* c_pfile;
  35. static int c_cnIndent;
  36. static int c_cnLevels;
  37. };
  38. #define THIS_FILE __FILE__
  39. #define LOG_block(name) CLogger logger(name, LOGGING_LEVEL, THIS_FILE, __LINE__)
  40. #define LOG_out logger.out
  41. #define LOG_out1 CLogger::out1
  42. #define LOG_error logger.error
  43. #ifdef _UNICODE
  44. #define return_if_false(f) if (f) {/*OK*/} else { LOG_error("%S LastError = %d", #f, GetLastError()); return false;}
  45. #define return_error_if_false(f) if (f) {/*OK*/} else { DWORD dwErr = GetLastError(); LOG_error("%S LastError = %d", #f, dwErr); return dwErr;}
  46. #define return_if_error(f) { DWORD dwErr = f; if (dwErr) { LOG_error("%S LastError = %d", #f, dwErr); return dwErr;} }
  47. #else
  48. #define return_if_false(f) if (f) {/*OK*/} else { LOG_error("%s LastError = %d", #f, GetLastError()); return false;}
  49. #define return_error_if_false(f) if (f) {/*OK*/} else { DWORD dwErr = GetLastError(); LOG_error("%s LastError = %d", #f, dwErr); return dwErr;}
  50. #define return_if_error(f) { DWORD dwErr = f; if (dwErr) { LOG_error("%s LastError = %d", #f, dwErr); return dwErr;} }
  51. #endif
  52. #else
  53. #define LOG_block(name)
  54. inline void __cdecl ___LOG(const char *szFormat, ...){}
  55. #define LOG_out true ? (void)0 : ___LOG
  56. #define LOG_out1 true ? (void)0 : ___LOG
  57. #define LOG_error true ? (void)0 : ___LOG
  58. #define return_if_false(f) if (f) {/*OK*/} else { return false;}
  59. #define return_error_if_false(f) if (f) {/*OK*/} else { return GetLastError(); }
  60. #define return_if_error(f) { DWORD dwErr = f; if (dwErr) { return dwErr;} }
  61. #endif
  62. #define tab_out(){if(c_pfile){ for(int i = 0; i < c_cnIndent; i ++) {_fputtc(_T('\t'),c_pfile);}}}