1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Assorted wxLogXXX functions, and wxLog (sink for logs)
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 // NB: this is needed even if wxUSE_LOG == 0
22 typedef unsigned long wxLogLevel
;
24 // the trace masks have been superseded by symbolic trace constants, they're
25 // for compatibility only and will be removed soon - do NOT use them
26 #if WXWIN_COMPATIBILITY_2_8
27 #define wxTraceMemAlloc 0x0001 // trace memory allocation (new/delete)
28 #define wxTraceMessages 0x0002 // trace window messages/X callbacks
29 #define wxTraceResAlloc 0x0004 // trace GDI resource allocation
30 #define wxTraceRefCount 0x0008 // trace various ref counting operations
33 #define wxTraceOleCalls 0x0100 // OLE interface calls
36 typedef unsigned long wxTraceMask
;
37 #endif // WXWIN_COMPATIBILITY_2_8
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 #include "wx/string.h"
44 #include "wx/strvararg.h"
48 #include "wx/arrstr.h"
52 #include <time.h> // for time_t
54 #endif // ! __WXPALMOS5__
56 #include "wx/dynarray.h"
58 // wxUSE_LOG_DEBUG enables the debug log messages
59 #ifndef wxUSE_LOG_DEBUG
61 #define wxUSE_LOG_DEBUG 1
62 #else // !wxDEBUG_LEVEL
63 #define wxUSE_LOG_DEBUG 0
67 // wxUSE_LOG_TRACE enables the trace messages, they are disabled by default
68 #ifndef wxUSE_LOG_TRACE
70 #define wxUSE_LOG_TRACE 1
71 #else // !wxDEBUG_LEVEL
72 #define wxUSE_LOG_TRACE 0
74 #endif // wxUSE_LOG_TRACE
76 // ----------------------------------------------------------------------------
77 // forward declarations
78 // ----------------------------------------------------------------------------
81 class WXDLLIMPEXP_FWD_CORE wxFrame
;
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 // different standard log levels (you may also define your own)
91 wxLOG_FatalError
, // program can't continue, abort immediately
92 wxLOG_Error
, // a serious error, user must be informed about it
93 wxLOG_Warning
, // user is normally informed about it but may be ignored
94 wxLOG_Message
, // normal message (i.e. normal output of a non GUI app)
95 wxLOG_Status
, // informational: might go to the status line of GUI app
96 wxLOG_Info
, // informational message (a.k.a. 'Verbose')
97 wxLOG_Debug
, // never shown to the user, disabled in release mode
98 wxLOG_Trace
, // trace messages are also only enabled in debug mode
99 wxLOG_Progress
, // used for progress indicator (not yet)
100 wxLOG_User
= 100, // user defined levels start here
104 // symbolic trace masks - wxLogTrace("foo", "some trace message...") will be
105 // discarded unless the string "foo" has been added to the list of allowed
106 // ones with AddTraceMask()
108 #define wxTRACE_MemAlloc wxT("memalloc") // trace memory allocation (new/delete)
109 #define wxTRACE_Messages wxT("messages") // trace window messages/X callbacks
110 #define wxTRACE_ResAlloc wxT("resalloc") // trace GDI resource allocation
111 #define wxTRACE_RefCount wxT("refcount") // trace various ref counting operations
114 #define wxTRACE_OleCalls wxT("ole") // OLE interface calls
117 #include "wx/iosfwrap.h"
119 // ----------------------------------------------------------------------------
120 // derive from this class to redirect (or suppress, or ...) log messages
121 // normally, only a single instance of this class exists but it's not enforced
122 // ----------------------------------------------------------------------------
124 class WXDLLIMPEXP_BASE wxLog
130 // these functions allow to completely disable all log messages
132 // is logging disabled now?
133 static bool IsEnabled() { return ms_doLog
; }
135 // change the flag state, return the previous one
136 static bool EnableLogging(bool doIt
= true)
137 { bool doLogOld
= ms_doLog
; ms_doLog
= doIt
; return doLogOld
; }
139 // static sink function - see DoLog() for function to overload in the
141 static void OnLog(wxLogLevel level
, const wxString
& szString
, time_t t
);
145 // flush shows all messages if they're not logged immediately (FILE
146 // and iostream logs don't need it, but wxGuiLog does to avoid showing
147 // 17 modal dialogs one after another)
148 virtual void Flush();
150 // flush the active target if any
151 static void FlushActive()
153 if ( !ms_suspendCount
)
155 wxLog
*log
= GetActiveTarget();
161 // only one sink is active at each moment
162 // get current log target, will call wxApp::CreateLogTarget() to
163 // create one if none exists
164 static wxLog
*GetActiveTarget();
166 // change log target, pLogger may be NULL
167 static wxLog
*SetActiveTarget(wxLog
*pLogger
);
169 // suspend the message flushing of the main target until the next call
170 // to Resume() - this is mainly for internal use (to prevent wxYield()
171 // from flashing the messages)
172 static void Suspend() { ms_suspendCount
++; }
174 // must be called for each Suspend()!
175 static void Resume() { ms_suspendCount
--; }
177 // functions controlling the default wxLog behaviour
178 // verbose mode is activated by standard command-line '-verbose'
180 static void SetVerbose(bool bVerbose
= true) { ms_bVerbose
= bVerbose
; }
182 // Set log level. Log messages with level > logLevel will not be logged.
183 static void SetLogLevel(wxLogLevel logLevel
) { ms_logLevel
= logLevel
; }
185 // should GetActiveTarget() try to create a new log object if the
187 static void DontCreateOnDemand();
189 // Make GetActiveTarget() create a new log object again.
190 static void DoCreateOnDemand();
192 // log the count of repeating messages instead of logging the messages
194 static void SetRepetitionCounting(bool bRepetCounting
= true)
195 { ms_bRepetCounting
= bRepetCounting
; }
197 // gets duplicate counting status
198 static bool GetRepetitionCounting() { return ms_bRepetCounting
; }
200 // add string trace mask
201 static void AddTraceMask(const wxString
& str
);
203 // add string trace mask
204 static void RemoveTraceMask(const wxString
& str
);
206 // remove all string trace masks
207 static void ClearTraceMasks();
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
; }
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
; }
218 // disable time stamping of log messages
219 static void DisableTimestamp() { SetTimestamp(wxEmptyString
); }
224 // gets the verbose status
225 static bool GetVerbose() { return ms_bVerbose
; }
227 // is this trace mask in the list?
228 static bool IsAllowedTraceMask(const wxString
& mask
);
230 // return the current loglevel limit
231 static wxLogLevel
GetLogLevel() { return ms_logLevel
; }
233 // get the current timestamp format string (may be NULL)
234 static const wxString
& GetTimestamp() { return ms_timestamp
; }
239 // put the time stamp into the string if ms_timestamp != NULL (don't
240 // change it otherwise)
241 static void TimeStamp(wxString
*str
);
243 // this method should only be called from derived classes DoLog()
244 // implementations and shouldn't be called directly, use logging functions
246 void Log(wxLogLevel level
, const wxString
& msg
, time_t t
)
248 DoLog(level
, msg
, t
);
251 // make dtor virtual for all derived classes
255 // this method exists for backwards compatibility only, don't use
256 bool HasPendingMessages() const { return true; }
258 #if WXWIN_COMPATIBILITY_2_6
259 // this function doesn't do anything any more, don't call it
260 wxDEPRECATED( static wxChar
*SetLogBuffer(wxChar
*buf
, size_t size
= 0) );
263 // don't use integer masks any more, use string trace masks instead
264 #if WXWIN_COMPATIBILITY_2_8
265 wxDEPRECATED_INLINE( static void SetTraceMask(wxTraceMask ulMask
),
266 ms_ulTraceMask
= ulMask
; )
267 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE( static wxTraceMask
GetTraceMask(),
268 return ms_ulTraceMask
; )
269 #endif // WXWIN_COMPATIBILITY_2_8
272 // the logging functions that can be overridden
274 // default DoLog() prepends the time stamp and a prefix corresponding
275 // to the message to szString and then passes it to DoLogString()
276 virtual void DoLog(wxLogLevel level
, const wxString
& szString
, time_t t
);
277 #if WXWIN_COMPATIBILITY_2_8
278 // these shouldn't be used by new code
279 wxDEPRECATED_BUT_USED_INTERNALLY(
280 virtual void DoLog(wxLogLevel level
, const char *szString
, time_t t
)
283 wxDEPRECATED_BUT_USED_INTERNALLY(
284 virtual void DoLog(wxLogLevel level
, const wchar_t *wzString
, time_t t
)
286 #endif // WXWIN_COMPATIBILITY_2_8
288 void LogString(const wxString
& szString
, time_t t
)
289 { DoLogString(szString
, t
); }
291 // default DoLogString does nothing but is not pure virtual because if
292 // you override DoLog() you might not need it at all
293 virtual void DoLogString(const wxString
& szString
, time_t t
);
294 #if WXWIN_COMPATIBILITY_2_8
295 // these shouldn't be used by new code
296 virtual void DoLogString(const char *WXUNUSED(szString
),
297 time_t WXUNUSED(t
)) {}
298 virtual void DoLogString(const wchar_t *WXUNUSED(szString
),
299 time_t WXUNUSED(t
)) {}
300 #endif // WXWIN_COMPATIBILITY_2_8
302 // this macro should be used in the derived classes to avoid warnings about
303 // hiding the other DoLog() overloads when overriding DoLog(wxString) --
304 // but don't use it with MSVC which doesn't give this warning but does give
305 // warning when a deprecated function is overridden
306 #if WXWIN_COMPATIBILITY_2_8 && !defined(__VISUALC__)
307 #define wxSUPPRESS_DOLOG_HIDE_WARNING() \
308 virtual void DoLog(wxLogLevel, const char *, time_t) { } \
309 virtual void DoLog(wxLogLevel, const wchar_t *, time_t) { }
311 #define wxSUPPRESS_DOLOGSTRING_HIDE_WARNING() \
312 virtual void DoLogString(const char *, time_t) { } \
313 virtual void DoLogString(const wchar_t *, time_t) { }
315 #define wxSUPPRESS_DOLOG_HIDE_WARNING()
316 #define wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
319 // log a message indicating the number of times the previous message was
320 // repeated if ms_prevCounter > 0, does nothing otherwise; return the old
321 // value of ms_prevCounter
322 unsigned LogLastRepeatIfNeeded();
325 // implement of LogLastRepeatIfNeeded(): it assumes that the
326 // caller had already locked ms_prevCS
327 unsigned LogLastRepeatIfNeededUnlocked();
332 // if true, don't log the same message multiple times, only log it once
333 // with the number of times it was repeated
334 static bool ms_bRepetCounting
;
336 static wxString ms_prevString
; // previous message that was logged
337 static unsigned ms_prevCounter
; // how many times it was repeated
338 static time_t ms_prevTimeStamp
;// timestamp of the previous message
339 static wxLogLevel ms_prevLevel
; // level of the previous message
341 static wxLog
*ms_pLogger
; // currently active log sink
342 static bool ms_doLog
; // false => all logging disabled
343 static bool ms_bAutoCreate
; // create new log targets on demand?
344 static bool ms_bVerbose
; // false => ignore LogInfo messages
346 static wxLogLevel ms_logLevel
; // limit logging to levels <= ms_logLevel
348 static size_t ms_suspendCount
; // if positive, logs are not flushed
350 // format string for strftime(), if NULL, time stamping log messages is
352 static wxString ms_timestamp
;
354 #if WXWIN_COMPATIBILITY_2_8
355 static wxTraceMask ms_ulTraceMask
; // controls wxLogTrace behaviour
356 #endif // WXWIN_COMPATIBILITY_2_8
358 // currently enabled trace masks
359 static wxArrayString ms_aTraceMasks
;
362 // ----------------------------------------------------------------------------
363 // "trivial" derivations of wxLog
364 // ----------------------------------------------------------------------------
366 // log everything except for the debug/trace messages (which are passed to
367 // wxMessageOutputDebug) to a buffer
368 class WXDLLIMPEXP_BASE wxLogBuffer
: public wxLog
373 // get the string contents with all messages logged
374 const wxString
& GetBuffer() const { return m_str
; }
376 // show the buffer contents to the user in the best possible way (this uses
377 // wxMessageOutputMessageBox) and clear it
378 virtual void Flush();
381 #if wxUSE_LOG_DEBUG || wxUSE_LOG_TRACE
382 virtual void DoLog(wxLogLevel level
, const wxString
& szString
, time_t t
);
384 wxSUPPRESS_DOLOG_HIDE_WARNING()
385 #endif // wxUSE_LOG_DEBUG || wxUSE_LOG_TRACE
387 virtual void DoLogString(const wxString
& szString
, time_t t
);
389 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
394 wxDECLARE_NO_COPY_CLASS(wxLogBuffer
);
398 // log everything to a "FILE *", stderr by default
399 class WXDLLIMPEXP_BASE wxLogStderr
: public wxLog
402 // redirect log output to a FILE
403 wxLogStderr(FILE *fp
= NULL
);
406 // implement sink function
407 virtual void DoLogString(const wxString
& szString
, time_t t
);
409 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
413 wxDECLARE_NO_COPY_CLASS(wxLogStderr
);
416 #if wxUSE_STD_IOSTREAM
418 // log everything to an "ostream", cerr by default
419 class WXDLLIMPEXP_BASE wxLogStream
: public wxLog
422 // redirect log output to an ostream
423 wxLogStream(wxSTD ostream
*ostr
= (wxSTD ostream
*) NULL
);
426 // implement sink function
427 virtual void DoLogString(const wxString
& szString
, time_t t
);
429 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
431 // using ptr here to avoid including <iostream.h> from this file
432 wxSTD ostream
*m_ostr
;
435 #endif // wxUSE_STD_IOSTREAM
437 // ----------------------------------------------------------------------------
438 // /dev/null log target: suppress logging until this object goes out of scope
439 // ----------------------------------------------------------------------------
447 // wxFile.Open() normally complains if file can't be opened, we don't
451 if ( !file.Open("bar") )
452 ... process error ourselves ...
454 // ~wxLogNull called, old log sink restored
457 class WXDLLIMPEXP_BASE wxLogNull
460 wxLogNull() : m_flagOld(wxLog::EnableLogging(false)) { }
461 ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld
); }
464 bool m_flagOld
; // the previous value of the wxLog::ms_doLog
467 // ----------------------------------------------------------------------------
468 // chaining log target: installs itself as a log target and passes all
469 // messages to the real log target given to it in the ctor but also forwards
470 // them to the previously active one
472 // note that you don't have to call SetActiveTarget() with this class, it
473 // does it itself in its ctor
474 // ----------------------------------------------------------------------------
476 class WXDLLIMPEXP_BASE wxLogChain
: public wxLog
479 wxLogChain(wxLog
*logger
);
480 virtual ~wxLogChain();
482 // change the new log target
483 void SetLog(wxLog
*logger
);
485 // this can be used to temporarily disable (and then reenable) passing
486 // messages to the old logger (by default we do pass them)
487 void PassMessages(bool bDoPass
) { m_bPassMessages
= bDoPass
; }
489 // are we passing the messages to the previous log target?
490 bool IsPassingMessages() const { return m_bPassMessages
; }
492 // return the previous log target (may be NULL)
493 wxLog
*GetOldLog() const { return m_logOld
; }
495 // override base class version to flush the old logger as well
496 virtual void Flush();
498 // call to avoid destroying the old log target
499 void DetachOldLog() { m_logOld
= NULL
; }
502 // pass the chain to the old logger if needed
503 virtual void DoLog(wxLogLevel level
, const wxString
& szString
, time_t t
);
505 wxSUPPRESS_DOLOG_HIDE_WARNING()
508 // the current log target
511 // the previous log target
514 // do we pass the messages to the old logger?
515 bool m_bPassMessages
;
517 wxDECLARE_NO_COPY_CLASS(wxLogChain
);
520 // a chain log target which uses itself as the new logger
522 #define wxLogPassThrough wxLogInterposer
524 class WXDLLIMPEXP_BASE wxLogInterposer
: public wxLogChain
530 wxDECLARE_NO_COPY_CLASS(wxLogInterposer
);
533 // a temporary interposer which doesn't destroy the old log target
534 // (calls DetachOldLog)
536 class WXDLLIMPEXP_BASE wxLogInterposerTemp
: public wxLogChain
539 wxLogInterposerTemp();
542 wxDECLARE_NO_COPY_CLASS(wxLogInterposerTemp
);
546 // include GUI log targets:
547 #include "wx/generic/logg.h"
550 // ============================================================================
552 // ============================================================================
554 // ----------------------------------------------------------------------------
555 // Log functions should be used by application instead of stdio, iostream &c
556 // for log messages for easy redirection
557 // ----------------------------------------------------------------------------
559 // ----------------------------------------------------------------------------
560 // get error code/error message from system in a portable way
561 // ----------------------------------------------------------------------------
563 // return the last system error code
564 WXDLLIMPEXP_BASE
unsigned long wxSysErrorCode();
566 // return the error message for given (or last if 0) error code
567 WXDLLIMPEXP_BASE
const wxChar
* wxSysErrorMsg(unsigned long nErrCode
= 0);
569 // ----------------------------------------------------------------------------
570 // define wxLog<level>
571 // ----------------------------------------------------------------------------
573 #define DECLARE_LOG_FUNCTION(level) \
574 extern void WXDLLIMPEXP_BASE \
575 wxDoLog##level##Wchar(const wxChar *format, ...); \
576 extern void WXDLLIMPEXP_BASE \
577 wxDoLog##level##Utf8(const char *format, ...); \
578 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
579 1, (const wxFormatString&), \
580 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
581 DECLARE_LOG_FUNCTION_WATCOM(level) \
582 extern void WXDLLIMPEXP_BASE wxVLog##level(const wxString& format, \
586 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
587 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
588 // something too big for Borland C++ to handle
589 #define DECLARE_LOG_FUNCTION_WATCOM(level) \
590 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
591 1, (const wxString&), \
592 (wxFormatString(f1))) \
593 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
594 1, (const wxCStrData&), \
595 (wxFormatString(f1))) \
596 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
598 (wxFormatString(f1))) \
599 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
600 1, (const wchar_t*), \
601 (wxFormatString(f1)))
603 #define DECLARE_LOG_FUNCTION_WATCOM(level)
607 #define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
608 extern void expdecl wxDoLog##level##Wchar(argclass arg, \
609 const wxChar *format, ...); \
610 extern void expdecl wxDoLog##level##Utf8(argclass arg, \
611 const char *format, ...); \
612 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
613 2, (argclass, const wxFormatString&), \
614 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
615 DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
616 extern void expdecl wxVLog##level(argclass arg, \
617 const wxString& format, \
621 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
622 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
623 // something too big for Borland C++ to handle
624 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
625 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
626 2, (argclass, const wxString&), \
627 (f1, wxFormatString(f2))) \
628 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
629 2, (argclass, const wxCStrData&), \
630 (f1, wxFormatString(f2))) \
631 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
632 2, (argclass, const char*), \
633 (f1, wxFormatString(f2))) \
634 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
635 2, (argclass, const wchar_t*), \
636 (f1, wxFormatString(f2)))
638 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl)
644 #undef wxUSE_LOG_DEBUG
645 #define wxUSE_LOG_DEBUG 0
647 #undef wxUSE_LOG_TRACE
648 #define wxUSE_LOG_TRACE 0
651 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
652 #define WX_WATCOM_ONLY_CODE( x ) x
654 #define WX_WATCOM_ONLY_CODE( x )
657 #if defined(__WATCOMC__) || defined(__MINGW32__)
658 // Mingw has similar problem with wxLogSysError:
659 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x ) x
661 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x )
664 // log functions do nothing at all
665 #define DECLARE_LOG_FUNCTION(level) \
666 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxString&)) \
667 WX_WATCOM_ONLY_CODE( \
668 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const char*)) \
669 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wchar_t*)) \
670 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxCStrData&)) \
672 inline void wxVLog##level(const wxString& WXUNUSED(format), \
673 va_list WXUNUSED(argptr)) { } \
675 #define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
676 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxString&)) \
677 WX_WATCOM_OR_MINGW_ONLY_CODE( \
678 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const char*)) \
679 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wchar_t*)) \
680 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxCStrData&)) \
682 inline void wxVLog##level(argclass WXUNUSED(arg), \
683 const wxString& WXUNUSED(format), \
684 va_list WXUNUSED(argptr)) {}
686 // Empty Class to fake wxLogNull
687 class WXDLLIMPEXP_BASE wxLogNull
693 // Dummy macros to replace some functions.
694 #define wxSysErrorCode() (unsigned long)0
695 #define wxSysErrorMsg( X ) (const wxChar*)NULL
697 // Fake symbolic trace masks... for those that are used frequently
698 #define wxTRACE_OleCalls wxEmptyString // OLE interface calls
700 #endif // wxUSE_LOG/!wxUSE_LOG
702 #define DECLARE_LOG_FUNCTION2(level, argclass, arg) \
703 DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, WXDLLIMPEXP_BASE)
705 // VC6 produces a warning if we a macro expanding to nothing to
706 // DECLARE_LOG_FUNCTION2:
707 #if defined(__VISUALC__) && __VISUALC__ < 1300
708 // "not enough actual parameters for macro 'DECLARE_LOG_FUNCTION2_EXP'"
709 #pragma warning(disable:4003)
712 // a generic function for all levels (level is passes as parameter)
713 DECLARE_LOG_FUNCTION2(Generic
, wxLogLevel
, level
);
715 // one function per each level
716 DECLARE_LOG_FUNCTION(FatalError
);
717 DECLARE_LOG_FUNCTION(Error
);
718 DECLARE_LOG_FUNCTION(Warning
);
719 DECLARE_LOG_FUNCTION(Message
);
720 DECLARE_LOG_FUNCTION(Info
);
721 DECLARE_LOG_FUNCTION(Verbose
);
723 // this function sends the log message to the status line of the top level
724 // application frame, if any
725 DECLARE_LOG_FUNCTION(Status
);
728 // this one is the same as previous except that it allows to explicitly
729 class WXDLLIMPEXP_FWD_CORE wxFrame
;
730 // specify the frame to which the output should go
731 DECLARE_LOG_FUNCTION2_EXP(Status
, wxFrame
*, pFrame
, WXDLLIMPEXP_CORE
);
734 // additional one: as wxLogError, but also logs last system call error code
735 // and the corresponding error message if available
736 DECLARE_LOG_FUNCTION(SysError
);
738 // and another one which also takes the error code (for those broken APIs
739 // that don't set the errno (like registry APIs in Win32))
740 DECLARE_LOG_FUNCTION2(SysError
, long, lErrCode
);
742 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
743 DECLARE_LOG_FUNCTION2(SysError
, unsigned long, lErrCode
);
747 // debug functions can be completely disabled in optimized builds
749 // if these log functions are disabled, we prefer to define them as (empty)
750 // variadic macros as this completely removes them and their argument
751 // evaluation from the object code but if this is not supported by compiler we
752 // use empty inline functions instead (defining them as nothing would result in
753 // compiler warnings)
755 // note that making wxVLogDebug/Trace() themselves (empty inline) functions is
756 // a bad idea as some compilers are stupid enough to not inline even empty
757 // functions if their parameters are complicated enough, but by defining them
758 // as an empty inline function we ensure that even dumbest compilers optimise
761 // but Borland gives "W8019: Code has no effect" for wxLogNop() so we need
762 // to define it differently for it to avoid these warnings (same problem as
763 // with wxUnusedVar())
764 #define wxLogNop() { }
766 inline void wxLogNop() { }
770 DECLARE_LOG_FUNCTION(Debug
);
771 #else // !wxUSE_LOG_DEBUG
772 #define wxVLogDebug(fmt, valist) wxLogNop()
774 #ifdef HAVE_VARIADIC_MACROS
775 #define wxLogDebug(fmt, ...) wxLogNop()
776 #else // !HAVE_VARIADIC_MACROS
777 WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug
, 1, (const wxString
&))
779 #endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
782 // this version only logs the message if the mask had been added to the
783 // list of masks with AddTraceMask()
784 DECLARE_LOG_FUNCTION2(Trace
, const wxString
&, mask
);
786 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
787 DECLARE_LOG_FUNCTION2(Trace
, const char*, mask
);
788 DECLARE_LOG_FUNCTION2(Trace
, const wchar_t*, mask
);
791 // and this one does nothing if all of level bits are not set in
792 // wxLog::GetActive()->GetTraceMask() -- it's deprecated in favour of
793 // string identifiers
794 #if WXWIN_COMPATIBILITY_2_8
795 DECLARE_LOG_FUNCTION2(Trace
, wxTraceMask
, mask
);
797 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
798 DECLARE_LOG_FUNCTION2(Trace
, int, mask
);
800 #endif // WXWIN_COMPATIBILITY_2_8
802 #else // !wxUSE_LOG_TRACE
803 #define wxVLogTrace(mask, fmt, valist) wxLogNop()
805 #ifdef HAVE_VARIADIC_MACROS
806 #define wxLogTrace(mask, fmt, ...) wxLogNop()
807 #else // !HAVE_VARIADIC_MACROS
808 #if WXWIN_COMPATIBILITY_2_8
809 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (wxTraceMask
, const wxString
&))
811 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wxString
&, const wxString
&))
813 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
814 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const char*, const char*))
815 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wchar_t*, const wchar_t*))
817 #endif // HAVE_VARIADIC_MACROS/!HAVE_VARIADIC_MACROS
818 #endif // wxUSE_LOG_TRACE/!wxUSE_LOG_TRACE
820 #if defined(__VISUALC__) && __VISUALC__ < 1300
821 #pragma warning(default:4003)
824 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
825 // i.e. without using wxMessageBox() for example because it could crash
826 void WXDLLIMPEXP_BASE
827 wxSafeShowMessage(const wxString
& title
, const wxString
& text
);
829 // ----------------------------------------------------------------------------
830 // debug only logging functions: use them with API name and error code
831 // ----------------------------------------------------------------------------
834 // make life easier for people using VC++ IDE: clicking on the message
835 // will take us immediately to the place of the failed API
837 #define wxLogApiError(api, rc) \
838 wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
839 __FILE__, __LINE__, api, \
840 (long)rc, wxSysErrorMsg(rc))
842 #define wxLogApiError(api, rc) \
843 wxLogDebug(wxT("In file %s at line %d: '%s' failed with ") \
844 wxT("error 0x%08lx (%s)."), \
845 __FILE__, __LINE__, api, \
846 (long)rc, wxSysErrorMsg(rc))
849 #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
851 #else // !wxUSE_LOG_DEBUG
852 #define wxLogApiError(api, err) wxLogNop()
853 #define wxLogLastError(api) wxLogNop()
854 #endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
856 // wxCocoa has additiional trace masks
857 #if defined(__WXCOCOA__)
858 #include "wx/cocoa/log.h"
861 #ifdef WX_WATCOM_ONLY_CODE
862 #undef WX_WATCOM_ONLY_CODE