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