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"
60 #include <time.h> // for time_t
62 #endif // ! __WXPALMOS5__
64 #include "wx/dynarray.h"
66 #ifndef wxUSE_LOG_DEBUG
68 # define wxUSE_LOG_DEBUG 1
69 # else // !__WXDEBUG__
70 # define wxUSE_LOG_DEBUG 0
74 // ----------------------------------------------------------------------------
75 // forward declarations
76 // ----------------------------------------------------------------------------
79 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
80 class WXDLLIMPEXP_FWD_CORE wxLogFrame
;
81 class WXDLLIMPEXP_FWD_CORE wxFrame
;
82 class WXDLLIMPEXP_FWD_CORE wxWindow
;
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 // different standard log levels (you may also define your own)
92 wxLOG_FatalError
, // program can't continue, abort immediately
93 wxLOG_Error
, // a serious error, user must be informed about it
94 wxLOG_Warning
, // user is normally informed about it but may be ignored
95 wxLOG_Message
, // normal message (i.e. normal output of a non GUI app)
96 wxLOG_Status
, // informational: might go to the status line of GUI app
97 wxLOG_Info
, // informational message (a.k.a. 'Verbose')
98 wxLOG_Debug
, // never shown to the user, disabled in release mode
99 wxLOG_Trace
, // trace messages are also only enabled in debug mode
100 wxLOG_Progress
, // used for progress indicator (not yet)
101 wxLOG_User
= 100, // user defined levels start here
105 // symbolic trace masks - wxLogTrace("foo", "some trace message...") will be
106 // discarded unless the string "foo" has been added to the list of allowed
107 // ones with AddTraceMask()
109 #define wxTRACE_MemAlloc wxT("memalloc") // trace memory allocation (new/delete)
110 #define wxTRACE_Messages wxT("messages") // trace window messages/X callbacks
111 #define wxTRACE_ResAlloc wxT("resalloc") // trace GDI resource allocation
112 #define wxTRACE_RefCount wxT("refcount") // trace various ref counting operations
115 #define wxTRACE_OleCalls wxT("ole") // OLE interface calls
118 #include "wx/iosfwrap.h"
120 // ----------------------------------------------------------------------------
121 // derive from this class to redirect (or suppress, or ...) log messages
122 // normally, only a single instance of this class exists but it's not enforced
123 // ----------------------------------------------------------------------------
125 class WXDLLIMPEXP_BASE wxLog
131 // these functions allow to completely disable all log messages
133 // is logging disabled now?
134 static bool IsEnabled() { return ms_doLog
; }
136 // change the flag state, return the previous one
137 static bool EnableLogging(bool doIt
= true)
138 { bool doLogOld
= ms_doLog
; ms_doLog
= doIt
; return doLogOld
; }
140 // static sink function - see DoLog() for function to overload in the
142 static void OnLog(wxLogLevel level
, const wxString
& szString
, time_t t
);
146 // flush shows all messages if they're not logged immediately (FILE
147 // and iostream logs don't need it, but wxGuiLog does to avoid showing
148 // 17 modal dialogs one after another)
149 virtual void Flush();
151 // flush the active target if any
152 static void FlushActive()
154 if ( !ms_suspendCount
)
156 wxLog
*log
= GetActiveTarget();
162 // only one sink is active at each moment
163 // get current log target, will call wxApp::CreateLogTarget() to
164 // create one if none exists
165 static wxLog
*GetActiveTarget();
167 // change log target, pLogger may be NULL
168 static wxLog
*SetActiveTarget(wxLog
*pLogger
);
170 // suspend the message flushing of the main target until the next call
171 // to Resume() - this is mainly for internal use (to prevent wxYield()
172 // from flashing the messages)
173 static void Suspend() { ms_suspendCount
++; }
175 // must be called for each Suspend()!
176 static void Resume() { ms_suspendCount
--; }
178 // functions controlling the default wxLog behaviour
179 // verbose mode is activated by standard command-line '-verbose'
181 static void SetVerbose(bool bVerbose
= true) { ms_bVerbose
= bVerbose
; }
183 // Set log level. Log messages with level > logLevel will not be logged.
184 static void SetLogLevel(wxLogLevel logLevel
) { ms_logLevel
= logLevel
; }
186 // should GetActiveTarget() try to create a new log object if the
188 static void DontCreateOnDemand();
190 // Make GetActiveTarget() create a new log object again.
191 static void DoCreateOnDemand();
193 // log the count of repeating messages instead of logging the messages
195 static void SetRepetitionCounting(bool bRepetCounting
= true)
196 { ms_bRepetCounting
= bRepetCounting
; }
198 // gets duplicate counting status
199 static bool GetRepetitionCounting() { return ms_bRepetCounting
; }
201 // trace mask (see wxTraceXXX constants for details)
202 static void SetTraceMask(wxTraceMask ulMask
) { ms_ulTraceMask
= ulMask
; }
204 // add string trace mask
205 static void AddTraceMask(const wxString
& str
)
206 { ms_aTraceMasks
.push_back(str
); }
208 // add string trace mask
209 static void RemoveTraceMask(const wxString
& str
);
211 // remove all string trace masks
212 static void ClearTraceMasks();
214 // get string trace masks
215 static const wxArrayString
&GetTraceMasks() { return ms_aTraceMasks
; }
217 // sets the time stamp string format: this is used as strftime() format
218 // string for the log targets which add time stamps to the messages; set
219 // it to empty string to disable time stamping completely.
220 static void SetTimestamp(const wxString
& ts
) { ms_timestamp
= ts
; }
222 // disable time stamping of log messages
223 static void DisableTimestamp() { SetTimestamp(wxEmptyString
); }
228 // gets the verbose status
229 static bool GetVerbose() { return ms_bVerbose
; }
232 static wxTraceMask
GetTraceMask() { return ms_ulTraceMask
; }
234 // is this trace mask in the list?
235 static bool IsAllowedTraceMask(const wxString
& mask
);
237 // return the current loglevel limit
238 static wxLogLevel
GetLogLevel() { return ms_logLevel
; }
240 // get the current timestamp format string (may be NULL)
241 static const wxString
& GetTimestamp() { return ms_timestamp
; }
246 // put the time stamp into the string if ms_timestamp != NULL (don't
247 // change it otherwise)
248 static void TimeStamp(wxString
*str
);
250 // make dtor virtual for all derived classes
254 // this method exists for backwards compatibility only, don't use
255 bool HasPendingMessages() const { return true; }
257 #if WXWIN_COMPATIBILITY_2_6
258 // this function doesn't do anything any more, don't call it
259 wxDEPRECATED( static wxChar
*SetLogBuffer(wxChar
*buf
, size_t size
= 0) );
263 // the logging functions that can be overriden
265 // default DoLog() prepends the time stamp and a prefix corresponding
266 // to the message to szString and then passes it to DoLogString()
267 virtual void DoLog(wxLogLevel level
, const wxString
& szString
, time_t t
);
268 #if WXWIN_COMPATIBILITY_2_8
269 // these shouldn't be used by new code
270 wxDEPRECATED_BUT_USED_INTERNALLY(
271 virtual void DoLog(wxLogLevel level
, const char *szString
, time_t t
)
274 wxDEPRECATED_BUT_USED_INTERNALLY(
275 virtual void DoLog(wxLogLevel level
, const wchar_t *wzString
, time_t t
)
277 #endif // WXWIN_COMPATIBILITY_2_8
279 void LogString(const wxString
& szString
, time_t t
)
280 { DoLogString(szString
, t
); }
282 // default DoLogString does nothing but is not pure virtual because if
283 // you override DoLog() you might not need it at all
284 virtual void DoLogString(const wxString
& szString
, time_t t
);
285 #if WXWIN_COMPATIBILITY_2_8
286 // these shouldn't be used by new code
287 virtual void DoLogString(const char *WXUNUSED(szString
),
288 time_t WXUNUSED(t
)) {}
289 virtual void DoLogString(const wchar_t *WXUNUSED(szString
),
290 time_t WXUNUSED(t
)) {}
291 #endif // WXWIN_COMPATIBILITY_2_8
293 // this macro should be used in the derived classes to avoid warnings about
294 // hiding the other DoLog() overloads when overriding DoLog(wxString) --
295 // but don't use it with MSVC which doesn't give this warning but does give
296 // warning when a deprecated function is overridden
297 #if WXWIN_COMPATIBILITY_2_8 && !defined(__VISUALC__)
298 #define wxSUPPRESS_DOLOG_HIDE_WARNING() \
299 virtual void DoLog(wxLogLevel, const char *, time_t) { } \
300 virtual void DoLog(wxLogLevel, const wchar_t *, time_t) { }
302 #define wxSUPPRESS_DOLOGSTRING_HIDE_WARNING() \
303 virtual void DoLogString(const char *, time_t) { } \
304 virtual void DoLogString(const wchar_t *, time_t) { }
306 #define wxSUPPRESS_DOLOG_HIDE_WARNING()
307 #define wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
310 // log a message indicating the number of times the previous message was
311 // repeated if ms_prevCounter > 0, does nothing otherwise; return the old
312 // value of ms_prevCounter
313 unsigned LogLastRepeatIfNeeded();
316 // implement of LogLastRepeatIfNeeded(): it assumes that the
317 // caller had already locked ms_prevCS
318 unsigned LogLastRepeatIfNeededUnlocked();
323 // if true, don't log the same message multiple times, only log it once
324 // with the number of times it was repeated
325 static bool ms_bRepetCounting
;
328 static wxCriticalSection ms_prevCS
; // protects the ms_prev values below
330 static wxString ms_prevString
; // previous message that was logged
331 static unsigned ms_prevCounter
; // how many times it was repeated
332 static time_t ms_prevTimeStamp
;// timestamp of the previous message
333 static wxLogLevel ms_prevLevel
; // level of the previous message
335 static wxLog
*ms_pLogger
; // currently active log sink
336 static bool ms_doLog
; // false => all logging disabled
337 static bool ms_bAutoCreate
; // create new log targets on demand?
338 static bool ms_bVerbose
; // false => ignore LogInfo messages
340 static wxLogLevel ms_logLevel
; // limit logging to levels <= ms_logLevel
342 static size_t ms_suspendCount
; // if positive, logs are not flushed
344 // format string for strftime(), if NULL, time stamping log messages is
346 static wxString ms_timestamp
;
348 static wxTraceMask ms_ulTraceMask
; // controls wxLogTrace behaviour
349 static wxArrayString ms_aTraceMasks
; // more powerful filter for wxLogTrace
352 // ----------------------------------------------------------------------------
353 // "trivial" derivations of wxLog
354 // ----------------------------------------------------------------------------
356 // log everything to a buffer
357 class WXDLLIMPEXP_BASE wxLogBuffer
: public wxLog
362 // get the string contents with all messages logged
363 const wxString
& GetBuffer() const { return m_str
; }
365 // show the buffer contents to the user in the best possible way (this uses
366 // wxMessageOutputMessageBox) and clear it
367 virtual void Flush();
370 virtual void DoLog(wxLogLevel level
, const wxString
& szString
, time_t t
);
371 virtual void DoLogString(const wxString
& szString
, time_t t
);
373 wxSUPPRESS_DOLOG_HIDE_WARNING()
374 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
379 DECLARE_NO_COPY_CLASS(wxLogBuffer
)
383 // log everything to a "FILE *", stderr by default
384 class WXDLLIMPEXP_BASE wxLogStderr
: public wxLog
387 // redirect log output to a FILE
388 wxLogStderr(FILE *fp
= (FILE *) NULL
);
391 // implement sink function
392 virtual void DoLogString(const wxString
& szString
, time_t t
);
394 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
398 DECLARE_NO_COPY_CLASS(wxLogStderr
)
401 #if wxUSE_STD_IOSTREAM
403 // log everything to an "ostream", cerr by default
404 class WXDLLIMPEXP_BASE wxLogStream
: public wxLog
407 // redirect log output to an ostream
408 wxLogStream(wxSTD ostream
*ostr
= (wxSTD ostream
*) NULL
);
411 // implement sink function
412 virtual void DoLogString(const wxString
& szString
, time_t t
);
414 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
416 // using ptr here to avoid including <iostream.h> from this file
417 wxSTD ostream
*m_ostr
;
420 #endif // wxUSE_STD_IOSTREAM
422 // ----------------------------------------------------------------------------
423 // /dev/null log target: suppress logging until this object goes out of scope
424 // ----------------------------------------------------------------------------
432 // wxFile.Open() normally complains if file can't be opened, we don't
436 if ( !file.Open("bar") )
437 ... process error ourselves ...
439 // ~wxLogNull called, old log sink restored
442 class WXDLLIMPEXP_BASE wxLogNull
445 wxLogNull() : m_flagOld(wxLog::EnableLogging(false)) { }
446 ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld
); }
449 bool m_flagOld
; // the previous value of the wxLog::ms_doLog
452 // ----------------------------------------------------------------------------
453 // chaining log target: installs itself as a log target and passes all
454 // messages to the real log target given to it in the ctor but also forwards
455 // them to the previously active one
457 // note that you don't have to call SetActiveTarget() with this class, it
458 // does it itself in its ctor
459 // ----------------------------------------------------------------------------
461 class WXDLLIMPEXP_BASE wxLogChain
: public wxLog
464 wxLogChain(wxLog
*logger
);
465 virtual ~wxLogChain();
467 // change the new log target
468 void SetLog(wxLog
*logger
);
470 // this can be used to temporarily disable (and then reenable) passing
471 // messages to the old logger (by default we do pass them)
472 void PassMessages(bool bDoPass
) { m_bPassMessages
= bDoPass
; }
474 // are we passing the messages to the previous log target?
475 bool IsPassingMessages() const { return m_bPassMessages
; }
477 // return the previous log target (may be NULL)
478 wxLog
*GetOldLog() const { return m_logOld
; }
480 // override base class version to flush the old logger as well
481 virtual void Flush();
483 // call to avoid destroying the old log target
484 void DetachOldLog() { m_logOld
= NULL
; }
487 // pass the chain to the old logger if needed
488 virtual void DoLog(wxLogLevel level
, const wxString
& szString
, time_t t
);
490 wxSUPPRESS_DOLOG_HIDE_WARNING()
493 // the current log target
496 // the previous log target
499 // do we pass the messages to the old logger?
500 bool m_bPassMessages
;
502 DECLARE_NO_COPY_CLASS(wxLogChain
)
505 // a chain log target which uses itself as the new logger
507 #define wxLogPassThrough wxLogInterposer
509 class WXDLLIMPEXP_BASE wxLogInterposer
: public wxLogChain
515 DECLARE_NO_COPY_CLASS(wxLogInterposer
)
518 // a temporary interposer which doesn't destroy the old log target
519 // (calls DetachOldLog)
521 class WXDLLIMPEXP_BASE wxLogInterposerTemp
: public wxLogChain
524 wxLogInterposerTemp();
527 DECLARE_NO_COPY_CLASS(wxLogInterposerTemp
)
531 // include GUI log targets:
532 #include "wx/generic/logg.h"
535 // ============================================================================
537 // ============================================================================
539 // ----------------------------------------------------------------------------
540 // Log functions should be used by application instead of stdio, iostream &c
541 // for log messages for easy redirection
542 // ----------------------------------------------------------------------------
544 // ----------------------------------------------------------------------------
545 // get error code/error message from system in a portable way
546 // ----------------------------------------------------------------------------
548 // return the last system error code
549 WXDLLIMPEXP_BASE
unsigned long wxSysErrorCode();
551 // return the error message for given (or last if 0) error code
552 WXDLLIMPEXP_BASE
const wxChar
* wxSysErrorMsg(unsigned long nErrCode
= 0);
554 // ----------------------------------------------------------------------------
555 // define wxLog<level>
556 // ----------------------------------------------------------------------------
558 #define DECLARE_LOG_FUNCTION(level) \
559 extern void WXDLLIMPEXP_BASE \
560 wxDoLog##level##Wchar(const wxChar *format, ...); \
561 extern void WXDLLIMPEXP_BASE \
562 wxDoLog##level##Utf8(const char *format, ...); \
563 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
564 1, (const wxFormatString&), \
565 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
566 DECLARE_LOG_FUNCTION_WATCOM(level) \
567 extern void WXDLLIMPEXP_BASE wxVLog##level(const wxString& format, \
571 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
572 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
573 // something too big for Borland C++ to handle
574 #define DECLARE_LOG_FUNCTION_WATCOM(level) \
575 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
576 1, (const wxString&), \
577 (wxFormatString(f1))) \
578 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
579 1, (const wxCStrData&), \
580 (wxFormatString(f1))) \
581 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
583 (wxFormatString(f1))) \
584 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
585 1, (const wchar_t*), \
586 (wxFormatString(f1)))
588 #define DECLARE_LOG_FUNCTION_WATCOM(level)
592 #define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
593 extern void expdecl wxDoLog##level##Wchar(argclass arg, \
594 const wxChar *format, ...); \
595 extern void expdecl wxDoLog##level##Utf8(argclass arg, \
596 const char *format, ...); \
597 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
598 2, (argclass, const wxFormatString&), \
599 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
600 DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
601 extern void expdecl wxVLog##level(argclass arg, \
602 const wxString& format, \
606 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
607 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
608 // something too big for Borland C++ to handle
609 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
610 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
611 2, (argclass, const wxString&), \
612 (f1, wxFormatString(f2))) \
613 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
614 2, (argclass, const wxCStrData&), \
615 (f1, wxFormatString(f2))) \
616 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
617 2, (argclass, const char*), \
618 (f1, wxFormatString(f2))) \
619 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
620 2, (argclass, const wchar_t*), \
621 (f1, wxFormatString(f2)))
623 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl)
630 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
631 #define WX_WATCOM_ONLY_CODE( x ) x
633 #define WX_WATCOM_ONLY_CODE( x )
636 #if defined(__WATCOMC__) || defined(__MINGW32__)
637 // Mingw has similar problem with wxLogSysError:
638 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x ) x
640 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x )
643 // log functions do nothing at all
644 #define DECLARE_LOG_FUNCTION(level) \
645 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxString&)) \
646 WX_WATCOM_ONLY_CODE( \
647 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const char*)) \
648 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wchar_t*)) \
649 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxCStrData&)) \
651 inline void wxVLog##level(const wxString& WXUNUSED(format), \
652 va_list WXUNUSED(argptr)) { } \
654 #define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
655 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxString&)) \
656 WX_WATCOM_OR_MINGW_ONLY_CODE( \
657 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const char*)) \
658 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wchar_t*)) \
659 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxCStrData&)) \
661 inline void wxVLog##level(argclass WXUNUSED(arg), \
662 const wxString& WXUNUSED(format), \
663 va_list WXUNUSED(argptr)) {}
665 // Empty Class to fake wxLogNull
666 class WXDLLIMPEXP_BASE wxLogNull
672 // Dummy macros to replace some functions.
673 #define wxSysErrorCode() (unsigned long)0
674 #define wxSysErrorMsg( X ) (const wxChar*)NULL
676 // Fake symbolic trace masks... for those that are used frequently
677 #define wxTRACE_OleCalls wxEmptyString // OLE interface calls
679 #endif // wxUSE_LOG/!wxUSE_LOG
681 #define DECLARE_LOG_FUNCTION2(level, argclass, arg) \
682 DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, WXDLLIMPEXP_BASE)
684 // VC6 produces a warning if we a macro expanding to nothing to
685 // DECLARE_LOG_FUNCTION2:
686 #if defined(__VISUALC__) && __VISUALC__ < 1300
687 // "not enough actual parameters for macro 'DECLARE_LOG_FUNCTION2_EXP'"
688 #pragma warning(disable:4003)
691 // a generic function for all levels (level is passes as parameter)
692 DECLARE_LOG_FUNCTION2(Generic
, wxLogLevel
, level
);
694 // one function per each level
695 DECLARE_LOG_FUNCTION(FatalError
);
696 DECLARE_LOG_FUNCTION(Error
);
697 DECLARE_LOG_FUNCTION(Warning
);
698 DECLARE_LOG_FUNCTION(Message
);
699 DECLARE_LOG_FUNCTION(Info
);
700 DECLARE_LOG_FUNCTION(Verbose
);
702 // this function sends the log message to the status line of the top level
703 // application frame, if any
704 DECLARE_LOG_FUNCTION(Status
);
707 // this one is the same as previous except that it allows to explicitly
708 class WXDLLIMPEXP_FWD_CORE wxFrame
;
709 // specify the frame to which the output should go
710 DECLARE_LOG_FUNCTION2_EXP(Status
, wxFrame
*, pFrame
, WXDLLIMPEXP_CORE
);
713 // additional one: as wxLogError, but also logs last system call error code
714 // and the corresponding error message if available
715 DECLARE_LOG_FUNCTION(SysError
);
717 // and another one which also takes the error code (for those broken APIs
718 // that don't set the errno (like registry APIs in Win32))
719 DECLARE_LOG_FUNCTION2(SysError
, long, lErrCode
);
721 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
722 DECLARE_LOG_FUNCTION2(SysError
, unsigned long, lErrCode
);
725 // debug functions do nothing in release mode
726 #if wxUSE_LOG && wxUSE_LOG_DEBUG
727 DECLARE_LOG_FUNCTION(Debug
);
729 // there is no more unconditional LogTrace: it is not different from
730 // LogDebug and it creates overload ambiguities
731 //DECLARE_LOG_FUNCTION(Trace);
733 // this version only logs the message if the mask had been added to the
734 // list of masks with AddTraceMask()
735 DECLARE_LOG_FUNCTION2(Trace
, const wxString
&, mask
);
737 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
738 DECLARE_LOG_FUNCTION2(Trace
, const char*, mask
);
739 DECLARE_LOG_FUNCTION2(Trace
, const wchar_t*, mask
);
742 // and this one does nothing if all of level bits are not set in
743 // wxLog::GetActive()->GetTraceMask() -- it's deprecated in favour of
744 // string identifiers
745 DECLARE_LOG_FUNCTION2(Trace
, wxTraceMask
, mask
);
747 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
748 DECLARE_LOG_FUNCTION2(Trace
, int, mask
);
750 #else //!debug || !wxUSE_LOG
751 // these functions do nothing in release builds, but don't define them as
752 // nothing as it could result in different code structure in debug and
753 // release and this could result in trouble when these macros are used
756 // note that making wxVLogDebug/Trace() themselves (empty inline) functions
757 // is a bad idea as some compilers are stupid enough to not inline even
758 // empty functions if their parameters are complicated enough, but by
759 // defining them as an empty inline function we ensure that even dumbest
760 // compilers optimise them away
761 inline void wxLogNop() { }
763 #define wxVLogDebug(fmt, valist) wxLogNop()
764 #define wxVLogTrace(mask, fmt, valist) wxLogNop()
766 #ifdef HAVE_VARIADIC_MACROS
767 // unlike the inline functions below, this completely removes the
768 // wxLogXXX calls from the object file:
769 #define wxLogDebug(fmt, ...) wxLogNop()
770 #define wxLogTrace(mask, fmt, ...) wxLogNop()
771 #else // !HAVE_VARIADIC_MACROS
772 //inline void wxLogDebug(const wxString& fmt, ...) {}
773 WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug
, 1, (const wxString
&))
774 //inline void wxLogTrace(wxTraceMask, const wxString& fmt, ...) {}
775 //inline void wxLogTrace(const wxString&, const wxString& fmt, ...) {}
776 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (wxTraceMask
, const wxString
&))
777 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wxString
&, const wxString
&))
779 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
780 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const char*, const char*))
781 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wchar_t*, const wchar_t*))
783 #endif // HAVE_VARIADIC_MACROS/!HAVE_VARIADIC_MACROS
784 #endif // debug/!debug
786 #if defined(__VISUALC__) && __VISUALC__ < 1300
787 #pragma warning(default:4003)
790 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
791 // i.e. without using wxMessageBox() for example because it could crash
792 void WXDLLIMPEXP_BASE
793 wxSafeShowMessage(const wxString
& title
, const wxString
& text
);
795 // ----------------------------------------------------------------------------
796 // debug only logging functions: use them with API name and error code
797 // ----------------------------------------------------------------------------
800 // make life easier for people using VC++ IDE: clicking on the message
801 // will take us immediately to the place of the failed API
803 #define wxLogApiError(api, rc) \
804 wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
805 __FILE__, __LINE__, api, \
806 (long)rc, wxSysErrorMsg(rc))
808 #define wxLogApiError(api, rc) \
809 wxLogDebug(wxT("In file %s at line %d: '%s' failed with ") \
810 wxT("error 0x%08lx (%s)."), \
811 __FILE__, __LINE__, api, \
812 (long)rc, wxSysErrorMsg(rc))
815 #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
818 #define wxLogApiError(api, err) wxLogNop()
819 #define wxLogLastError(api) wxLogNop()
820 #endif //debug/!debug
822 // wxCocoa has additiional trace masks
823 #if defined(__WXCOCOA__)
824 #include "wx/cocoa/log.h"
827 #ifdef WX_WATCOM_ONLY_CODE
828 #undef WX_WATCOM_ONLY_CODE