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 /////////////////////////////////////////////////////////////////////////////
18 class WXDLLIMPEXP_FWD_BASE wxCriticalSection
;
21 // ----------------------------------------------------------------------------
22 // common constants for use in wxUSE_LOG/!wxUSE_LOG
23 // ----------------------------------------------------------------------------
25 // the trace masks have been superceded by symbolic trace constants, they're
26 // for compatibility only andwill be removed soon - do NOT use them
28 // meaning of different bits of the trace mask (which allows selectively
29 // enable/disable some trace messages)
30 #define wxTraceMemAlloc 0x0001 // trace memory allocation (new/delete)
31 #define wxTraceMessages 0x0002 // trace window messages/X callbacks
32 #define wxTraceResAlloc 0x0004 // trace GDI resource allocation
33 #define wxTraceRefCount 0x0008 // trace various ref counting operations
36 #define wxTraceOleCalls 0x0100 // OLE interface calls
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 // NB: these types are needed even if wxUSE_LOG == 0
44 typedef unsigned long wxTraceMask
;
45 typedef unsigned long wxLogLevel
;
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 #include "wx/string.h"
52 #include "wx/strvararg.h"
56 #include "wx/arrstr.h"
59 #include <time.h> // for time_t
62 #include "wx/dynarray.h"
64 #ifndef wxUSE_LOG_DEBUG
66 # define wxUSE_LOG_DEBUG 1
67 # else // !__WXDEBUG__
68 # define wxUSE_LOG_DEBUG 0
72 // ----------------------------------------------------------------------------
73 // forward declarations
74 // ----------------------------------------------------------------------------
77 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
78 class WXDLLIMPEXP_FWD_CORE wxLogFrame
;
79 class WXDLLIMPEXP_FWD_CORE wxFrame
;
80 class WXDLLIMPEXP_FWD_CORE wxWindow
;
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 // different standard log levels (you may also define your own)
90 wxLOG_FatalError
, // program can't continue, abort immediately
91 wxLOG_Error
, // a serious error, user must be informed about it
92 wxLOG_Warning
, // user is normally informed about it but may be ignored
93 wxLOG_Message
, // normal message (i.e. normal output of a non GUI app)
94 wxLOG_Status
, // informational: might go to the status line of GUI app
95 wxLOG_Info
, // informational message (a.k.a. 'Verbose')
96 wxLOG_Debug
, // never shown to the user, disabled in release mode
97 wxLOG_Trace
, // trace messages are also only enabled in debug mode
98 wxLOG_Progress
, // used for progress indicator (not yet)
99 wxLOG_User
= 100, // user defined levels start here
103 // symbolic trace masks - wxLogTrace("foo", "some trace message...") will be
104 // discarded unless the string "foo" has been added to the list of allowed
105 // ones with AddTraceMask()
107 #define wxTRACE_MemAlloc wxT("memalloc") // trace memory allocation (new/delete)
108 #define wxTRACE_Messages wxT("messages") // trace window messages/X callbacks
109 #define wxTRACE_ResAlloc wxT("resalloc") // trace GDI resource allocation
110 #define wxTRACE_RefCount wxT("refcount") // trace various ref counting operations
113 #define wxTRACE_OleCalls wxT("ole") // OLE interface calls
116 #include "wx/iosfwrap.h"
118 // ----------------------------------------------------------------------------
119 // derive from this class to redirect (or suppress, or ...) log messages
120 // normally, only a single instance of this class exists but it's not enforced
121 // ----------------------------------------------------------------------------
123 class WXDLLIMPEXP_BASE wxLog
129 // these functions allow to completely disable all log messages
131 // is logging disabled now?
132 static bool IsEnabled() { return ms_doLog
; }
134 // change the flag state, return the previous one
135 static bool EnableLogging(bool doIt
= true)
136 { bool doLogOld
= ms_doLog
; ms_doLog
= doIt
; return doLogOld
; }
138 // static sink function - see DoLog() for function to overload in the
140 static void OnLog(wxLogLevel level
, const wxString
& szString
, time_t t
);
144 // flush shows all messages if they're not logged immediately (FILE
145 // and iostream logs don't need it, but wxGuiLog does to avoid showing
146 // 17 modal dialogs one after another)
147 virtual void Flush();
149 // flush the active target if any
150 static void FlushActive()
152 if ( !ms_suspendCount
)
154 wxLog
*log
= GetActiveTarget();
160 // only one sink is active at each moment
161 // get current log target, will call wxApp::CreateLogTarget() to
162 // create one if none exists
163 static wxLog
*GetActiveTarget();
165 // change log target, pLogger may be NULL
166 static wxLog
*SetActiveTarget(wxLog
*pLogger
);
168 // suspend the message flushing of the main target until the next call
169 // to Resume() - this is mainly for internal use (to prevent wxYield()
170 // from flashing the messages)
171 static void Suspend() { ms_suspendCount
++; }
173 // must be called for each Suspend()!
174 static void Resume() { ms_suspendCount
--; }
176 // functions controlling the default wxLog behaviour
177 // verbose mode is activated by standard command-line '-verbose'
179 static void SetVerbose(bool bVerbose
= true) { ms_bVerbose
= bVerbose
; }
181 // Set log level. Log messages with level > logLevel will not be logged.
182 static void SetLogLevel(wxLogLevel logLevel
) { ms_logLevel
= logLevel
; }
184 // should GetActiveTarget() try to create a new log object if the
186 static void DontCreateOnDemand();
188 // Make GetActiveTarget() create a new log object again.
189 static void DoCreateOnDemand();
191 // log the count of repeating messages instead of logging the messages
193 static void SetRepetitionCounting(bool bRepetCounting
= true)
194 { ms_bRepetCounting
= bRepetCounting
; }
196 // gets duplicate counting status
197 static bool GetRepetitionCounting() { return ms_bRepetCounting
; }
199 // trace mask (see wxTraceXXX constants for details)
200 static void SetTraceMask(wxTraceMask ulMask
) { ms_ulTraceMask
= ulMask
; }
202 // add string trace mask
203 static void AddTraceMask(const wxString
& str
)
204 { ms_aTraceMasks
.push_back(str
); }
206 // add string trace mask
207 static void RemoveTraceMask(const wxString
& str
);
209 // remove all string trace masks
210 static void ClearTraceMasks();
212 // get string trace masks
213 static const wxArrayString
&GetTraceMasks() { return ms_aTraceMasks
; }
215 // sets the time stamp string format: this is used as strftime() format
216 // string for the log targets which add time stamps to the messages; set
217 // it to empty string to disable time stamping completely.
218 static void SetTimestamp(const wxString
& ts
) { ms_timestamp
= ts
; }
220 // disable time stamping of log messages
221 static void DisableTimestamp() { SetTimestamp(wxEmptyString
); }
226 // gets the verbose status
227 static bool GetVerbose() { return ms_bVerbose
; }
230 static wxTraceMask
GetTraceMask() { return ms_ulTraceMask
; }
232 // is this trace mask in the list?
233 static bool IsAllowedTraceMask(const wxString
& mask
);
235 // return the current loglevel limit
236 static wxLogLevel
GetLogLevel() { return ms_logLevel
; }
238 // get the current timestamp format string (may be NULL)
239 static const wxString
& GetTimestamp() { return ms_timestamp
; }
244 // put the time stamp into the string if ms_timestamp != NULL (don't
245 // change it otherwise)
246 static void TimeStamp(wxString
*str
);
248 // make dtor virtual for all derived classes
252 // this method exists for backwards compatibility only, don't use
253 bool HasPendingMessages() const { return true; }
255 #if WXWIN_COMPATIBILITY_2_6
256 // this function doesn't do anything any more, don't call it
257 wxDEPRECATED( static wxChar
*SetLogBuffer(wxChar
*buf
, size_t size
= 0) );
261 // the logging functions that can be overriden
263 // default DoLog() prepends the time stamp and a prefix corresponding
264 // to the message to szString and then passes it to DoLogString()
265 virtual void DoLog(wxLogLevel level
, const wxString
& szString
, time_t t
);
266 #if WXWIN_COMPATIBILITY_2_8
267 // these shouldn't be used by new code
268 wxDEPRECATED_BUT_USED_INTERNALLY(
269 virtual void DoLog(wxLogLevel level
, const char *szString
, time_t t
)
272 wxDEPRECATED_BUT_USED_INTERNALLY(
273 virtual void DoLog(wxLogLevel level
, const wchar_t *wzString
, time_t t
)
275 #endif // WXWIN_COMPATIBILITY_2_8
277 void LogString(const wxString
& szString
, time_t t
)
278 { DoLogString(szString
, t
); }
280 // default DoLogString does nothing but is not pure virtual because if
281 // you override DoLog() you might not need it at all
282 virtual void DoLogString(const wxString
& szString
, time_t t
);
283 #if WXWIN_COMPATIBILITY_2_8
284 // these shouldn't be used by new code
285 virtual void DoLogString(const char *WXUNUSED(szString
),
286 time_t WXUNUSED(t
)) {}
287 virtual void DoLogString(const wchar_t *WXUNUSED(szString
),
288 time_t WXUNUSED(t
)) {}
289 #endif // WXWIN_COMPATIBILITY_2_8
291 // this macro should be used in the derived classes to avoid warnings about
292 // hiding the other DoLog() overloads when overriding DoLog(wxString) --
293 // but don't use it with MSVC which doesn't give this warning but does give
294 // warning when a deprecated function is overridden
295 #if WXWIN_COMPATIBILITY_2_8 && !defined(__VISUALC__)
296 #define wxSUPPRESS_DOLOG_HIDE_WARNING() \
297 virtual void DoLog(wxLogLevel, const char *, time_t) { } \
298 virtual void DoLog(wxLogLevel, const wchar_t *, time_t) { }
300 #define wxSUPPRESS_DOLOGSTRING_HIDE_WARNING() \
301 virtual void DoLogString(const char *, time_t) { } \
302 virtual void DoLogString(const wchar_t *, time_t) { }
304 #define wxSUPPRESS_DOLOG_HIDE_WARNING()
305 #define wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
308 // log a message indicating the number of times the previous message was
309 // repeated if ms_prevCounter > 0, does nothing otherwise; return the old
310 // value of ms_prevCounter
311 unsigned LogLastRepeatIfNeeded();
314 // implement of LogLastRepeatIfNeeded(): it assumes that the
315 // caller had already locked ms_prevCS
316 unsigned LogLastRepeatIfNeededUnlocked();
321 // if true, don't log the same message multiple times, only log it once
322 // with the number of times it was repeated
323 static bool ms_bRepetCounting
;
326 static wxCriticalSection ms_prevCS
; // protects the ms_prev values below
328 static wxString ms_prevString
; // previous message that was logged
329 static unsigned ms_prevCounter
; // how many times it was repeated
330 static time_t ms_prevTimeStamp
;// timestamp of the previous message
331 static wxLogLevel ms_prevLevel
; // level of the previous message
333 static wxLog
*ms_pLogger
; // currently active log sink
334 static bool ms_doLog
; // false => all logging disabled
335 static bool ms_bAutoCreate
; // create new log targets on demand?
336 static bool ms_bVerbose
; // false => ignore LogInfo messages
338 static wxLogLevel ms_logLevel
; // limit logging to levels <= ms_logLevel
340 static size_t ms_suspendCount
; // if positive, logs are not flushed
342 // format string for strftime(), if NULL, time stamping log messages is
344 static wxString ms_timestamp
;
346 static wxTraceMask ms_ulTraceMask
; // controls wxLogTrace behaviour
347 static wxArrayString ms_aTraceMasks
; // more powerful filter for wxLogTrace
350 // ----------------------------------------------------------------------------
351 // "trivial" derivations of wxLog
352 // ----------------------------------------------------------------------------
354 // log everything to a buffer
355 class WXDLLIMPEXP_BASE wxLogBuffer
: public wxLog
360 // get the string contents with all messages logged
361 const wxString
& GetBuffer() const { return m_str
; }
363 // show the buffer contents to the user in the best possible way (this uses
364 // wxMessageOutputMessageBox) and clear it
365 virtual void Flush();
368 virtual void DoLog(wxLogLevel level
, const wxString
& szString
, time_t t
);
369 virtual void DoLogString(const wxString
& szString
, time_t t
);
371 wxSUPPRESS_DOLOG_HIDE_WARNING()
372 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
377 DECLARE_NO_COPY_CLASS(wxLogBuffer
)
381 // log everything to a "FILE *", stderr by default
382 class WXDLLIMPEXP_BASE wxLogStderr
: public wxLog
385 // redirect log output to a FILE
386 wxLogStderr(FILE *fp
= (FILE *) NULL
);
389 // implement sink function
390 virtual void DoLogString(const wxString
& szString
, time_t t
);
392 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
396 DECLARE_NO_COPY_CLASS(wxLogStderr
)
399 #if wxUSE_STD_IOSTREAM
401 // log everything to an "ostream", cerr by default
402 class WXDLLIMPEXP_BASE wxLogStream
: public wxLog
405 // redirect log output to an ostream
406 wxLogStream(wxSTD ostream
*ostr
= (wxSTD ostream
*) NULL
);
409 // implement sink function
410 virtual void DoLogString(const wxString
& szString
, time_t t
);
412 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
414 // using ptr here to avoid including <iostream.h> from this file
415 wxSTD ostream
*m_ostr
;
418 #endif // wxUSE_STD_IOSTREAM
420 // ----------------------------------------------------------------------------
421 // /dev/null log target: suppress logging until this object goes out of scope
422 // ----------------------------------------------------------------------------
430 // wxFile.Open() normally complains if file can't be opened, we don't
434 if ( !file.Open("bar") )
435 ... process error ourselves ...
437 // ~wxLogNull called, old log sink restored
440 class WXDLLIMPEXP_BASE wxLogNull
443 wxLogNull() : m_flagOld(wxLog::EnableLogging(false)) { }
444 ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld
); }
447 bool m_flagOld
; // the previous value of the wxLog::ms_doLog
450 // ----------------------------------------------------------------------------
451 // chaining log target: installs itself as a log target and passes all
452 // messages to the real log target given to it in the ctor but also forwards
453 // them to the previously active one
455 // note that you don't have to call SetActiveTarget() with this class, it
456 // does it itself in its ctor
457 // ----------------------------------------------------------------------------
459 class WXDLLIMPEXP_BASE wxLogChain
: public wxLog
462 wxLogChain(wxLog
*logger
);
463 virtual ~wxLogChain();
465 // change the new log target
466 void SetLog(wxLog
*logger
);
468 // this can be used to temporarily disable (and then reenable) passing
469 // messages to the old logger (by default we do pass them)
470 void PassMessages(bool bDoPass
) { m_bPassMessages
= bDoPass
; }
472 // are we passing the messages to the previous log target?
473 bool IsPassingMessages() const { return m_bPassMessages
; }
475 // return the previous log target (may be NULL)
476 wxLog
*GetOldLog() const { return m_logOld
; }
478 // override base class version to flush the old logger as well
479 virtual void Flush();
481 // call to avoid destroying the old log target
482 void DetachOldLog() { m_logOld
= NULL
; }
485 // pass the chain to the old logger if needed
486 virtual void DoLog(wxLogLevel level
, const wxString
& szString
, time_t t
);
488 wxSUPPRESS_DOLOG_HIDE_WARNING()
491 // the current log target
494 // the previous log target
497 // do we pass the messages to the old logger?
498 bool m_bPassMessages
;
500 DECLARE_NO_COPY_CLASS(wxLogChain
)
503 // a chain log target which uses itself as the new logger
505 #define wxLogPassThrough wxLogInterposer
507 class WXDLLIMPEXP_BASE wxLogInterposer
: public wxLogChain
513 DECLARE_NO_COPY_CLASS(wxLogInterposer
)
516 // a temporary interposer which doesn't destroy the old log target
517 // (calls DetachOldLog)
519 class WXDLLIMPEXP_BASE wxLogInterposerTemp
: public wxLogChain
522 wxLogInterposerTemp();
525 DECLARE_NO_COPY_CLASS(wxLogInterposerTemp
)
529 // include GUI log targets:
530 #include "wx/generic/logg.h"
533 // ============================================================================
535 // ============================================================================
537 // ----------------------------------------------------------------------------
538 // Log functions should be used by application instead of stdio, iostream &c
539 // for log messages for easy redirection
540 // ----------------------------------------------------------------------------
542 // ----------------------------------------------------------------------------
543 // get error code/error message from system in a portable way
544 // ----------------------------------------------------------------------------
546 // return the last system error code
547 WXDLLIMPEXP_BASE
unsigned long wxSysErrorCode();
549 // return the error message for given (or last if 0) error code
550 WXDLLIMPEXP_BASE
const wxChar
* wxSysErrorMsg(unsigned long nErrCode
= 0);
552 // ----------------------------------------------------------------------------
553 // define wxLog<level>
554 // ----------------------------------------------------------------------------
556 #define DECLARE_LOG_FUNCTION(level) \
557 extern void WXDLLIMPEXP_BASE \
558 wxDoLog##level##Wchar(const wxChar *format, ...); \
559 extern void WXDLLIMPEXP_BASE \
560 wxDoLog##level##Utf8(const char *format, ...); \
561 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
562 1, (const wxFormatString&), \
563 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
564 DECLARE_LOG_FUNCTION_WATCOM(level) \
565 extern void WXDLLIMPEXP_BASE wxVLog##level(const wxString& format, \
569 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
570 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
571 // something too big for Borland C++ to handle
572 #define DECLARE_LOG_FUNCTION_WATCOM(level) \
573 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
574 1, (const wxString&), \
575 (wxFormatString(f1))) \
576 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
577 1, (const wxCStrData&), \
578 (wxFormatString(f1))) \
579 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
581 (wxFormatString(f1))) \
582 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
583 1, (const wchar_t*), \
584 (wxFormatString(f1)))
586 #define DECLARE_LOG_FUNCTION_WATCOM(level)
590 #define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
591 extern void expdecl wxDoLog##level##Wchar(argclass arg, \
592 const wxChar *format, ...); \
593 extern void expdecl wxDoLog##level##Utf8(argclass arg, \
594 const char *format, ...); \
595 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
596 2, (argclass, const wxFormatString&), \
597 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
598 DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
599 extern void expdecl wxVLog##level(argclass arg, \
600 const wxString& format, \
604 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
605 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
606 // something too big for Borland C++ to handle
607 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
608 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
609 2, (argclass, const wxString&), \
610 (f1, wxFormatString(f2))) \
611 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
612 2, (argclass, const wxCStrData&), \
613 (f1, wxFormatString(f2))) \
614 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
615 2, (argclass, const char*), \
616 (f1, wxFormatString(f2))) \
617 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
618 2, (argclass, const wchar_t*), \
619 (f1, wxFormatString(f2)))
621 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl)
628 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
629 #define WX_WATCOM_ONLY_CODE( x ) x
631 #define WX_WATCOM_ONLY_CODE( x )
634 #if defined(__WATCOMC__) || defined(__MINGW32__)
635 // Mingw has similar problem with wxLogSysError:
636 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x ) x
638 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x )
641 // log functions do nothing at all
642 #define DECLARE_LOG_FUNCTION(level) \
643 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxString&)) \
644 WX_WATCOM_ONLY_CODE( \
645 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const char*)) \
646 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wchar_t*)) \
647 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxCStrData&)) \
649 inline void wxVLog##level(const wxString& WXUNUSED(format), \
650 va_list WXUNUSED(argptr)) { } \
652 #define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
653 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxString&)) \
654 WX_WATCOM_OR_MINGW_ONLY_CODE( \
655 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const char*)) \
656 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wchar_t*)) \
657 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxCStrData&)) \
659 inline void wxVLog##level(argclass WXUNUSED(arg), \
660 const wxString& WXUNUSED(format), \
661 va_list WXUNUSED(argptr)) {}
663 // Empty Class to fake wxLogNull
664 class WXDLLIMPEXP_BASE wxLogNull
670 // Dummy macros to replace some functions.
671 #define wxSysErrorCode() (unsigned long)0
672 #define wxSysErrorMsg( X ) (const wxChar*)NULL
674 // Fake symbolic trace masks... for those that are used frequently
675 #define wxTRACE_OleCalls wxEmptyString // OLE interface calls
677 #endif // wxUSE_LOG/!wxUSE_LOG
679 #define DECLARE_LOG_FUNCTION2(level, argclass, arg) \
680 DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, WXDLLIMPEXP_BASE)
682 // VC6 produces a warning if we a macro expanding to nothing to
683 // DECLARE_LOG_FUNCTION2:
684 #if defined(__VISUALC__) && __VISUALC__ < 1300
685 // "not enough actual parameters for macro 'DECLARE_LOG_FUNCTION2_EXP'"
686 #pragma warning(disable:4003)
689 // a generic function for all levels (level is passes as parameter)
690 DECLARE_LOG_FUNCTION2(Generic
, wxLogLevel
, level
);
692 // one function per each level
693 DECLARE_LOG_FUNCTION(FatalError
);
694 DECLARE_LOG_FUNCTION(Error
);
695 DECLARE_LOG_FUNCTION(Warning
);
696 DECLARE_LOG_FUNCTION(Message
);
697 DECLARE_LOG_FUNCTION(Info
);
698 DECLARE_LOG_FUNCTION(Verbose
);
700 // this function sends the log message to the status line of the top level
701 // application frame, if any
702 DECLARE_LOG_FUNCTION(Status
);
705 // this one is the same as previous except that it allows to explicitly
706 class WXDLLIMPEXP_FWD_CORE wxFrame
;
707 // specify the frame to which the output should go
708 DECLARE_LOG_FUNCTION2_EXP(Status
, wxFrame
*, pFrame
, WXDLLIMPEXP_CORE
);
711 // additional one: as wxLogError, but also logs last system call error code
712 // and the corresponding error message if available
713 DECLARE_LOG_FUNCTION(SysError
);
715 // and another one which also takes the error code (for those broken APIs
716 // that don't set the errno (like registry APIs in Win32))
717 DECLARE_LOG_FUNCTION2(SysError
, long, lErrCode
);
719 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
720 DECLARE_LOG_FUNCTION2(SysError
, unsigned long, lErrCode
);
723 // debug functions do nothing in release mode
724 #if wxUSE_LOG && wxUSE_LOG_DEBUG
725 DECLARE_LOG_FUNCTION(Debug
);
727 // there is no more unconditional LogTrace: it is not different from
728 // LogDebug and it creates overload ambiguities
729 //DECLARE_LOG_FUNCTION(Trace);
731 // this version only logs the message if the mask had been added to the
732 // list of masks with AddTraceMask()
733 DECLARE_LOG_FUNCTION2(Trace
, const wxString
&, mask
);
735 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
736 DECLARE_LOG_FUNCTION2(Trace
, const char*, mask
);
737 DECLARE_LOG_FUNCTION2(Trace
, const wchar_t*, mask
);
740 // and this one does nothing if all of level bits are not set in
741 // wxLog::GetActive()->GetTraceMask() -- it's deprecated in favour of
742 // string identifiers
743 DECLARE_LOG_FUNCTION2(Trace
, wxTraceMask
, mask
);
745 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
746 DECLARE_LOG_FUNCTION2(Trace
, int, mask
);
748 #else //!debug || !wxUSE_LOG
749 // these functions do nothing in release builds, but don't define them as
750 // nothing as it could result in different code structure in debug and
751 // release and this could result in trouble when these macros are used
754 // note that making wxVLogDebug/Trace() themselves (empty inline) functions
755 // is a bad idea as some compilers are stupid enough to not inline even
756 // empty functions if their parameters are complicated enough, but by
757 // defining them as an empty inline function we ensure that even dumbest
758 // compilers optimise them away
759 inline void wxLogNop() { }
761 #define wxVLogDebug(fmt, valist) wxLogNop()
762 #define wxVLogTrace(mask, fmt, valist) wxLogNop()
764 #ifdef HAVE_VARIADIC_MACROS
765 // unlike the inline functions below, this completely removes the
766 // wxLogXXX calls from the object file:
767 #define wxLogDebug(fmt, ...) wxLogNop()
768 #define wxLogTrace(mask, fmt, ...) wxLogNop()
769 #else // !HAVE_VARIADIC_MACROS
770 //inline void wxLogDebug(const wxString& fmt, ...) {}
771 WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug
, 1, (const wxString
&))
772 //inline void wxLogTrace(wxTraceMask, const wxString& fmt, ...) {}
773 //inline void wxLogTrace(const wxString&, const wxString& fmt, ...) {}
774 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (wxTraceMask
, const wxString
&))
775 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wxString
&, const wxString
&))
777 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
778 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const char*, const char*))
779 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wchar_t*, const wchar_t*))
781 #endif // HAVE_VARIADIC_MACROS/!HAVE_VARIADIC_MACROS
782 #endif // debug/!debug
784 #if defined(__VISUALC__) && __VISUALC__ < 1300
785 #pragma warning(default:4003)
788 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
789 // i.e. without using wxMessageBox() for example because it could crash
790 void WXDLLIMPEXP_BASE
791 wxSafeShowMessage(const wxString
& title
, const wxString
& text
);
793 // ----------------------------------------------------------------------------
794 // debug only logging functions: use them with API name and error code
795 // ----------------------------------------------------------------------------
798 // make life easier for people using VC++ IDE: clicking on the message
799 // will take us immediately to the place of the failed API
801 #define wxLogApiError(api, rc) \
802 wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
803 __FILE__, __LINE__, api, \
804 (long)rc, wxSysErrorMsg(rc))
806 #define wxLogApiError(api, rc) \
807 wxLogDebug(wxT("In file %s at line %d: '%s' failed with ") \
808 wxT("error 0x%08lx (%s)."), \
809 __FILE__, __LINE__, api, \
810 (long)rc, wxSysErrorMsg(rc))
813 #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
816 #define wxLogApiError(api, err) wxLogNop()
817 #define wxLogLastError(api) wxLogNop()
818 #endif //debug/!debug
820 // wxCocoa has additiional trace masks
821 #if defined(__WXCOCOA__)
822 #include "wx/cocoa/log.h"
825 #ifdef WX_WATCOM_ONLY_CODE
826 #undef WX_WATCOM_ONLY_CODE