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