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.

486 lines
10 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. log.h
  5. Abstract:
  6. Implements routines that simplify the writing to setupact.log
  7. and setuperr.log.
  8. Author:
  9. Jim Schmidt (jimschm) 25-Feb-1997
  10. Revision History:
  11. mikeco 23-May-1997 Ran code through train_wreck.exe
  12. Ovidiu Temereanca (ovidiut) 23-Oct-1998
  13. Added new logging capabilities
  14. */
  15. //
  16. // If either DBG or DEBUG defined, use debug mode
  17. //
  18. #ifdef DBG
  19. #ifndef DEBUG
  20. #define DEBUG
  21. #endif
  22. #endif
  23. #ifdef DEBUG
  24. #ifndef DBG
  25. #define DBG
  26. #endif
  27. #endif
  28. //
  29. // Redefine MYASSERT
  30. //
  31. #ifdef DEBUG
  32. #ifdef MYASSERT
  33. #undef MYASSERT
  34. #endif
  35. #define DBG_ASSERT "Assert"
  36. #define MYASSERT(expr) LogBegin(g_hInst); \
  37. LogIfA( \
  38. !(expr), \
  39. DBG_ASSERT, \
  40. "Assert Failure\n\n%s\n\n%s line %u", \
  41. #expr, \
  42. __FILE__, \
  43. __LINE__ \
  44. ); \
  45. LogEnd()
  46. #else
  47. #ifndef MYASSERT
  48. #define MYASSERT(x)
  49. #endif
  50. #endif
  51. #define LOG_FATAL_ERROR "Fatal Error"
  52. #define LOG_MODULE_ERROR "Module Error"
  53. #define LOG_ERROR "Error"
  54. #define LOG_WARNING "Warning"
  55. #define LOG_INFORMATION "Info"
  56. #define LOG_STATUS "Status"
  57. #define LOG_UPDATE "Update"
  58. typedef enum {
  59. LOGSEV_DEBUG = 0,
  60. LOGSEV_INFORMATION = 1,
  61. LOGSEV_WARNING = 2,
  62. LOGSEV_ERROR = 3,
  63. LOGSEV_FATAL_ERROR = 4
  64. } LOGSEVERITY;
  65. typedef struct {
  66. BOOL Debug;
  67. HMODULE ModuleInstance;
  68. LOGSEVERITY Severity; // non-debug only
  69. PCSTR Type;
  70. PCSTR Message; // debug only
  71. PCSTR FormattedMessage;
  72. } LOGARGA, *PLOGARGA;
  73. typedef struct {
  74. BOOL Debug;
  75. HMODULE ModuleInstance;
  76. LOGSEVERITY Severity; // non-debug only
  77. PCSTR Type; // note ansi type
  78. PCWSTR Message; // debug only
  79. PCWSTR FormattedMessage;
  80. } LOGARGW, *PLOGARGW;
  81. typedef enum {
  82. OD_UNDEFINED = 0x00, // undefined output dest
  83. OD_DEBUGLOG = 0x01, // debuglog used
  84. OD_SUPPRESS = 0x02, // don't log to any device
  85. OD_ERROR = 0x04, // automatically append GetLastError() to the message
  86. OD_LOGFILE = 0x08, // messages go to logfile
  87. OD_DEBUGGER = 0x10, // messages go to debugger
  88. OD_CONSOLE = 0x20, // messages go to console
  89. OD_POPUP = 0x40, // display a popup dialog
  90. OD_POPUP_CANCEL = 0x80, // do not display a popup dialog (cancelled by user)
  91. OD_FORCE_POPUP = 0x100, // force the popup to be displayed always
  92. OD_MUST_BE_LOCALIZED = 0x200, // used for LOG() that will generate a popup
  93. OD_UNATTEND_POPUP = 0x400, // force the popup to be displayed in unattend mode
  94. OD_ASSERT = 0x800, // give DebugBreak option in popup
  95. } OUTPUT_DESTINATION;
  96. typedef enum {
  97. LL_FATAL_ERROR = 0x01,
  98. LL_MODULE_ERROR = 0x02,
  99. LL_ERROR = 0x04,
  100. LL_WARNING = 0x08,
  101. LL_INFORMATION = 0x10,
  102. LL_STATUS = 0x20,
  103. LL_UPDATE = 0x40,
  104. } LOG_LEVEL;
  105. typedef BOOL (WINAPI LOGCALLBACKA)(PLOGARGA Args);
  106. typedef LOGCALLBACKA * PLOGCALLBACKA;
  107. typedef BOOL (WINAPI LOGCALLBACKW)(PLOGARGW Args);
  108. typedef LOGCALLBACKW * PLOGCALLBACKW;
  109. VOID
  110. LogBegin (
  111. IN HMODULE ModuleInstance
  112. );
  113. VOID
  114. LogEnd (
  115. VOID
  116. );
  117. BOOL
  118. LogReInitA (
  119. IN HWND NewParent, OPTIONAL
  120. OUT HWND *OrgParent, OPTIONAL
  121. IN PCSTR LogFile, OPTIONAL
  122. IN PLOGCALLBACKA LogCallback OPTIONAL
  123. );
  124. BOOL
  125. LogReInitW (
  126. IN HWND NewParent, OPTIONAL
  127. OUT HWND *OrgParent, OPTIONAL
  128. IN PCWSTR LogFile, OPTIONAL
  129. IN PLOGCALLBACKW LogCallback OPTIONAL
  130. );
  131. VOID
  132. LogSetVerboseLevel (
  133. IN OUTPUT_DESTINATION Level
  134. );
  135. VOID
  136. LogSetVerboseBitmap (
  137. IN LOG_LEVEL Bitmap,
  138. IN LOG_LEVEL BitsToAdjustMask,
  139. IN BOOL EnableDebugger
  140. );
  141. #ifdef UNICODE
  142. #define LOGARG LOGARGW
  143. #define LOGCALLBACK LOGCALLBACKW
  144. #define PLOGARG PLOGARGW
  145. #define PLOGCALLBACK PLOGCALLBACKW
  146. #define LogReInit LogReInitW
  147. #else
  148. #define LOGARG LOGARGA
  149. #define LOGCALLBACK LOGCALLBACKA
  150. #define PLOGARG PLOGARGA
  151. #define PLOGCALLBACK PLOGCALLBACKA
  152. #define LogReInit LogReInitA
  153. #endif
  154. VOID
  155. LogDeleteOnNextInit(
  156. VOID
  157. );
  158. #define SET_RESETLOG() LogDeleteOnNextInit()
  159. VOID
  160. _cdecl
  161. LogA (
  162. IN PCSTR Type,
  163. IN PCSTR Format,
  164. ...
  165. );
  166. VOID
  167. _cdecl
  168. LogW (
  169. IN PCSTR Type,
  170. IN PCSTR Format,
  171. ...
  172. );
  173. VOID
  174. _cdecl
  175. LogIfA (
  176. IN BOOL Condition,
  177. IN PCSTR Type,
  178. IN PCSTR Format,
  179. ...
  180. );
  181. VOID
  182. _cdecl
  183. LogIfW (
  184. IN BOOL Condition,
  185. IN PCSTR Type,
  186. IN PCSTR Format,
  187. ...
  188. );
  189. VOID
  190. LogTitleA (
  191. IN PCSTR Type,
  192. IN PCSTR Title
  193. );
  194. VOID
  195. LogTitleW (
  196. IN PCSTR Type,
  197. IN PCWSTR Title
  198. );
  199. VOID
  200. LogLineA (
  201. IN PCSTR Line
  202. );
  203. VOID
  204. LogLineW (
  205. IN PCWSTR Line
  206. );
  207. VOID
  208. LogDirectA (
  209. IN PCSTR Type,
  210. IN PCSTR Text
  211. );
  212. VOID
  213. LogDirectW (
  214. IN PCSTR Type,
  215. IN PCWSTR Text
  216. );
  217. VOID
  218. SuppressAllLogPopups (
  219. IN BOOL SuppressOn
  220. );
  221. BOOL
  222. LogSetErrorDest (
  223. IN PCSTR Type,
  224. IN OUTPUT_DESTINATION OutDest
  225. );
  226. // Define W symbols
  227. extern HMODULE g_hInst;
  228. #define LOGW(x) LogBegin(g_hInst);LogW x;LogEnd()
  229. #define LOGW_IF(x) LogBegin(g_hInst);LogIfW x;LogEnd()
  230. #define ELSE_LOGW(x) else {LogBegin(g_hInst);LogW x;LogEnd();}
  231. #define ELSE_LOGW_IF(x) else {LogBegin(g_hInst);LogIfW x;LogEnd();}
  232. #define LOGTITLEW(type,title) LogBegin(g_hInst);LogTitleW (type,title);LogEnd()
  233. #define LOGLINEW(title) LogBegin(g_hInst);LogLineW (title);LogEnd()
  234. #define LOGDIRECTW(type,text) LogBegin(g_hInst);LogDirectW (type,text);LogEnd()
  235. // Define A symbols
  236. #define LOGA(x) LogBegin(g_hInst);LogA x;LogEnd()
  237. #define LOGA_IF(x) LogBegin(g_hInst);LogIfA x;LogEnd()
  238. #define ELSE_LOGA(x) else {LogBegin(g_hInst);LogA x;LogEnd();}
  239. #define ELSE_LOGA_IF(x) else {LogBegin(g_hInst);LogIfA x;LogEnd();}
  240. #define LOGTITLEA(type,title) LogBegin(g_hInst);LogTitleA (type,title);LogEnd()
  241. #define LOGLINEA(line) LogBegin(g_hInst);LogLineA (line);LogEnd()
  242. #define LOGDIRECTA(type,text) LogBegin(g_hInst);LogDirectA (type,text);LogEnd()
  243. // Define generic symbols
  244. #ifdef UNICODE
  245. #define LOG(x) LOGW(x)
  246. #define LOG_IF(x) LOGW_IF(x)
  247. #define ELSE_LOG(x) ELSE_LOGW(x)
  248. #define ELSE_LOG_IF(x) ELSE_LOGW_IF(x)
  249. #define LOGTITLE(type,title) LOGTITLEW(type,title)
  250. #define LOGLINE(title) LOGLINEW(title)
  251. #define LOGDIRECT(type,text) LOGDIRECTW(type,text)
  252. #else
  253. #define LOG(x) LOGA(x)
  254. #define LOG_IF(x) LOGA_IF(x)
  255. #define ELSE_LOG(x) ELSE_LOGA(x)
  256. #define ELSE_LOG_IF(x) ELSE_LOGA_IF(x)
  257. #define LOGTITLE(type,title) LOGTITLEA(type,title)
  258. #define LOGLINE(title) LOGLINEA(title)
  259. #define LOGDIRECT(type,text) LOGDIRECTA(type,text)
  260. #endif // UNICODE
  261. #ifdef DEBUG
  262. #define DBG_NAUSEA "Nausea"
  263. #define DBG_VERBOSE "Verbose"
  264. #define DBG_STATS "Stats"
  265. #define DBG_WARNING "Warning"
  266. #define DBG_ERROR "Error"
  267. #define DBG_WHOOPS "Whoops"
  268. #define DBG_TRACK "Track"
  269. #define DBG_TIME "Time"
  270. VOID
  271. _cdecl
  272. DbgLogA (
  273. IN PCSTR Type,
  274. IN PCSTR Format,
  275. ...
  276. );
  277. VOID
  278. _cdecl
  279. DbgLogW (
  280. IN PCSTR Type,
  281. IN PCSTR Format,
  282. ...
  283. );
  284. VOID
  285. _cdecl
  286. DbgLogIfA (
  287. IN BOOL Condition,
  288. IN PCSTR Type,
  289. IN PCSTR Format,
  290. ...
  291. );
  292. VOID
  293. _cdecl
  294. DbgLogIfW (
  295. IN BOOL Condition,
  296. IN PCSTR Type,
  297. IN PCSTR Format,
  298. ...
  299. );
  300. VOID
  301. DbgDirectA (
  302. IN PCSTR Type,
  303. IN PCSTR Text
  304. );
  305. VOID
  306. DbgDirectW (
  307. IN PCSTR Type,
  308. IN PCWSTR Text
  309. );
  310. VOID
  311. _cdecl
  312. DebugLogTimeA (
  313. IN PCSTR Format,
  314. ...
  315. );
  316. VOID
  317. _cdecl
  318. DebugLogTimeW (
  319. IN PCSTR Format,
  320. ...
  321. );
  322. VOID
  323. LogCopyDebugInfPathA(
  324. OUT PSTR MaxPathBuffer
  325. );
  326. VOID
  327. LogCopyDebugInfPathW(
  328. OUT PWSTR MaxPathBuffer
  329. );
  330. // Define W symbols
  331. #define DEBUGMSGW(x) LogBegin(g_hInst);DbgLogW x;LogEnd()
  332. #define DEBUGMSGW_IF(x) LogBegin(g_hInst);DbgLogIfW x;LogEnd()
  333. #define ELSE_DEBUGMSGW(x) else {LogBegin(g_hInst);DbgLogW x;LogEnd();}
  334. #define ELSE_DEBUGMSGW_IF(x) else {LogBegin(g_hInst);DbgLogW x;LogEnd();}
  335. #define DEBUGLOGTIMEW(x) LogBegin(g_hInst);DebugLogTimeW x;LogEnd()
  336. #define DEBUGDIRECTW(type,text) LogBegin(g_hInst);DbgDirectW (type,text);LogEnd()
  337. // Define A symbols
  338. #define DEBUGMSGA(x) LogBegin(g_hInst);DbgLogA x;LogEnd()
  339. #define DEBUGMSGA_IF(x) LogBegin(g_hInst);DbgLogIfA x;LogEnd()
  340. #define ELSE_DEBUGMSGA(x) else {LogBegin(g_hInst);DbgLogA x;LogEnd();}
  341. #define ELSE_DEBUGMSGA_IF(x) else {LogBegin(g_hInst);DbgLogIfA x;LogEnd();}
  342. #define DEBUGLOGTIMEA(x) LogBegin(g_hInst);DebugLogTimeA x;LogEnd()
  343. #define DEBUGDIRECTA(type,text) LogBegin(g_hInst);DbgDirectA (type,text);LogEnd()
  344. // Define generic symbols
  345. #ifdef UNICODE
  346. #define DEBUGMSG(x) DEBUGMSGW(x)
  347. #define DEBUGMSG_IF(x) DEBUGMSGW_IF(x)
  348. #define ELSE_DEBUGMSG(x) ELSE_DEBUGMSGW(x)
  349. #define ELSE_DEBUGMSG_IF(x) ELSE_DEBUGMSGW_IF(x)
  350. #define DEBUGLOGTIME(x) DEBUGLOGTIMEW(x)
  351. #define DEBUGDIRECT(type,text) DEBUGDIRECTW(type,text)
  352. #define LogCopyDebugInfPath LogCopyDebugInfPathW
  353. #else
  354. #define DEBUGMSG(x) DEBUGMSGA(x)
  355. #define DEBUGMSG_IF(x) DEBUGMSGA_IF(x)
  356. #define ELSE_DEBUGMSG(x) ELSE_DEBUGMSGA(x)
  357. #define ELSE_DEBUGMSG_IF(x) ELSE_DEBUGMSGA_IF(x)
  358. #define DEBUGLOGTIME(x) DEBUGLOGTIMEA(x)
  359. #define DEBUGDIRECT(type,text) DEBUGDIRECTA(type,text)
  360. #define LogCopyDebugInfPath LogCopyDebugInfPathA
  361. #endif // UNICODE
  362. #else // !defined(DEBUG)
  363. //
  364. // No-debug constants
  365. //
  366. #define DEBUGMSG(x)
  367. #define DEBUGMSGA(x)
  368. #define DEBUGMSGW(x)
  369. #define DEBUGMSG_IF(x)
  370. #define DEBUGMSGA_IF(x)
  371. #define DEBUGMSGW_IF(x)
  372. #define ELSE_DEBUGMSG(x)
  373. #define ELSE_DEBUGMSGA(x)
  374. #define ELSE_DEBUGMSGW(x)
  375. #define ELSE_DEBUGMSG_IF(x)
  376. #define ELSE_DEBUGMSGA_IF(x)
  377. #define ELSE_DEBUGMSGW_IF(x)
  378. #define DEBUGLOGTIME(x)
  379. #define DEBUGDIRECTA(type,text)
  380. #define DEBUGDIRECTW(type,text)
  381. #define DEBUGDIRECT(type,text)
  382. #endif // DEBUG