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