]> git.saurik.com Git - wxWidgets.git/blob - include/wx/log.h
makefiels updated to reflect removal of db sample
[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 #include "wx/thread.h"
18
19 // ----------------------------------------------------------------------------
20 // common constants for use in wxUSE_LOG/!wxUSE_LOG
21 // ----------------------------------------------------------------------------
22
23 // the trace masks have been superceded by symbolic trace constants, they're
24 // for compatibility only andwill be removed soon - do NOT use them
25
26 // meaning of different bits of the trace mask (which allows selectively
27 // enable/disable some trace messages)
28 #define wxTraceMemAlloc 0x0001 // trace memory allocation (new/delete)
29 #define wxTraceMessages 0x0002 // trace window messages/X callbacks
30 #define wxTraceResAlloc 0x0004 // trace GDI resource allocation
31 #define wxTraceRefCount 0x0008 // trace various ref counting operations
32
33 #ifdef __WXMSW__
34 #define wxTraceOleCalls 0x0100 // OLE interface calls
35 #endif
36
37 // ----------------------------------------------------------------------------
38 // types
39 // ----------------------------------------------------------------------------
40
41 // NB: these types are needed even if wxUSE_LOG == 0
42 typedef unsigned long wxTraceMask;
43 typedef unsigned long wxLogLevel;
44
45 // ----------------------------------------------------------------------------
46 // headers
47 // ----------------------------------------------------------------------------
48
49 #include "wx/string.h"
50 #include "wx/strvararg.h"
51
52 #if wxUSE_LOG
53
54 #include "wx/arrstr.h"
55
56 #ifndef __WXWINCE__
57 #include <time.h> // for time_t
58 #endif
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 { ms_aTraceMasks.push_back(str); }
203
204 // add string trace mask
205 static void RemoveTraceMask(const wxString& str);
206
207 // remove all string trace masks
208 static void ClearTraceMasks();
209
210 // get string trace masks
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; only does something if ms_prevCounter > 0
308 static void LogLastRepetitionCountIfNeeded();
309
310 private:
311 // static variables
312 // ----------------
313
314 // if true, don't log the same message multiple times, only log it once
315 // with the number of times it was repeated
316 static bool ms_bRepetCounting;
317
318 wxCRIT_SECT_DECLARE(ms_prevCS); // protects the ms_prev values below
319 static wxString ms_prevString; // previous message that was logged
320 static unsigned ms_prevCounter; // how many times it was repeated
321 static time_t ms_prevTimeStamp;// timestamp of the previous message
322 static wxLogLevel ms_prevLevel; // level of the previous message
323
324 static wxLog *ms_pLogger; // currently active log sink
325 static bool ms_doLog; // false => all logging disabled
326 static bool ms_bAutoCreate; // create new log targets on demand?
327 static bool ms_bVerbose; // false => ignore LogInfo messages
328
329 static wxLogLevel ms_logLevel; // limit logging to levels <= ms_logLevel
330
331 static size_t ms_suspendCount; // if positive, logs are not flushed
332
333 // format string for strftime(), if NULL, time stamping log messages is
334 // disabled
335 static wxString ms_timestamp;
336
337 static wxTraceMask ms_ulTraceMask; // controls wxLogTrace behaviour
338 static wxArrayString ms_aTraceMasks; // more powerful filter for wxLogTrace
339 };
340
341 // ----------------------------------------------------------------------------
342 // "trivial" derivations of wxLog
343 // ----------------------------------------------------------------------------
344
345 // log everything to a buffer
346 class WXDLLIMPEXP_BASE wxLogBuffer : public wxLog
347 {
348 public:
349 wxLogBuffer() { }
350
351 // get the string contents with all messages logged
352 const wxString& GetBuffer() const { return m_str; }
353
354 // show the buffer contents to the user in the best possible way (this uses
355 // wxMessageOutputMessageBox) and clear it
356 virtual void Flush();
357
358 protected:
359 virtual void DoLog(wxLogLevel level, const wxString& szString, time_t t);
360 virtual void DoLogString(const wxString& szString, time_t t);
361
362 wxSUPPRESS_DOLOG_HIDE_WARNING()
363 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
364
365 private:
366 wxString m_str;
367
368 DECLARE_NO_COPY_CLASS(wxLogBuffer)
369 };
370
371
372 // log everything to a "FILE *", stderr by default
373 class WXDLLIMPEXP_BASE wxLogStderr : public wxLog
374 {
375 public:
376 // redirect log output to a FILE
377 wxLogStderr(FILE *fp = (FILE *) NULL);
378
379 protected:
380 // implement sink function
381 virtual void DoLogString(const wxString& szString, time_t t);
382
383 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
384
385 FILE *m_fp;
386
387 DECLARE_NO_COPY_CLASS(wxLogStderr)
388 };
389
390 #if wxUSE_STD_IOSTREAM
391
392 // log everything to an "ostream", cerr by default
393 class WXDLLIMPEXP_BASE wxLogStream : public wxLog
394 {
395 public:
396 // redirect log output to an ostream
397 wxLogStream(wxSTD ostream *ostr = (wxSTD ostream *) NULL);
398
399 protected:
400 // implement sink function
401 virtual void DoLogString(const wxString& szString, time_t t);
402
403 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
404
405 // using ptr here to avoid including <iostream.h> from this file
406 wxSTD ostream *m_ostr;
407 };
408
409 #endif // wxUSE_STD_IOSTREAM
410
411 // ----------------------------------------------------------------------------
412 // /dev/null log target: suppress logging until this object goes out of scope
413 // ----------------------------------------------------------------------------
414
415 // example of usage:
416 /*
417 void Foo()
418 {
419 wxFile file;
420
421 // wxFile.Open() normally complains if file can't be opened, we don't
422 // want it
423 wxLogNull logNo;
424
425 if ( !file.Open("bar") )
426 ... process error ourselves ...
427
428 // ~wxLogNull called, old log sink restored
429 }
430 */
431 class WXDLLIMPEXP_BASE wxLogNull
432 {
433 public:
434 wxLogNull() : m_flagOld(wxLog::EnableLogging(false)) { }
435 ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld); }
436
437 private:
438 bool m_flagOld; // the previous value of the wxLog::ms_doLog
439 };
440
441 // ----------------------------------------------------------------------------
442 // chaining log target: installs itself as a log target and passes all
443 // messages to the real log target given to it in the ctor but also forwards
444 // them to the previously active one
445 //
446 // note that you don't have to call SetActiveTarget() with this class, it
447 // does it itself in its ctor
448 // ----------------------------------------------------------------------------
449
450 class WXDLLIMPEXP_BASE wxLogChain : public wxLog
451 {
452 public:
453 wxLogChain(wxLog *logger);
454 virtual ~wxLogChain();
455
456 // change the new log target
457 void SetLog(wxLog *logger);
458
459 // this can be used to temporarily disable (and then reenable) passing
460 // messages to the old logger (by default we do pass them)
461 void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; }
462
463 // are we passing the messages to the previous log target?
464 bool IsPassingMessages() const { return m_bPassMessages; }
465
466 // return the previous log target (may be NULL)
467 wxLog *GetOldLog() const { return m_logOld; }
468
469 // override base class version to flush the old logger as well
470 virtual void Flush();
471
472 // call to avoid destroying the old log target
473 void DetachOldLog() { m_logOld = NULL; }
474
475 protected:
476 // pass the chain to the old logger if needed
477 virtual void DoLog(wxLogLevel level, const wxString& szString, time_t t);
478
479 wxSUPPRESS_DOLOG_HIDE_WARNING()
480
481 private:
482 // the current log target
483 wxLog *m_logNew;
484
485 // the previous log target
486 wxLog *m_logOld;
487
488 // do we pass the messages to the old logger?
489 bool m_bPassMessages;
490
491 DECLARE_NO_COPY_CLASS(wxLogChain)
492 };
493
494 // a chain log target which uses itself as the new logger
495
496 #define wxLogPassThrough wxLogInterposer
497
498 class WXDLLIMPEXP_BASE wxLogInterposer : public wxLogChain
499 {
500 public:
501 wxLogInterposer();
502
503 private:
504 DECLARE_NO_COPY_CLASS(wxLogInterposer)
505 };
506
507 // a temporary interposer which doesn't destroy the old log target
508 // (calls DetachOldLog)
509
510 class WXDLLIMPEXP_BASE wxLogInterposerTemp : public wxLogChain
511 {
512 public:
513 wxLogInterposerTemp();
514
515 private:
516 DECLARE_NO_COPY_CLASS(wxLogInterposerTemp)
517 };
518
519 #if wxUSE_GUI
520 // include GUI log targets:
521 #include "wx/generic/logg.h"
522 #endif // wxUSE_GUI
523
524 // ============================================================================
525 // global functions
526 // ============================================================================
527
528 // ----------------------------------------------------------------------------
529 // Log functions should be used by application instead of stdio, iostream &c
530 // for log messages for easy redirection
531 // ----------------------------------------------------------------------------
532
533 // ----------------------------------------------------------------------------
534 // get error code/error message from system in a portable way
535 // ----------------------------------------------------------------------------
536
537 // return the last system error code
538 WXDLLIMPEXP_BASE unsigned long wxSysErrorCode();
539
540 // return the error message for given (or last if 0) error code
541 WXDLLIMPEXP_BASE const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0);
542
543 // ----------------------------------------------------------------------------
544 // define wxLog<level>
545 // ----------------------------------------------------------------------------
546
547 #define DECLARE_LOG_FUNCTION(level) \
548 extern void WXDLLIMPEXP_BASE \
549 wxDoLog##level##Wchar(const wxChar *format, ...); \
550 extern void WXDLLIMPEXP_BASE \
551 wxDoLog##level##Utf8(const char *format, ...); \
552 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
553 1, (const wxFormatString&), \
554 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
555 DECLARE_LOG_FUNCTION_WATCOM(level) \
556 extern void WXDLLIMPEXP_BASE wxVLog##level(const wxString& format, \
557 va_list argptr)
558
559 #ifdef __WATCOMC__
560 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
561 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
562 // something too big for Borland C++ to handle
563 #define DECLARE_LOG_FUNCTION_WATCOM(level) \
564 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
565 1, (const wxString&), \
566 (wxFormatString(f1))) \
567 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
568 1, (const wxCStrData&), \
569 (wxFormatString(f1))) \
570 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
571 1, (const char*), \
572 (wxFormatString(f1))) \
573 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
574 1, (const wchar_t*), \
575 (wxFormatString(f1)))
576 #else
577 #define DECLARE_LOG_FUNCTION_WATCOM(level)
578 #endif
579
580
581 #define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
582 extern void expdecl wxDoLog##level##Wchar(argclass arg, \
583 const wxChar *format, ...); \
584 extern void expdecl wxDoLog##level##Utf8(argclass arg, \
585 const char *format, ...); \
586 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
587 2, (argclass, const wxFormatString&), \
588 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
589 DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
590 extern void expdecl wxVLog##level(argclass arg, \
591 const wxString& format, \
592 va_list argptr)
593
594 #ifdef __WATCOMC__
595 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
596 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
597 // something too big for Borland C++ to handle
598 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
599 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
600 2, (argclass, const wxString&), \
601 (f1, wxFormatString(f2))) \
602 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
603 2, (argclass, const wxCStrData&), \
604 (f1, wxFormatString(f2))) \
605 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
606 2, (argclass, const char*), \
607 (f1, wxFormatString(f2))) \
608 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
609 2, (argclass, const wchar_t*), \
610 (f1, wxFormatString(f2)))
611 #else
612 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl)
613 #endif
614
615
616 #else // !wxUSE_LOG
617
618 #ifdef __WATCOMC__
619 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
620 #define WX_WATCOM_ONLY_CODE( x ) x
621 #else
622 #define WX_WATCOM_ONLY_CODE( x )
623 #endif
624
625 #if defined(__WATCOMC__) || defined(__MINGW32__)
626 // Mingw has similar problem with wxLogSysError:
627 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x ) x
628 #else
629 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x )
630 #endif
631
632 // log functions do nothing at all
633 #define DECLARE_LOG_FUNCTION(level) \
634 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxString&)) \
635 WX_WATCOM_ONLY_CODE( \
636 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const char*)) \
637 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wchar_t*)) \
638 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxCStrData&)) \
639 ) \
640 inline void wxVLog##level(const wxString& WXUNUSED(format), \
641 va_list WXUNUSED(argptr)) { } \
642
643 #define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
644 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxString&)) \
645 WX_WATCOM_OR_MINGW_ONLY_CODE( \
646 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const char*)) \
647 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wchar_t*)) \
648 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxCStrData&)) \
649 ) \
650 inline void wxVLog##level(argclass WXUNUSED(arg), \
651 const wxString& WXUNUSED(format), \
652 va_list WXUNUSED(argptr)) {}
653
654 // Empty Class to fake wxLogNull
655 class WXDLLIMPEXP_BASE wxLogNull
656 {
657 public:
658 wxLogNull() { }
659 };
660
661 // Dummy macros to replace some functions.
662 #define wxSysErrorCode() (unsigned long)0
663 #define wxSysErrorMsg( X ) (const wxChar*)NULL
664
665 // Fake symbolic trace masks... for those that are used frequently
666 #define wxTRACE_OleCalls wxEmptyString // OLE interface calls
667
668 #endif // wxUSE_LOG/!wxUSE_LOG
669
670 #define DECLARE_LOG_FUNCTION2(level, argclass, arg) \
671 DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, WXDLLIMPEXP_BASE)
672
673 // VC6 produces a warning if we a macro expanding to nothing to
674 // DECLARE_LOG_FUNCTION2:
675 #if defined(__VISUALC__) && __VISUALC__ < 1300
676 // "not enough actual parameters for macro 'DECLARE_LOG_FUNCTION2_EXP'"
677 #pragma warning(disable:4003)
678 #endif
679
680 // a generic function for all levels (level is passes as parameter)
681 DECLARE_LOG_FUNCTION2(Generic, wxLogLevel, level);
682
683 // one function per each level
684 DECLARE_LOG_FUNCTION(FatalError);
685 DECLARE_LOG_FUNCTION(Error);
686 DECLARE_LOG_FUNCTION(Warning);
687 DECLARE_LOG_FUNCTION(Message);
688 DECLARE_LOG_FUNCTION(Info);
689 DECLARE_LOG_FUNCTION(Verbose);
690
691 // this function sends the log message to the status line of the top level
692 // application frame, if any
693 DECLARE_LOG_FUNCTION(Status);
694
695 #if wxUSE_GUI
696 // this one is the same as previous except that it allows to explicitly
697 class WXDLLIMPEXP_FWD_CORE wxFrame;
698 // specify the frame to which the output should go
699 DECLARE_LOG_FUNCTION2_EXP(Status, wxFrame *, pFrame, WXDLLIMPEXP_CORE);
700 #endif // wxUSE_GUI
701
702 // additional one: as wxLogError, but also logs last system call error code
703 // and the corresponding error message if available
704 DECLARE_LOG_FUNCTION(SysError);
705
706 // and another one which also takes the error code (for those broken APIs
707 // that don't set the errno (like registry APIs in Win32))
708 DECLARE_LOG_FUNCTION2(SysError, long, lErrCode);
709 #ifdef __WATCOMC__
710 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
711 DECLARE_LOG_FUNCTION2(SysError, unsigned long, lErrCode);
712 #endif
713
714 // debug functions do nothing in release mode
715 #if wxUSE_LOG && wxUSE_LOG_DEBUG
716 DECLARE_LOG_FUNCTION(Debug);
717
718 // there is no more unconditional LogTrace: it is not different from
719 // LogDebug and it creates overload ambiguities
720 //DECLARE_LOG_FUNCTION(Trace);
721
722 // this version only logs the message if the mask had been added to the
723 // list of masks with AddTraceMask()
724 DECLARE_LOG_FUNCTION2(Trace, const wxString&, mask);
725 #ifdef __WATCOMC__
726 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
727 DECLARE_LOG_FUNCTION2(Trace, const char*, mask);
728 DECLARE_LOG_FUNCTION2(Trace, const wchar_t*, mask);
729 #endif
730
731 // and this one does nothing if all of level bits are not set in
732 // wxLog::GetActive()->GetTraceMask() -- it's deprecated in favour of
733 // string identifiers
734 DECLARE_LOG_FUNCTION2(Trace, wxTraceMask, mask);
735 #ifdef __WATCOMC__
736 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
737 DECLARE_LOG_FUNCTION2(Trace, int, mask);
738 #endif
739 #else //!debug || !wxUSE_LOG
740 // these functions do nothing in release builds, but don't define them as
741 // nothing as it could result in different code structure in debug and
742 // release and this could result in trouble when these macros are used
743 // inside if/else
744 //
745 // note that making wxVLogDebug/Trace() themselves (empty inline) functions
746 // is a bad idea as some compilers are stupid enough to not inline even
747 // empty functions if their parameters are complicated enough, but by
748 // defining them as an empty inline function we ensure that even dumbest
749 // compilers optimise them away
750 inline void wxLogNop() { }
751
752 #define wxVLogDebug(fmt, valist) wxLogNop()
753 #define wxVLogTrace(mask, fmt, valist) wxLogNop()
754
755 #ifdef HAVE_VARIADIC_MACROS
756 // unlike the inline functions below, this completely removes the
757 // wxLogXXX calls from the object file:
758 #define wxLogDebug(fmt, ...) wxLogNop()
759 #define wxLogTrace(mask, fmt, ...) wxLogNop()
760 #else // !HAVE_VARIADIC_MACROS
761 //inline void wxLogDebug(const wxString& fmt, ...) {}
762 WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug, 1, (const wxString&))
763 //inline void wxLogTrace(wxTraceMask, const wxString& fmt, ...) {}
764 //inline void wxLogTrace(const wxString&, const wxString& fmt, ...) {}
765 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (wxTraceMask, const wxString&))
766 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (const wxString&, const wxString&))
767 #ifdef __WATCOMC__
768 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
769 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (const char*, const char*))
770 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (const wchar_t*, const wchar_t*))
771 #endif
772 #endif // HAVE_VARIADIC_MACROS/!HAVE_VARIADIC_MACROS
773 #endif // debug/!debug
774
775 #if defined(__VISUALC__) && __VISUALC__ < 1300
776 #pragma warning(default:4003)
777 #endif
778
779 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
780 // i.e. without using wxMessageBox() for example because it could crash
781 void WXDLLIMPEXP_BASE
782 wxSafeShowMessage(const wxString& title, const wxString& text);
783
784 // ----------------------------------------------------------------------------
785 // debug only logging functions: use them with API name and error code
786 // ----------------------------------------------------------------------------
787
788 #ifdef __WXDEBUG__
789 // make life easier for people using VC++ IDE: clicking on the message
790 // will take us immediately to the place of the failed API
791 #ifdef __VISUALC__
792 #define wxLogApiError(api, rc) \
793 wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
794 __FILE__, __LINE__, api, \
795 (long)rc, wxSysErrorMsg(rc))
796 #else // !VC++
797 #define wxLogApiError(api, rc) \
798 wxLogDebug(wxT("In file %s at line %d: '%s' failed with ") \
799 wxT("error 0x%08lx (%s)."), \
800 __FILE__, __LINE__, api, \
801 (long)rc, wxSysErrorMsg(rc))
802 #endif // VC++/!VC++
803
804 #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
805
806 #else //!debug
807 #define wxLogApiError(api, err) wxLogNop()
808 #define wxLogLastError(api) wxLogNop()
809 #endif //debug/!debug
810
811 // wxCocoa has additiional trace masks
812 #if defined(__WXCOCOA__)
813 #include "wx/cocoa/log.h"
814 #endif
815
816 #ifdef WX_WATCOM_ONLY_CODE
817 #undef WX_WATCOM_ONLY_CODE
818 #endif
819
820 #endif // _WX_LOG_H_
821