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