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