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