]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
8ca28fb7 | 2 | // Name: wx/log.h |
c801d85f KB |
3 | // Purpose: Assorted wxLogXXX functions, and wxLog (sink for logs) |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 29/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
34138703 JS |
12 | #ifndef _WX_LOG_H_ |
13 | #define _WX_LOG_H_ | |
c801d85f | 14 | |
d6b9496a VZ |
15 | #ifdef __GNUG__ |
16 | #pragma interface "log.h" | |
0d3820b3 | 17 | #endif |
c801d85f | 18 | |
38830220 | 19 | #include "wx/setup.h" |
d1af991f | 20 | #include "wx/string.h" |
38830220 | 21 | |
546db2a8 VZ |
22 | // ---------------------------------------------------------------------------- |
23 | // forward declarations | |
24 | // ---------------------------------------------------------------------------- | |
25 | ||
26 | class WXDLLEXPORT wxTextCtrl; | |
27 | class WXDLLEXPORT wxLogFrame; | |
28 | class WXDLLEXPORT wxFrame; | |
29 | ||
30 | // ---------------------------------------------------------------------------- | |
31 | // types | |
32 | // ---------------------------------------------------------------------------- | |
33 | ||
34 | typedef unsigned long wxTraceMask; | |
35 | typedef unsigned long wxLogLevel; | |
36 | ||
37 | // ---------------------------------------------------------------------------- | |
38 | // headers | |
39 | // ---------------------------------------------------------------------------- | |
40 | ||
88ac883a VZ |
41 | #if wxUSE_LOG |
42 | ||
c30aaf75 VZ |
43 | #include <time.h> // for time_t |
44 | ||
45 | #include "wx/dynarray.h" | |
d6b9496a | 46 | |
9ef3052c VZ |
47 | // ---------------------------------------------------------------------------- |
48 | // constants | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
51 | // different standard log levels (you may also define your own) | |
52 | enum | |
53 | { | |
d6b9496a VZ |
54 | wxLOG_FatalError, // program can't continue, abort immediately |
55 | wxLOG_Error, // a serious error, user must be informed about it | |
56 | wxLOG_Warning, // user is normally informed about it but may be ignored | |
57 | wxLOG_Message, // normal message (i.e. normal output of a non GUI app) | |
58 | wxLOG_Info, // informational message (a.k.a. 'Verbose') | |
59 | wxLOG_Status, // informational: might go to the status line of GUI app | |
60 | wxLOG_Debug, // never shown to the user, disabled in release mode | |
61 | wxLOG_Trace, // trace messages are also only enabled in debug mode | |
62 | wxLOG_Progress, // used for progress indicator (not yet) | |
63 | wxLOG_User = 100 // user defined levels start here | |
9ef3052c VZ |
64 | }; |
65 | ||
d6b9496a VZ |
66 | // symbolic trace masks - wxLogTrace("foo", "some trace message...") will be |
67 | // discarded unless the string "foo" has been added to the list of allowed | |
68 | // ones with AddTraceMask() | |
69 | ||
08298395 OK |
70 | #define wxTRACE_MemAlloc wxT("memalloc") // trace memory allocation (new/delete) |
71 | #define wxTRACE_Messages wxT("messages") // trace window messages/X callbacks | |
72 | #define wxTRACE_ResAlloc wxT("resalloc") // trace GDI resource allocation | |
73 | #define wxTRACE_RefCount wxT("refcount") // trace various ref counting operations | |
d6b9496a VZ |
74 | |
75 | #ifdef __WXMSW__ | |
08298395 | 76 | #define wxTRACE_OleCalls wxT("ole") // OLE interface calls |
d6b9496a VZ |
77 | #endif |
78 | ||
79 | // the trace masks have been superceded by symbolic trace constants, they're | |
80 | // for compatibility only andwill be removed soon - do NOT use them | |
81 | ||
9ef3052c VZ |
82 | // meaning of different bits of the trace mask (which allows selectively |
83 | // enable/disable some trace messages) | |
84 | #define wxTraceMemAlloc 0x0001 // trace memory allocation (new/delete) | |
85 | #define wxTraceMessages 0x0002 // trace window messages/X callbacks | |
86 | #define wxTraceResAlloc 0x0004 // trace GDI resource allocation | |
87 | #define wxTraceRefCount 0x0008 // trace various ref counting operations | |
88 | ||
2049ba38 | 89 | #ifdef __WXMSW__ |
d6b9496a | 90 | #define wxTraceOleCalls 0x0100 // OLE interface calls |
9ef3052c VZ |
91 | #endif |
92 | ||
38830220 | 93 | #include "wx/ioswrap.h" |
470b7da3 | 94 | |
c801d85f KB |
95 | // ---------------------------------------------------------------------------- |
96 | // derive from this class to redirect (or suppress, or ...) log messages | |
97 | // normally, only a single instance of this class exists but it's not enforced | |
c801d85f | 98 | // ---------------------------------------------------------------------------- |
d6b9496a | 99 | |
c801d85f KB |
100 | class WXDLLEXPORT wxLog |
101 | { | |
102 | public: | |
d6b9496a VZ |
103 | // ctor |
104 | wxLog(); | |
105 | ||
106 | // these functions allow to completely disable all log messages | |
107 | // is logging disabled now? | |
108 | static bool IsEnabled() { return ms_doLog; } | |
109 | // change the flag state, return the previous one | |
110 | static bool EnableLogging(bool doIt = TRUE) | |
111 | { bool doLogOld = ms_doLog; ms_doLog = doIt; return doLogOld; } | |
112 | ||
113 | // static sink function - see DoLog() for function to overload in the | |
114 | // derived classes | |
9e3d3318 | 115 | static void OnLog(wxLogLevel level, const wxChar *szString, time_t t) |
d6b9496a VZ |
116 | { |
117 | if ( IsEnabled() ) { | |
118 | wxLog *pLogger = GetActiveTarget(); | |
119 | if ( pLogger ) | |
120 | pLogger->DoLog(level, szString, t); | |
121 | } | |
803bf1c5 | 122 | } |
d6b9496a VZ |
123 | |
124 | // message buffering | |
125 | // flush shows all messages if they're not logged immediately (FILE | |
126 | // and iostream logs don't need it, but wxGuiLog does to avoid showing | |
127 | // 17 modal dialogs one after another) | |
128 | virtual void Flush(); | |
129 | // call to Flush() may be optimized: call it only if this function | |
130 | // returns true (although Flush() also returns immediately if there is | |
131 | // no messages, this functions is more efficient because inline) | |
132 | bool HasPendingMessages() const { return m_bHasMessages; } | |
133 | ||
134 | // only one sink is active at each moment | |
bbfa0322 VZ |
135 | // flush the active target if any |
136 | static void FlushActive() | |
137 | { | |
2ed3265e VZ |
138 | if ( !ms_suspendCount ) |
139 | { | |
140 | wxLog *log = GetActiveTarget(); | |
141 | if ( log && log->HasPendingMessages() ) | |
142 | log->Flush(); | |
143 | } | |
bbfa0322 | 144 | } |
d6b9496a VZ |
145 | // get current log target, will call wxApp::CreateLogTarget() to |
146 | // create one if none exists | |
147 | static wxLog *GetActiveTarget(); | |
148 | // change log target, pLogger may be NULL | |
149 | static wxLog *SetActiveTarget(wxLog *pLogger); | |
150 | ||
2ed3265e VZ |
151 | // suspend the message flushing of the main target until the next call |
152 | // to Resume() - this is mainly for internal use (to prevent wxYield() | |
153 | // from flashing the messages) | |
154 | static void Suspend() { ms_suspendCount++; } | |
155 | // must be called for each Suspend()! | |
156 | static void Resume() { ms_suspendCount--; } | |
157 | ||
d6b9496a VZ |
158 | // functions controlling the default wxLog behaviour |
159 | // verbose mode is activated by standard command-line '-verbose' | |
160 | // option | |
fd7718b2 | 161 | static void SetVerbose(bool bVerbose = TRUE) { ms_bVerbose = bVerbose; } |
d6b9496a VZ |
162 | // should GetActiveTarget() try to create a new log object if the |
163 | // current is NULL? | |
36bd6902 | 164 | static void DontCreateOnDemand(); |
d6b9496a VZ |
165 | |
166 | // trace mask (see wxTraceXXX constants for details) | |
167 | static void SetTraceMask(wxTraceMask ulMask) { ms_ulTraceMask = ulMask; } | |
168 | // add string trace mask | |
169 | static void AddTraceMask(const wxString& str) { ms_aTraceMasks.Add(str); } | |
170 | // add string trace mask | |
171 | static void RemoveTraceMask(const wxString& str); | |
36bd6902 VZ |
172 | // remove all string trace masks |
173 | static void ClearTraceMasks(); | |
d6b9496a | 174 | |
d2e1ef19 VZ |
175 | // sets the timestamp string: this is used as strftime() format string |
176 | // for the log targets which add time stamps to the messages - set it | |
177 | // to NULL to disable time stamping completely. | |
178 | static void SetTimestamp(const wxChar *ts) { ms_timestamp = ts; } | |
179 | ||
d6b9496a VZ |
180 | // accessors |
181 | // gets the verbose status | |
fd7718b2 | 182 | static bool GetVerbose() { return ms_bVerbose; } |
d6b9496a VZ |
183 | // get trace mask |
184 | static wxTraceMask GetTraceMask() { return ms_ulTraceMask; } | |
185 | // is this trace mask in the list? | |
9e3d3318 | 186 | static bool IsAllowedTraceMask(const wxChar *mask) |
d6b9496a VZ |
187 | { return ms_aTraceMasks.Index(mask) != wxNOT_FOUND; } |
188 | ||
d2e1ef19 VZ |
189 | // get the current timestamp format string (may be NULL) |
190 | static const wxChar *GetTimestamp() { return ms_timestamp; } | |
191 | ||
192 | // helpers | |
193 | // put the time stamp into the string if ms_timestamp != NULL (don't | |
194 | // change it otherwise) | |
195 | static void TimeStamp(wxString *str); | |
196 | ||
d6b9496a VZ |
197 | // make dtor virtual for all derived classes |
198 | virtual ~wxLog() { } | |
c801d85f KB |
199 | |
200 | protected: | |
d6b9496a | 201 | bool m_bHasMessages; // any messages in the queue? |
c801d85f | 202 | |
d6b9496a VZ |
203 | // the logging functions that can be overriden |
204 | // default DoLog() prepends the time stamp and a prefix corresponding | |
205 | // to the message to szString and then passes it to DoLogString() | |
9e3d3318 | 206 | virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t); |
d6b9496a VZ |
207 | // default DoLogString does nothing but is not pure virtual because if |
208 | // you override DoLog() you might not need it at all | |
9e3d3318 | 209 | virtual void DoLogString(const wxChar *szString, time_t t); |
c801d85f | 210 | |
d6b9496a VZ |
211 | private: |
212 | // static variables | |
213 | // ---------------- | |
06db8ebd | 214 | |
d6b9496a VZ |
215 | static wxLog *ms_pLogger; // currently active log sink |
216 | static bool ms_doLog; // FALSE => all logging disabled | |
217 | static bool ms_bAutoCreate; // create new log targets on demand? | |
fd7718b2 | 218 | static bool ms_bVerbose; // FALSE => ignore LogInfo messages |
fe7b1156 | 219 | |
2ed3265e VZ |
220 | static size_t ms_suspendCount; // if positive, logs are not flushed |
221 | ||
d2e1ef19 VZ |
222 | // format string for strftime(), if NULL, time stamping log messages is |
223 | // disabled | |
224 | static const wxChar *ms_timestamp; | |
225 | ||
d6b9496a VZ |
226 | static wxTraceMask ms_ulTraceMask; // controls wxLogTrace behaviour |
227 | static wxArrayString ms_aTraceMasks; // more powerful filter for wxLogTrace | |
c801d85f KB |
228 | }; |
229 | ||
230 | // ---------------------------------------------------------------------------- | |
231 | // "trivial" derivations of wxLog | |
232 | // ---------------------------------------------------------------------------- | |
233 | ||
234 | // log everything to a "FILE *", stderr by default | |
235 | class WXDLLEXPORT wxLogStderr : public wxLog | |
236 | { | |
237 | public: | |
d6b9496a VZ |
238 | // redirect log output to a FILE |
239 | wxLogStderr(FILE *fp = (FILE *) NULL); | |
c801d85f | 240 | |
03147cd0 | 241 | protected: |
d6b9496a | 242 | // implement sink function |
9e3d3318 | 243 | virtual void DoLogString(const wxChar *szString, time_t t); |
c801d85f | 244 | |
d6b9496a | 245 | FILE *m_fp; |
c801d85f KB |
246 | }; |
247 | ||
4bf78aae | 248 | #if wxUSE_STD_IOSTREAM |
03147cd0 | 249 | |
c801d85f KB |
250 | // log everything to an "ostream", cerr by default |
251 | class WXDLLEXPORT wxLogStream : public wxLog | |
252 | { | |
253 | public: | |
d6b9496a | 254 | // redirect log output to an ostream |
dd107c50 | 255 | wxLogStream(wxSTD ostream *ostr = (wxSTD ostream *) NULL); |
c801d85f KB |
256 | |
257 | protected: | |
d6b9496a | 258 | // implement sink function |
9e3d3318 | 259 | virtual void DoLogString(const wxChar *szString, time_t t); |
c801d85f | 260 | |
d6b9496a | 261 | // using ptr here to avoid including <iostream.h> from this file |
dd107c50 | 262 | wxSTD ostream *m_ostr; |
c801d85f | 263 | }; |
03147cd0 VZ |
264 | |
265 | #endif // wxUSE_STD_IOSTREAM | |
c801d85f | 266 | |
03147cd0 VZ |
267 | // ---------------------------------------------------------------------------- |
268 | // /dev/null log target: suppress logging until this object goes out of scope | |
269 | // ---------------------------------------------------------------------------- | |
270 | ||
271 | // example of usage: | |
272 | /* | |
273 | void Foo() | |
274 | { | |
275 | wxFile file; | |
276 | ||
277 | // wxFile.Open() normally complains if file can't be opened, we don't | |
278 | // want it | |
279 | wxLogNull logNo; | |
280 | ||
281 | if ( !file.Open("bar") ) | |
282 | ... process error ourselves ... | |
283 | ||
284 | // ~wxLogNull called, old log sink restored | |
285 | } | |
286 | */ | |
287 | class WXDLLEXPORT wxLogNull | |
288 | { | |
289 | public: | |
290 | wxLogNull() { m_flagOld = wxLog::EnableLogging(FALSE); } | |
291 | ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld); } | |
292 | ||
293 | private: | |
294 | bool m_flagOld; // the previous value of the wxLog::ms_doLog | |
295 | }; | |
296 | ||
297 | // ---------------------------------------------------------------------------- | |
298 | // chaining log target: installs itself as a log target and passes all | |
299 | // messages to the real log target given to it in the ctor but also forwards | |
300 | // them to the previously active one | |
301 | // | |
302 | // note that you don't have to call SetActiveTarget() with this class, it | |
303 | // does it itself in its ctor | |
304 | // ---------------------------------------------------------------------------- | |
305 | ||
306 | class WXDLLEXPORT wxLogChain : public wxLog | |
307 | { | |
308 | public: | |
309 | wxLogChain(wxLog *logger); | |
310 | virtual ~wxLogChain() { delete m_logOld; } | |
311 | ||
312 | // change the new log target | |
313 | void SetLog(wxLog *logger); | |
314 | ||
315 | // this can be used to temporarily disable (and then reenable) passing | |
316 | // messages to the old logger (by default we do pass them) | |
317 | void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; } | |
318 | ||
319 | // are we passing the messages to the previous log target? | |
320 | bool IsPassingMessages() const { return m_bPassMessages; } | |
321 | ||
322 | // return the previous log target (may be NULL) | |
323 | wxLog *GetOldLog() const { return m_logOld; } | |
324 | ||
325 | // override base class version to flush the old logger as well | |
326 | virtual void Flush(); | |
327 | ||
328 | protected: | |
329 | // pass the chain to the old logger if needed | |
330 | virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t); | |
331 | ||
332 | private: | |
333 | // the current log target | |
334 | wxLog *m_logNew; | |
335 | ||
336 | // the previous log target | |
337 | wxLog *m_logOld; | |
338 | ||
339 | // do we pass the messages to the old logger? | |
340 | bool m_bPassMessages; | |
341 | }; | |
342 | ||
343 | // a chain log target which uses itself as the new logger | |
344 | class WXDLLEXPORT wxLogPassThrough : public wxLogChain | |
345 | { | |
346 | public: | |
93d4c1d0 | 347 | wxLogPassThrough(); |
03147cd0 VZ |
348 | }; |
349 | ||
8ca28fb7 VZ |
350 | // ---------------------------------------------------------------------------- |
351 | // the following log targets are only compiled in if the we're compiling the | |
352 | // GUI part (andnot just the base one) of the library, they're implemented in | |
353 | // src/generic/logg.cpp *and not src/common/log.cpp unlike all the rest) | |
354 | // ---------------------------------------------------------------------------- | |
355 | ||
356 | #if wxUSE_GUI | |
357 | ||
358 | #if wxUSE_TEXTCTRL | |
359 | ||
360 | // log everything to a text window (GUI only of course) | |
361 | class WXDLLEXPORT wxLogTextCtrl : public wxLog | |
362 | { | |
363 | public: | |
364 | wxLogTextCtrl(wxTextCtrl *pTextCtrl); | |
365 | ||
366 | private: | |
367 | // implement sink function | |
368 | virtual void DoLogString(const wxChar *szString, time_t t); | |
369 | ||
370 | // the control we use | |
371 | wxTextCtrl *m_pTextCtrl; | |
372 | }; | |
373 | ||
374 | #endif // wxUSE_TEXTCTRL | |
375 | ||
c801d85f KB |
376 | // ---------------------------------------------------------------------------- |
377 | // GUI log target, the default one for wxWindows programs | |
378 | // ---------------------------------------------------------------------------- | |
1e6feb95 VZ |
379 | |
380 | #if wxUSE_LOGGUI | |
381 | ||
c801d85f KB |
382 | class WXDLLEXPORT wxLogGui : public wxLog |
383 | { | |
384 | public: | |
d6b9496a VZ |
385 | // ctor |
386 | wxLogGui(); | |
c801d85f | 387 | |
d6b9496a VZ |
388 | // show all messages that were logged since the last Flush() |
389 | virtual void Flush(); | |
c801d85f KB |
390 | |
391 | protected: | |
9e3d3318 | 392 | virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t); |
d6b9496a VZ |
393 | |
394 | // empty everything | |
395 | void Clear(); | |
c801d85f | 396 | |
f1df0927 VZ |
397 | wxArrayString m_aMessages; // the log message texts |
398 | wxArrayInt m_aSeverity; // one of wxLOG_XXX values | |
399 | wxArrayLong m_aTimes; // the time of each message | |
d6b9496a VZ |
400 | bool m_bErrors, // do we have any errors? |
401 | m_bWarnings; // any warnings? | |
c801d85f KB |
402 | }; |
403 | ||
1e6feb95 VZ |
404 | #endif // wxUSE_LOGGUI |
405 | ||
9ef3052c VZ |
406 | // ---------------------------------------------------------------------------- |
407 | // (background) log window: this class forwards all log messages to the log | |
408 | // target which was active when it was instantiated, but also collects them | |
409 | // to the log window. This window has it's own menu which allows the user to | |
410 | // close it, clear the log contents or save it to the file. | |
411 | // ---------------------------------------------------------------------------- | |
1e6feb95 VZ |
412 | |
413 | #if wxUSE_LOGWINDOW | |
414 | ||
03147cd0 | 415 | class WXDLLEXPORT wxLogWindow : public wxLogPassThrough |
9ef3052c VZ |
416 | { |
417 | public: | |
d6b9496a | 418 | wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL) |
03147cd0 VZ |
419 | const wxChar *szTitle, // the title of the frame |
420 | bool bShow = TRUE, // show window immediately? | |
421 | bool bPassToOld = TRUE); // pass messages to the old target? | |
422 | ||
d6b9496a | 423 | ~wxLogWindow(); |
06db8ebd | 424 | |
d6b9496a | 425 | // window operations |
f6bcfd97 | 426 | // show/hide the log window |
d6b9496a | 427 | void Show(bool bShow = TRUE); |
f6bcfd97 | 428 | // retrieve the pointer to the frame |
d6b9496a | 429 | wxFrame *GetFrame() const; |
9ef3052c | 430 | |
d6b9496a | 431 | // overridables |
f6bcfd97 BP |
432 | // called immediately after the log frame creation allowing for |
433 | // any extra initializations | |
d6b9496a | 434 | virtual void OnFrameCreate(wxFrame *frame); |
f6bcfd97 BP |
435 | // called if the user closes the window interactively, will not be |
436 | // called if it is destroyed for another reason (such as when program | |
437 | // exits) - return TRUE from here to allow the frame to close, FALSE | |
438 | // to prevent this from happening | |
439 | virtual bool OnFrameClose(wxFrame *frame); | |
440 | // called right before the log frame is going to be deleted: will | |
441 | // always be called unlike OnFrameClose() | |
d6b9496a | 442 | virtual void OnFrameDelete(wxFrame *frame); |
fe7b1156 | 443 | |
9ef3052c | 444 | protected: |
9e3d3318 OK |
445 | virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t); |
446 | virtual void DoLogString(const wxChar *szString, time_t t); | |
06db8ebd | 447 | |
9ef3052c | 448 | private: |
d6b9496a | 449 | wxLogFrame *m_pLogFrame; // the log frame |
9ef3052c VZ |
450 | }; |
451 | ||
1e6feb95 VZ |
452 | #endif // wxUSE_LOGWINDOW |
453 | ||
e90c1d2a | 454 | #endif // wxUSE_GUI |
03f38c58 | 455 | |
c801d85f KB |
456 | // ============================================================================ |
457 | // global functions | |
458 | // ============================================================================ | |
459 | ||
460 | // ---------------------------------------------------------------------------- | |
461 | // Log functions should be used by application instead of stdio, iostream &c | |
462 | // for log messages for easy redirection | |
463 | // ---------------------------------------------------------------------------- | |
464 | ||
88ac883a VZ |
465 | // ---------------------------------------------------------------------------- |
466 | // get error code/error message from system in a portable way | |
467 | // ---------------------------------------------------------------------------- | |
468 | ||
469 | // return the last system error code | |
470 | WXDLLEXPORT unsigned long wxSysErrorCode(); | |
471 | // return the error message for given (or last if 0) error code | |
472 | WXDLLEXPORT const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0); | |
473 | ||
c801d85f KB |
474 | // define wxLog<level> |
475 | // ------------------- | |
476 | ||
c801d85f | 477 | #define DECLARE_LOG_FUNCTION(level) \ |
1d63fd6b | 478 | extern void WXDLLEXPORT wxVLog##level(const wxChar *szFormat, \ |
ea44a631 | 479 | va_list argptr); \ |
9e3d3318 | 480 | extern void WXDLLEXPORT wxLog##level(const wxChar *szFormat, ...) |
a1530845 | 481 | #define DECLARE_LOG_FUNCTION2(level, arg1) \ |
1d63fd6b | 482 | extern void WXDLLEXPORT wxVLog##level(arg1, const wxChar *szFormat, \ |
ea44a631 | 483 | va_list argptr); \ |
9e3d3318 | 484 | extern void WXDLLEXPORT wxLog##level(arg1, const wxChar *szFormat, ...) |
a1530845 | 485 | |
88ac883a VZ |
486 | #else // !wxUSE_LOG |
487 | ||
488 | // log functions do nothing at all | |
489 | #define DECLARE_LOG_FUNCTION(level) \ | |
1d63fd6b | 490 | inline void WXDLLEXPORT wxVLog##level(const wxChar *szFormat, \ |
ea44a631 | 491 | va_list argptr) {} \ |
546db2a8 | 492 | inline void WXDLLEXPORT wxLog##level(const wxChar *szFormat, ...) {} |
88ac883a | 493 | #define DECLARE_LOG_FUNCTION2(level, arg1) \ |
1d63fd6b | 494 | inline void WXDLLEXPORT wxVLog##level(arg1, const wxChar *szFormat, \ |
ea44a631 | 495 | va_list argptr) {} \ |
546db2a8 | 496 | inline void WXDLLEXPORT wxLog##level(arg1, const wxChar *szFormat, ...) {} |
88ac883a VZ |
497 | |
498 | #endif // wxUSE_LOG/!wxUSE_LOG | |
c801d85f | 499 | |
88ac883a VZ |
500 | // a generic function for all levels (level is passes as parameter) |
501 | DECLARE_LOG_FUNCTION2(Generic, wxLogLevel level); | |
c801d85f | 502 | |
88ac883a VZ |
503 | // one function per each level |
504 | DECLARE_LOG_FUNCTION(FatalError); | |
505 | DECLARE_LOG_FUNCTION(Error); | |
506 | DECLARE_LOG_FUNCTION(Warning); | |
507 | DECLARE_LOG_FUNCTION(Message); | |
508 | DECLARE_LOG_FUNCTION(Info); | |
509 | DECLARE_LOG_FUNCTION(Verbose); | |
470b7da3 | 510 | |
88ac883a VZ |
511 | // this function sends the log message to the status line of the top level |
512 | // application frame, if any | |
513 | DECLARE_LOG_FUNCTION(Status); | |
470b7da3 | 514 | |
88ac883a VZ |
515 | // this one is the same as previous except that it allows to explicitly |
516 | // specify the frame to which the output should go | |
517 | DECLARE_LOG_FUNCTION2(Status, wxFrame *pFrame); | |
c801d85f | 518 | |
88ac883a VZ |
519 | // additional one: as wxLogError, but also logs last system call error code |
520 | // and the corresponding error message if available | |
521 | DECLARE_LOG_FUNCTION(SysError); | |
c801d85f | 522 | |
88ac883a VZ |
523 | // and another one which also takes the error code (for those broken APIs |
524 | // that don't set the errno (like registry APIs in Win32)) | |
525 | DECLARE_LOG_FUNCTION2(SysError, long lErrCode); | |
526 | ||
527 | // debug functions do nothing in release mode | |
b2aef89b | 528 | #ifdef __WXDEBUG__ |
d6b9496a VZ |
529 | DECLARE_LOG_FUNCTION(Debug); |
530 | ||
ea44a631 | 531 | // first kind of LogTrace is unconditional: it doesn't check the level, |
d6b9496a VZ |
532 | DECLARE_LOG_FUNCTION(Trace); |
533 | ||
534 | // this second version will only log the message if the mask had been | |
535 | // added to the list of masks with AddTraceMask() | |
f6bcfd97 | 536 | DECLARE_LOG_FUNCTION2(Trace, const wxChar *mask); |
9ef3052c | 537 | |
d6b9496a VZ |
538 | // the last one does nothing if all of level bits are not set |
539 | // in wxLog::GetActive()->GetTraceMask() - it's deprecated in favour of | |
540 | // string identifiers | |
541 | DECLARE_LOG_FUNCTION2(Trace, wxTraceMask mask); | |
9ef3052c | 542 | #else //!debug |
d6b9496a | 543 | // these functions do nothing in release builds |
1d63fd6b | 544 | inline void wxVLogDebug(const wxChar *, va_list) { } |
9e3d3318 | 545 | inline void wxLogDebug(const wxChar *, ...) { } |
1d63fd6b | 546 | inline void wxVLogTrace(const wxChar *, va_list) { } |
9e3d3318 | 547 | inline void wxLogTrace(const wxChar *, ...) { } |
1d63fd6b | 548 | inline void wxVLogTrace(wxTraceMask, const wxChar *, va_list) { } |
9e3d3318 | 549 | inline void wxLogTrace(wxTraceMask, const wxChar *, ...) { } |
1d63fd6b | 550 | inline void wxVLogTrace(const wxChar *, const wxChar *, va_list) { } |
9e3d3318 | 551 | inline void wxLogTrace(const wxChar *, const wxChar *, ...) { } |
88ac883a | 552 | #endif // debug/!debug |
c801d85f | 553 | |
88ac883a VZ |
554 | // ---------------------------------------------------------------------------- |
555 | // debug only logging functions: use them with API name and error code | |
556 | // ---------------------------------------------------------------------------- | |
c801d85f | 557 | |
e90babdf | 558 | #ifdef __WXDEBUG__ |
42e69d6b VZ |
559 | // make life easier for people using VC++ IDE: clicking on the message |
560 | // will take us immediately to the place of the failed API | |
561 | #ifdef __VISUALC__ | |
4b7f2165 VZ |
562 | #define wxLogApiError(api, rc) \ |
563 | wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \ | |
f6bcfd97 | 564 | __TFILE__, __LINE__, api, \ |
42e69d6b VZ |
565 | rc, wxSysErrorMsg(rc)) |
566 | #else // !VC++ | |
4b7f2165 VZ |
567 | #define wxLogApiError(api, rc) \ |
568 | wxLogDebug(wxT("In file %s at line %d: '%s' failed with " \ | |
569 | "error 0x%08lx (%s)."), \ | |
f6bcfd97 | 570 | __TFILE__, __LINE__, api, \ |
42e69d6b VZ |
571 | rc, wxSysErrorMsg(rc)) |
572 | #endif // VC++/!VC++ | |
573 | ||
574 | #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode()) | |
575 | ||
c801d85f | 576 | #else //!debug |
9e3d3318 OK |
577 | inline void wxLogApiError(const wxChar *, long) { } |
578 | inline void wxLogLastError(const wxChar *) { } | |
c801d85f KB |
579 | #endif //debug/!debug |
580 | ||
34138703 | 581 | #endif // _WX_LOG_H_ |