main
h 360 lines 11.5 KB
Raw
1 #pragma once
2 // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
3
4
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8
9 #define LogExitOnFailureSource(d, x, i, f, ...) if (FAILED(x)) { LogErrorId(x, i, __VA_ARGS__); ExitTraceSource(d, x, f, __VA_ARGS__); goto LExit; }
10 #define LogExitOnRootFailureSource(d, x, i, f, ...) if (FAILED(x)) { LogErrorId(x, i, __VA_ARGS__); Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(d, x, f, __VA_ARGS__); goto LExit; }
11 #define LogExitWithRootFailureSource(d, x, e, i, f, ...) { x = FAILED(e) ? e : E_FAIL; LogErrorId(x, i, __VA_ARGS__); Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(d, x, f, __VA_ARGS__); goto LExit; }
12
13 #define LogExitOnFailure(x, i, f, ...) LogExitOnFailureSource(DUTIL_SOURCE_DEFAULT, x, i, f, __VA_ARGS__)
14 #define LogExitOnRootFailure(x, i, f, ...) LogExitOnRootFailureSource(DUTIL_SOURCE_DEFAULT, x, i, f, __VA_ARGS__)
15 #define LogExitWithRootFailure(x, e, i, f, ...) LogExitWithRootFailureSource(DUTIL_SOURCE_DEFAULT, x, e, i, f, __VA_ARGS__)
16
17 typedef HRESULT (DAPI *PFN_LOGSTRINGWORKRAW)(
18 __in_z LPCSTR szString,
19 __in_opt LPVOID pvContext
20 );
21
22 // enums
23
24 // structs
25
26 // functions
27 /********************************************************************
28 IsLogInitialized - Checks if log is currently initialized.
29 ********************************************************************/
30 BOOL DAPI IsLogInitialized();
31
32 /********************************************************************
33 IsLogOpen - Checks if log is currently initialized and open.
34 ********************************************************************/
35 BOOL DAPI IsLogOpen();
36
37 /********************************************************************
38 LogInitialize - initializes the logutil API
39
40 ********************************************************************/
41 void DAPI LogInitialize(
42 __in_opt HMODULE hModule
43 );
44
45 /********************************************************************
46 LogOpen - creates an application log file
47
48 NOTE: if wzExt is null then wzLog is path to desired log else wzLog and wzExt are used to generate log name
49 ********************************************************************/
50 HRESULT DAPI LogOpen(
51 __in_z_opt LPCWSTR wzDirectory,
52 __in_z LPCWSTR wzLog,
53 __in_z_opt LPCWSTR wzPostfix,
54 __in_z_opt LPCWSTR wzExt,
55 __in BOOL fAppend,
56 __in BOOL fHeader,
57 __out_z_opt LPWSTR* psczLogPath
58 );
59
60 /********************************************************************
61 LogDisable - closes any open files and disables in memory logging.
62
63 ********************************************************************/
64 void DAPI LogDisable();
65
66 /********************************************************************
67 LogRedirect - Redirects all logging strings to the specified
68 function - or set NULL to disable the hook
69 ********************************************************************/
70 void DAPI LogRedirect(
71 __in_opt PFN_LOGSTRINGWORKRAW vpfLogStringWorkRaw,
72 __in_opt LPVOID pvContext
73 );
74
75 /********************************************************************
76 LogRename - Renames a logfile, moving its contents to a new path,
77 and re-opening the file for appending at the new
78 location
79 ********************************************************************/
80 HRESULT DAPI LogRename(
81 __in_z LPCWSTR wzNewPath
82 );
83
84 /********************************************************************
85 LogFlush - calls ::FlushFileBuffers with the log file handle.
86
87 ********************************************************************/
88 HRESULT DAPI LogFlush();
89
90 void DAPI LogClose(
91 __in BOOL fFooter
92 );
93
94 void DAPI LogUninitialize(
95 __in BOOL fFooter
96 );
97
98 /********************************************************************
99 LogIsOpen - returns whether log file is open or note
100
101 ********************************************************************/
102 BOOL DAPI LogIsOpen();
103
104 /********************************************************************
105 LogSetSpecialParams - sets a special beginline string, endline
106 string, post-timestamp string, etc.
107 ********************************************************************/
108 HRESULT DAPI LogSetSpecialParams(
109 __in_z_opt LPCWSTR wzSpecialBeginLine,
110 __in_z_opt LPCWSTR wzSpecialAfterTimeStamp,
111 __in_z_opt LPCWSTR wzSpecialEndLine
112 );
113
114 /********************************************************************
115 LogSetLevel - sets the logging level
116
117 NOTE: returns previous logging level
118 ********************************************************************/
119 REPORT_LEVEL DAPI LogSetLevel(
120 __in REPORT_LEVEL rl,
121 __in BOOL fLogChange
122 );
123
124 /********************************************************************
125 LogGetLevel - gets the current logging level
126
127 ********************************************************************/
128 REPORT_LEVEL DAPI LogGetLevel();
129
130 /********************************************************************
131 LogGetPath - gets the current log path
132
133 ********************************************************************/
134 HRESULT DAPI LogGetPath(
135 __out_ecount_z(cchLogPath) LPWSTR pwzLogPath,
136 __in DWORD cchLogPath
137 );
138
139 /********************************************************************
140 LogGetHandle - gets the current log file handle
141
142 ********************************************************************/
143 HANDLE DAPI LogGetHandle();
144
145 /********************************************************************
146 LogStringArgs - implementation of LogString
147
148 ********************************************************************/
149 HRESULT DAPI LogStringArgs(
150 __in REPORT_LEVEL rl,
151 __in_z __format_string LPCSTR szFormat,
152 __in va_list args
153 );
154
155 /********************************************************************
156 LogString - write a string to the log
157
158 NOTE: use printf formatting ("%ls", "%d", etc.)
159 ********************************************************************/
160 inline HRESULT LogString(
161 __in REPORT_LEVEL rl,
162 __in_z __format_string LPCSTR szFormat,
163 ...
164 )
165 {
166 HRESULT hr = S_OK;
167 va_list args;
168
169 va_start(args, szFormat);
170 hr = LogStringArgs(rl, szFormat, args);
171 va_end(args);
172
173 return hr;
174 }
175
176 /********************************************************************
177 LogStringLineArgs - implementation of LogStringLine
178
179 ********************************************************************/
180 HRESULT DAPI LogStringLineArgs(
181 __in REPORT_LEVEL rl,
182 __in_z __format_string LPCSTR szFormat,
183 __in va_list args
184 );
185
186 /********************************************************************
187 LogStringLine - write a string plus LOGUTIL_NEWLINE to the log
188
189 NOTE: use printf formatting ("%ls", "%d", etc.)
190 ********************************************************************/
191 inline HRESULT LogStringLine(
192 __in REPORT_LEVEL rl,
193 __in_z __format_string LPCSTR szFormat,
194 ...
195 )
196 {
197 HRESULT hr = S_OK;
198 va_list args;
199
200 va_start(args, szFormat);
201 hr = LogStringLineArgs(rl, szFormat, args);
202 va_end(args);
203
204 return hr;
205 }
206
207 /********************************************************************
208 LogIdModuleArgs - implementation of LogIdModule
209
210 ********************************************************************/
211 HRESULT DAPI LogIdModuleArgs(
212 __in REPORT_LEVEL rl,
213 __in DWORD dwLogId,
214 __in_opt HMODULE hModule,
215 __in va_list args
216 );
217
218 /********************************************************************
219 LogIdModule - write a string embedded in a MESSAGETABLE in the specified module to the log
220
221 NOTE: uses format string from MESSAGETABLE resource
222 ********************************************************************/
223 inline HRESULT LogIdModule(
224 __in REPORT_LEVEL rl,
225 __in DWORD dwLogId,
226 __in_opt HMODULE hModule,
227 ...
228 )
229 {
230 HRESULT hr = S_OK;
231 va_list args;
232
233 va_start(args, hModule);
234 hr = LogIdModuleArgs(rl, dwLogId, hModule, args);
235 va_end(args);
236
237 return hr;
238 }
239
240 /********************************************************************
241 LogIdArgs - inline wrapper for LogIdModuleArgs, passing NULL for hModule
242
243 ********************************************************************/
244 inline HRESULT LogIdArgs(
245 __in REPORT_LEVEL rl,
246 __in DWORD dwLogId,
247 __in va_list args
248 )
249 {
250 return LogIdModuleArgs(rl, dwLogId, NULL, args);
251 }
252
253 /********************************************************************
254 LogId - write a string embedded in a MESSAGETABLE in the default module to the log
255
256 NOTE: uses format string from MESSAGETABLE resource
257 ********************************************************************/
258 inline HRESULT LogId(
259 __in REPORT_LEVEL rl,
260 __in DWORD dwLogId,
261 ...
262 )
263 {
264 HRESULT hr = S_OK;
265 va_list args;
266
267 va_start(args, dwLogId);
268 hr = LogIdArgs(rl, dwLogId, args);
269 va_end(args);
270
271 return hr;
272 }
273
274 /********************************************************************
275 LogErrorStringArgs - implementation of LogErrorString
276
277 ********************************************************************/
278 HRESULT DAPI LogErrorStringArgs(
279 __in HRESULT hrError,
280 __in_z __format_string LPCSTR szFormat,
281 __in va_list args
282 );
283
284 /********************************************************************
285 LogErrorString - write an error to the log
286
287 NOTE: use printf formatting ("%ls", "%d", etc.)
288 ********************************************************************/
289 inline HRESULT LogErrorString(
290 __in HRESULT hrError,
291 __in_z __format_string LPCSTR szFormat,
292 ...
293 )
294 {
295 HRESULT hr = S_OK;
296
297 va_list args;
298 va_start(args, szFormat);
299 hr = LogErrorStringArgs(hrError, szFormat, args);
300 va_end(args);
301
302 return hr;
303 }
304
305 /********************************************************************
306 LogErrorIdModule - write an error string embedded in the specified module in a MESSAGETABLE to the log
307
308 NOTE: uses format string from MESSAGETABLE resource
309 can log no more than three strings in the error message
310 ********************************************************************/
311 HRESULT DAPI LogErrorIdModule(
312 __in HRESULT hrError,
313 __in DWORD dwLogId,
314 __in_opt HMODULE hModule,
315 __in_z_opt LPCWSTR wzString1,
316 __in_z_opt LPCWSTR wzString2,
317 __in_z_opt LPCWSTR wzString3
318 );
319
320 /********************************************************************
321 LogErrorId - write an error string embedded in the default module in a MESSAGETABLE to the log
322
323 NOTE: uses format string from MESSAGETABLE resource
324 can log no more than three strings in the error message
325 ********************************************************************/
326 inline HRESULT LogErrorId(
327 __in HRESULT hrError,
328 __in DWORD dwLogId,
329 __in_z_opt LPCWSTR wzString1 = NULL,
330 __in_z_opt LPCWSTR wzString2 = NULL,
331 __in_z_opt LPCWSTR wzString3 = NULL
332 )
333 {
334 return LogErrorIdModule(hrError, dwLogId, NULL, wzString1, wzString2, wzString3);
335 }
336
337 /********************************************************************
338 LogHeader - write a standard header to the log
339
340 ********************************************************************/
341 HRESULT DAPI LogHeader();
342
343 /********************************************************************
344 LogFooter - write a standard footer to the log
345
346 ********************************************************************/
347 HRESULT DAPI LogFooter();
348
349 /********************************************************************
350 LogStringWorkRaw - Write a raw, unformatted string to the log
351
352 ********************************************************************/
353 HRESULT DAPI LogStringWorkRaw(
354 __in_z LPCSTR szLogData
355 );
356
357 #ifdef __cplusplus
358 }
359 #endif
360