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