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