Leaked source code of windows server 2003
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.

309 lines
8.9 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Abstract:
  4. Standard log macros. Support standard
  5. setupact.log, setuperr.log and debug.log logs.
  6. Author:
  7. Souren Aghajanyan (sourenag) 24-Sep-2001
  8. Revision History:
  9. <alias> <date> <comments>
  10. --*/
  11. #pragma once
  12. #include "log.h"
  13. #undef INITIALIZE_LOG_CODE
  14. #ifndef DEBUG
  15. #define INITIALIZE_LOG_CODE if(!LogStandardInit(NULL, NULL, TRUE, FALSE, FALSE, FALSE, FALSE)){__leave;}
  16. #else
  17. #define INITIALIZE_LOG_CODE \
  18. {\
  19. WCHAR winDirectory[MAX_PATH];\
  20. GetWindowsDirectoryW(winDirectory, sizeof(winDirectory) / sizeof(winDirectory[0]));\
  21. lstrcatW (winDirectory, L"\\spsetup.log");\
  22. if(!LogStandardInit(winDirectory, NULL, TRUE, FALSE, FALSE, FALSE, FALSE)){__leave;}\
  23. }
  24. #endif
  25. #undef TERMINATE_LOG_CODE
  26. #define TERMINATE_LOG_CODE LogDestroyStandard();
  27. #if defined(__cplusplus)
  28. extern "C" {
  29. #endif
  30. #if _MSC_VER < 1300
  31. #define __FUNCTION__ "AvailableOnlyInVersion13"
  32. #endif
  33. #define STD_CALL_TYPE __stdcall
  34. #if defined(DEBUG)
  35. #ifdef _X86_
  36. #define BreakPoint() __asm {int 3};
  37. #else
  38. #define BreakPoint() DebugBreak()
  39. #endif
  40. #else
  41. #define BreakPoint()
  42. #endif
  43. #define MAX_MESSAGE_CHAR (1<<11)
  44. typedef union tagLOG_MESSAGE{
  45. CHAR pAStr[MAX_MESSAGE_CHAR];
  46. WCHAR pWStr[MAX_MESSAGE_CHAR];
  47. }LOG_MESSAGE, *PLOG_MESSAGE;
  48. typedef struct tagLOG_PARTIAL_MSG{
  49. DWORD Severity;
  50. LOG_MESSAGE Message;
  51. }LOG_PARTIAL_MSG, *PLOG_PARTIAL_MSG;
  52. ILogManager *
  53. STD_CALL_TYPE
  54. LogStandardInit(
  55. IN PCWSTR pDebugLogFileName,
  56. IN HINSTANCE hModuleInstance, OPTIONAL
  57. IN BOOL bCreateNew, OPTIONAL
  58. IN BOOL bExcludeSetupActLog, OPTIONAL
  59. IN BOOL bExcludeSetupErrLog, OPTIONAL
  60. IN BOOL bExcludeXMLLog, OPTIONAL
  61. IN BOOL bExcludeDebugFilter OPTIONAL
  62. );
  63. VOID
  64. STD_CALL_TYPE
  65. LogDestroyStandard(
  66. VOID
  67. );
  68. PLOG_PARTIAL_MSG
  69. STD_CALL_TYPE
  70. ConstructPartialMsgVW(
  71. IN DWORD dwSeverity,
  72. IN PCSTR Format,
  73. IN va_list args
  74. );
  75. PLOG_PARTIAL_MSG
  76. STD_CALL_TYPE
  77. ConstructPartialMsgVA(
  78. IN DWORD dwSeverity,
  79. IN PCSTR Format,
  80. IN va_list args
  81. );
  82. LOGRESULT
  83. STD_CALL_TYPE
  84. LogMessageA(
  85. IN PLOG_PARTIAL_MSG pPartialMsg,
  86. IN PCSTR Condition,
  87. IN DWORD SourceLineNumber,
  88. IN PCSTR SourceFile,
  89. IN PCSTR SourceFunction
  90. );
  91. LOGRESULT
  92. STD_CALL_TYPE
  93. LogMessageW(
  94. IN PLOG_PARTIAL_MSG pPartialMsg,
  95. IN PCSTR Condition,
  96. IN DWORD SourceLineNumber,
  97. IN PCWSTR SourceFile,
  98. IN PCWSTR SourceFunction
  99. );
  100. PLOG_PARTIAL_MSG
  101. STD_CALL_TYPE
  102. ConstructPartialMsgIfA(
  103. IN BOOL bCondition,
  104. IN DWORD dwSeverity,
  105. IN PCSTR Format,
  106. ...
  107. );
  108. PLOG_PARTIAL_MSG
  109. STD_CALL_TYPE
  110. ConstructPartialMsgIfW(
  111. IN BOOL bCondition,
  112. IN DWORD dwSeverity,
  113. IN PCSTR Format,
  114. ...
  115. );
  116. #ifdef DEBUG
  117. VOID
  118. _cdecl
  119. DebugLogTimeA (
  120. IN PCSTR Format,
  121. ...
  122. );
  123. VOID
  124. _cdecl
  125. DebugLogTimeW (
  126. IN PCWSTR Format,
  127. ...
  128. );
  129. #endif
  130. #if defined(__cplusplus)
  131. }
  132. #endif
  133. __inline BOOL IsConditionTrue(BOOL bCondition, ...){
  134. return bCondition;
  135. }
  136. __inline
  137. PLOG_PARTIAL_MSG
  138. STD_CALL_TYPE
  139. ConstructPartialMsgA(
  140. IN DWORD dwSeverity,
  141. IN PCSTR Format,
  142. ...
  143. ){
  144. va_list args;
  145. va_start(args, Format);
  146. return ConstructPartialMsgVA(dwSeverity, Format, args);
  147. }
  148. __inline
  149. PLOG_PARTIAL_MSG
  150. STD_CALL_TYPE
  151. ConstructPartialMsgW(
  152. IN DWORD dwSeverity,
  153. IN PCSTR Format,
  154. ...
  155. ){
  156. va_list args;
  157. va_start(args, Format);
  158. return ConstructPartialMsgVW(dwSeverity, Format, args);
  159. }
  160. #ifdef UNICODE
  161. #define ConstructPartialMsgIf ConstructPartialMsgIfW
  162. #define ConstructPartialMsg ConstructPartialMsgW
  163. #define LogMessage LogMessageW
  164. #define DebugLogTime DebugLogTimeW
  165. #else
  166. #define ConstructPartialMsgIf ConstructPartialMsgIfA
  167. #define ConstructPartialMsg ConstructPartialMsgA
  168. #define LogMessage LogMessageA
  169. #define DebugLogTime DebugLogTimeA
  170. #endif
  171. #define LOGMSGA(condition, message) LogMessageA(ConstructPartialMsgA message, condition, __LINE__, TEXT(__FILE__), TEXT(__FUNCTION__));
  172. #define LOGMSGW(condition, message) LogMessageW(ConstructPartialMsgW message, condition, __LINE__, TEXT(__FILE__), TEXT(__FUNCTION__));
  173. #define LOGMSGIFA(message) LogMessageA(ConstructPartialMsgIfA message, NULL, __LINE__, TEXT(__FILE__), TEXT(__FUNCTION__));
  174. #define LOGMSGIFW(message) LogMessageW(ConstructPartialMsgIfW message, NULL, __LINE__, TEXT(__FILE__), TEXT(__FUNCTION__));
  175. #define LOGA(message) LOGMSGA(NULL, message);
  176. #define LOGW(message) LOGMSGW(NULL, message);
  177. #define LOG_IFA(if_message) if(IsConditionTrue if_message){LOGMSGIFA(if_message);}
  178. #define LOG_IFW(if_message) if(IsConditionTrue if_message){LOGMSGIFW(if_message);}
  179. #define ELSE_LOGA(message) else{LOGA(message);}
  180. #define ELSE_LOGW(message) else{LOGW(message);}
  181. #define ELSE_LOG_IFA(if_message) else LOG_IFA(if_message);
  182. #define ELSE_LOG_IFW(if_message) else LOG_IFW(if_message);
  183. #ifdef UNICODE
  184. #define LOGMSG LOGMSGW
  185. #define LOGMSGIF LOGMSGIFW
  186. #define LOG LOGW
  187. #define LOG_IF LOG_IFW
  188. #define ELSE_LOG ELSE_LOGW
  189. #define ELSE_LOG_IF ELSE_LOG_IFW
  190. #else
  191. #define LOGMSG LOGMSGA
  192. #define LOGMSGIF LOGMSGIFA
  193. #define LOG LOGA
  194. #define LOG_IF LOG_IFA
  195. #define ELSE_LOG ELSE_LOGA
  196. #define ELSE_LOG_IF ELSE_LOG_IFA
  197. #endif
  198. #if defined(DEBUG)
  199. #define DBGMSGA(condition, message) if(logBreakPoint == LogMessageA(ConstructPartialMsgA message, condition, __LINE__, TEXT(__FILE__), TEXT(__FUNCTION__))){BreakPoint();}
  200. #define DBGMSGW(condition, message) if(logBreakPoint == LogMessageW(ConstructPartialMsgW message, condition, __LINE__, TEXT(__FILE__), TEXT(__FUNCTION__))){BreakPoint();}
  201. #define DBGMSGIFA(message) LOGMSGIFA(message)
  202. #define DBGMSGIFW(message) LOGMSGIFW(message)
  203. #else
  204. #define DBGMSGA(condition, message)
  205. #define DBGMSGW(condition, message)
  206. #define DBGMSGIFA(message)
  207. #define DBGMSGIFW(message)
  208. #endif
  209. #define DEBUGMSGA(message) DBGMSGA(NULL, message);
  210. #define DEBUGMSGW(message) DBGMSGW(NULL, message);
  211. #define DEBUGMSG_IFA(if_message) if(IsConditionTrue if_message){DBGMSGIFA(if_message);}
  212. #define DEBUGMSG_IFW(if_message) if(IsConditionTrue if_message){DBGMSGIFW(if_message);}
  213. #define ELSE_DEBUGMSGA(message) else{DEBUGMSGA(message);}
  214. #define ELSE_DEBUGMSGW(message) else{DEBUGMSGW(message);}
  215. #define ELSE_DEBUGMSG_IFA(if_message) else DEBUGMSG_IF(if_message);
  216. #define ELSE_DEBUGMSG_IFW(if_message) else DEBUGMSG_IF(if_message);
  217. #define DEBUGLOGTIMEA(message) DebugLogTimeA(message)
  218. #define DEBUGLOGTIMEW(message) DebugLogTimeW(message)
  219. #ifdef UNICODE
  220. #define DBGMSG DBGMSGW
  221. #define DBGMSGIF DBGMSGIFW
  222. #define DEBUGMSG DEBUGMSGW
  223. #define DEBUGMSG_IF DEBUGMSG_IFW
  224. #define ELSE_DEBUGMSG ELSE_DEBUGMSGW
  225. #define ELSE_DEBUGMSG_IF ELSE_DEBUGMSG_IFW
  226. #define DEBUGLOGTIME DEBUGLOGTIMEW
  227. #else
  228. #define DBGMSG DBGMSGA
  229. #define DBGMSGIF DBGMSGIFA
  230. #define DEBUGMSG DEBUGMSGA
  231. #define DEBUGMSG_IF DEBUGMSG_IFA
  232. #define ELSE_DEBUGMSG ELSE_DEBUGMSGA
  233. #define ELSE_DEBUGMSG_IF ELSE_DEBUGMSG_IFA
  234. #define DEBUGLOGTIME DEBUGLOGTIMEA
  235. #endif
  236. #if defined(DEBUG)
  237. #define MYVERIFY(condition) if(!(condition)){DBGMSG(#condition, (DBG_ASSERT, #condition));}
  238. #else
  239. #define MYVERIFY(condition) if(!(condition)){LOGMSG(#condition, (LOG_ASSERT, #condition));}
  240. #endif
  241. #define MYASSERT(condition) if(!(condition)){DBGMSG(#condition, (DBG_ASSERT, #condition));}
  242. #define MYASSERT_F(condition, message) if(!(condition)){DBGMSG(#condition, (DBG_ASSERT, message));}
  243. #define DEBUGMSG0(severity, message) DEBUGMSG((severity, message))
  244. #define DEBUGMSG1(severity, message, p1) DEBUGMSG((severity, message, p1))
  245. #define DEBUGMSG2(severity, message, p1, p2) DEBUGMSG((severity, message, p1, p2))
  246. #define DEBUGMSG3(severity, message, p1, p2, p3) DEBUGMSG((severity, message, p1, p2, p3))
  247. #define DEBUGMSG4(severity, message, p1, p2, p3, p4) DEBUGMSG((severity, message, p1, p2, p3, p4))
  248. #define LOG0(severity, message) LOG((severity, message))
  249. #define LOG1(severity, message, p1) LOG((severity, message, p1))
  250. #define LOG2(severity, message, p1, p2) LOG((severity, message, p1, p2))
  251. #define LOG3(severity, message, p1, p2, p3) LOG((severity, message, p1, p2, p3))
  252. #define LOG4(severity, message, p1, p2, p3, p4) LOG((severity, message, p1, p2, p3, p4))
  253. #define USEMSGID(x) ((PCSTR)(SIZE_T)(x))