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