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