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"
59 #include "wx/thread.h"
60 #endif // wxUSE_THREADS
62 // wxUSE_LOG_DEBUG enables the debug log messages
63 #ifndef wxUSE_LOG_DEBUG
65 #define wxUSE_LOG_DEBUG 1
66 #else // !wxDEBUG_LEVEL
67 #define wxUSE_LOG_DEBUG 0
71 // wxUSE_LOG_TRACE enables the trace messages, they are disabled by default
72 #ifndef wxUSE_LOG_TRACE
74 #define wxUSE_LOG_TRACE 1
75 #else // !wxDEBUG_LEVEL
76 #define wxUSE_LOG_TRACE 0
78 #endif // wxUSE_LOG_TRACE
80 // ----------------------------------------------------------------------------
81 // forward declarations
82 // ----------------------------------------------------------------------------
85 class WXDLLIMPEXP_FWD_CORE wxFrame
;
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 // different standard log levels (you may also define your own)
95 wxLOG_FatalError
, // program can't continue, abort immediately
96 wxLOG_Error
, // a serious error, user must be informed about it
97 wxLOG_Warning
, // user is normally informed about it but may be ignored
98 wxLOG_Message
, // normal message (i.e. normal output of a non GUI app)
99 wxLOG_Status
, // informational: might go to the status line of GUI app
100 wxLOG_Info
, // informational message (a.k.a. 'Verbose')
101 wxLOG_Debug
, // never shown to the user, disabled in release mode
102 wxLOG_Trace
, // trace messages are also only enabled in debug mode
103 wxLOG_Progress
, // used for progress indicator (not yet)
104 wxLOG_User
= 100, // user defined levels start here
108 // symbolic trace masks - wxLogTrace("foo", "some trace message...") will be
109 // discarded unless the string "foo" has been added to the list of allowed
110 // ones with AddTraceMask()
112 #define wxTRACE_MemAlloc wxT("memalloc") // trace memory allocation (new/delete)
113 #define wxTRACE_Messages wxT("messages") // trace window messages/X callbacks
114 #define wxTRACE_ResAlloc wxT("resalloc") // trace GDI resource allocation
115 #define wxTRACE_RefCount wxT("refcount") // trace various ref counting operations
118 #define wxTRACE_OleCalls wxT("ole") // OLE interface calls
121 #include "wx/iosfwrap.h"
123 // ----------------------------------------------------------------------------
124 // information about a log record, i.e. unit of log output
125 // ----------------------------------------------------------------------------
127 struct wxLogRecordInfo
135 #endif // wxUSE_THREADS
138 // default copy ctor, assignment operator and dtor are ok
141 // time of record generation
145 // id of the thread which logged this record
146 wxThreadIdType threadId
;
147 #endif // wxUSE_THREADS
150 // ----------------------------------------------------------------------------
151 // derive from this class to redirect (or suppress, or ...) log messages
152 // normally, only a single instance of this class exists but it's not enforced
153 // ----------------------------------------------------------------------------
155 class WXDLLIMPEXP_BASE wxLog
161 // make dtor virtual for all derived classes
165 // these functions allow to completely disable all log messages
167 // is logging disabled now?
168 static bool IsEnabled() { return ms_doLog
; }
170 // change the flag state, return the previous one
171 static bool EnableLogging(bool doIt
= true)
172 { bool doLogOld
= ms_doLog
; ms_doLog
= doIt
; return doLogOld
; }
176 // flush shows all messages if they're not logged immediately (FILE
177 // and iostream logs don't need it, but wxGuiLog does to avoid showing
178 // 17 modal dialogs one after another)
179 virtual void Flush();
181 // flush the active target if any
182 static void FlushActive()
184 if ( !ms_suspendCount
)
186 wxLog
*log
= GetActiveTarget();
192 // only one sink is active at each moment
193 // get current log target, will call wxApp::CreateLogTarget() to
194 // create one if none exists
195 static wxLog
*GetActiveTarget();
197 // change log target, pLogger may be NULL
198 static wxLog
*SetActiveTarget(wxLog
*pLogger
);
200 // suspend the message flushing of the main target until the next call
201 // to Resume() - this is mainly for internal use (to prevent wxYield()
202 // from flashing the messages)
203 static void Suspend() { ms_suspendCount
++; }
205 // must be called for each Suspend()!
206 static void Resume() { ms_suspendCount
--; }
208 // functions controlling the default wxLog behaviour
209 // verbose mode is activated by standard command-line '--verbose'
211 static void SetVerbose(bool bVerbose
= true) { ms_bVerbose
= bVerbose
; }
213 // Set log level. Log messages with level > logLevel will not be logged.
214 static void SetLogLevel(wxLogLevel logLevel
) { ms_logLevel
= logLevel
; }
216 // should GetActiveTarget() try to create a new log object if the
218 static void DontCreateOnDemand();
220 // Make GetActiveTarget() create a new log object again.
221 static void DoCreateOnDemand();
223 // log the count of repeating messages instead of logging the messages
225 static void SetRepetitionCounting(bool bRepetCounting
= true)
226 { ms_bRepetCounting
= bRepetCounting
; }
228 // gets duplicate counting status
229 static bool GetRepetitionCounting() { return ms_bRepetCounting
; }
231 // add string trace mask
232 static void AddTraceMask(const wxString
& str
);
234 // add string trace mask
235 static void RemoveTraceMask(const wxString
& str
);
237 // remove all string trace masks
238 static void ClearTraceMasks();
240 // get string trace masks: note that this is MT-unsafe if other threads can
241 // call AddTraceMask() concurrently
242 static const wxArrayString
& GetTraceMasks() { return ms_aTraceMasks
; }
244 // sets the time stamp string format: this is used as strftime() format
245 // string for the log targets which add time stamps to the messages; set
246 // it to empty string to disable time stamping completely.
247 static void SetTimestamp(const wxString
& ts
) { ms_timestamp
= ts
; }
249 // disable time stamping of log messages
250 static void DisableTimestamp() { SetTimestamp(wxEmptyString
); }
255 // gets the verbose status
256 static bool GetVerbose() { return ms_bVerbose
; }
258 // is this trace mask in the list?
259 static bool IsAllowedTraceMask(const wxString
& mask
);
261 // return the current loglevel limit
262 static wxLogLevel
GetLogLevel() { return ms_logLevel
; }
264 // get the current timestamp format string (maybe empty)
265 static const wxString
& GetTimestamp() { return ms_timestamp
; }
269 // helpers: all functions in this section are mostly for internal use only,
270 // don't call them from your code even if they are not formally deprecated
272 // put the time stamp into the string if ms_timestamp != NULL (don't
273 // change it otherwise)
274 static void TimeStamp(wxString
*str
);
276 // these methods should only be called from derived classes DoLogRecord(),
277 // DoLogTextAtLevel() and DoLogText() implementations respectively and
278 // shouldn't be called directly, use logging functions instead
279 void LogRecord(wxLogLevel level
,
281 const wxLogRecordInfo
& info
)
283 DoLogRecord(level
, msg
, info
);
286 void LogTextAtLevel(wxLogLevel level
, const wxString
& msg
)
288 DoLogTextAtLevel(level
, msg
);
291 void LogText(const wxString
& msg
)
296 // this is a helper used by wxLogXXX() functions, don't call it directly
297 // and see DoLog() for function to overload in the derived classes
298 static void OnLog(wxLogLevel level
,
300 const wxLogRecordInfo
& info
);
302 // version called when no information about the location of the log record
303 // generation is available (but the time stamp is), it mainly exists for
304 // backwards compatibility, don't use it in new code
305 static void OnLog(wxLogLevel level
, const wxString
& msg
, time_t t
);
307 // a helper calling the above overload with current time
308 static void OnLog(wxLogLevel level
, const wxString
& msg
)
310 OnLog(level
, msg
, time(NULL
));
314 // this method exists for backwards compatibility only, don't use
315 bool HasPendingMessages() const { return true; }
317 #if WXWIN_COMPATIBILITY_2_6
318 // this function doesn't do anything any more, don't call it
320 static wxChar
*SetLogBuffer(wxChar
*, size_t = 0), return NULL
;
322 #endif // WXWIN_COMPATIBILITY_2_6
324 // don't use integer masks any more, use string trace masks instead
325 #if WXWIN_COMPATIBILITY_2_8
326 wxDEPRECATED_INLINE( static void SetTraceMask(wxTraceMask ulMask
),
327 ms_ulTraceMask
= ulMask
; )
328 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE( static wxTraceMask
GetTraceMask(),
329 return ms_ulTraceMask
; )
330 #endif // WXWIN_COMPATIBILITY_2_8
333 // the logging functions that can be overridden: DoLogRecord() is called
334 // for every "record", i.e. a unit of log output, to be logged and by
335 // default formats the message and passes it to DoLogTextAtLevel() which in
336 // turn passes it to DoLogText() by default
338 // override this method if you want to change message formatting or do
340 virtual void DoLogRecord(wxLogLevel level
,
342 const wxLogRecordInfo
& info
);
344 // override this method to redirect output to different channels depending
345 // on its level only; if even the level doesn't matter, override
346 // DoLogText() instead
347 virtual void DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
);
349 // this function is not pure virtual as it might not be needed if you do
350 // the logging in overridden DoLogRecord() or DoLogTextAtLevel() directly
351 // but if you do not override them in your derived class you must override
352 // this one as the default implementation of it simply asserts
353 virtual void DoLogText(const wxString
& msg
);
356 // the rest of the functions are for backwards compatibility only, don't
357 // use them in new code; if you're updating your existing code you need to
358 // switch to overriding DoLogRecord/Text() above (although as long as these
359 // functions exist, log classes using them will continue to work)
360 #if WXWIN_COMPATIBILITY_2_8
361 wxDEPRECATED_BUT_USED_INTERNALLY(
362 virtual void DoLog(wxLogLevel level
, const char *szString
, time_t t
)
365 wxDEPRECATED_BUT_USED_INTERNALLY(
366 virtual void DoLog(wxLogLevel level
, const wchar_t *wzString
, time_t t
)
369 // these shouldn't be used by new code
370 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
371 virtual void DoLogString(const char *WXUNUSED(szString
),
375 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
376 virtual void DoLogString(const wchar_t *WXUNUSED(wzString
),
379 #endif // WXWIN_COMPATIBILITY_2_8
382 // log a message indicating the number of times the previous message was
383 // repeated if previous repetition counter is strictly positive, does
384 // nothing otherwise; return the old value of repetition counter
385 unsigned LogLastRepeatIfNeeded();
388 // implement of LogLastRepeatIfNeeded(): it assumes that the
389 // caller had already locked GetPreviousLogCS()
390 unsigned LogLastRepeatIfNeededUnlocked();
395 // if true, don't log the same message multiple times, only log it once
396 // with the number of times it was repeated
397 static bool ms_bRepetCounting
;
399 static wxLog
*ms_pLogger
; // currently active log sink
400 static bool ms_doLog
; // false => all logging disabled
401 static bool ms_bAutoCreate
; // create new log targets on demand?
402 static bool ms_bVerbose
; // false => ignore LogInfo messages
404 static wxLogLevel ms_logLevel
; // limit logging to levels <= ms_logLevel
406 static size_t ms_suspendCount
; // if positive, logs are not flushed
408 // format string for strftime(), if empty, time stamping log messages is
410 static wxString ms_timestamp
;
412 #if WXWIN_COMPATIBILITY_2_8
413 static wxTraceMask ms_ulTraceMask
; // controls wxLogTrace behaviour
414 #endif // WXWIN_COMPATIBILITY_2_8
416 // currently enabled trace masks
417 static wxArrayString ms_aTraceMasks
;
420 // ----------------------------------------------------------------------------
421 // "trivial" derivations of wxLog
422 // ----------------------------------------------------------------------------
424 // log everything except for the debug/trace messages (which are passed to
425 // wxMessageOutputDebug) to a buffer
426 class WXDLLIMPEXP_BASE wxLogBuffer
: public wxLog
431 // get the string contents with all messages logged
432 const wxString
& GetBuffer() const { return m_str
; }
434 // show the buffer contents to the user in the best possible way (this uses
435 // wxMessageOutputMessageBox) and clear it
436 virtual void Flush();
439 virtual void DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
);
444 wxDECLARE_NO_COPY_CLASS(wxLogBuffer
);
448 // log everything to a "FILE *", stderr by default
449 class WXDLLIMPEXP_BASE wxLogStderr
: public wxLog
452 // redirect log output to a FILE
453 wxLogStderr(FILE *fp
= NULL
);
456 // implement sink function
457 virtual void DoLogText(const wxString
& msg
);
461 wxDECLARE_NO_COPY_CLASS(wxLogStderr
);
464 #if wxUSE_STD_IOSTREAM
466 // log everything to an "ostream", cerr by default
467 class WXDLLIMPEXP_BASE wxLogStream
: public wxLog
470 // redirect log output to an ostream
471 wxLogStream(wxSTD ostream
*ostr
= (wxSTD ostream
*) NULL
);
474 // implement sink function
475 virtual void DoLogText(const wxString
& msg
);
477 // using ptr here to avoid including <iostream.h> from this file
478 wxSTD ostream
*m_ostr
;
481 #endif // wxUSE_STD_IOSTREAM
483 // ----------------------------------------------------------------------------
484 // /dev/null log target: suppress logging until this object goes out of scope
485 // ----------------------------------------------------------------------------
493 // wxFile.Open() normally complains if file can't be opened, we don't
497 if ( !file.Open("bar") )
498 ... process error ourselves ...
500 // ~wxLogNull called, old log sink restored
503 class WXDLLIMPEXP_BASE wxLogNull
506 wxLogNull() : m_flagOld(wxLog::EnableLogging(false)) { }
507 ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld
); }
510 bool m_flagOld
; // the previous value of the wxLog::ms_doLog
513 // ----------------------------------------------------------------------------
514 // chaining log target: installs itself as a log target and passes all
515 // messages to the real log target given to it in the ctor but also forwards
516 // them to the previously active one
518 // note that you don't have to call SetActiveTarget() with this class, it
519 // does it itself in its ctor
520 // ----------------------------------------------------------------------------
522 class WXDLLIMPEXP_BASE wxLogChain
: public wxLog
525 wxLogChain(wxLog
*logger
);
526 virtual ~wxLogChain();
528 // change the new log target
529 void SetLog(wxLog
*logger
);
531 // this can be used to temporarily disable (and then reenable) passing
532 // messages to the old logger (by default we do pass them)
533 void PassMessages(bool bDoPass
) { m_bPassMessages
= bDoPass
; }
535 // are we passing the messages to the previous log target?
536 bool IsPassingMessages() const { return m_bPassMessages
; }
538 // return the previous log target (may be NULL)
539 wxLog
*GetOldLog() const { return m_logOld
; }
541 // override base class version to flush the old logger as well
542 virtual void Flush();
544 // call to avoid destroying the old log target
545 void DetachOldLog() { m_logOld
= NULL
; }
548 // pass the record to the old logger if needed
549 virtual void DoLogRecord(wxLogLevel level
,
551 const wxLogRecordInfo
& info
);
554 // the current log target
557 // the previous log target
560 // do we pass the messages to the old logger?
561 bool m_bPassMessages
;
563 wxDECLARE_NO_COPY_CLASS(wxLogChain
);
566 // a chain log target which uses itself as the new logger
568 #define wxLogPassThrough wxLogInterposer
570 class WXDLLIMPEXP_BASE wxLogInterposer
: public wxLogChain
576 wxDECLARE_NO_COPY_CLASS(wxLogInterposer
);
579 // a temporary interposer which doesn't destroy the old log target
580 // (calls DetachOldLog)
582 class WXDLLIMPEXP_BASE wxLogInterposerTemp
: public wxLogChain
585 wxLogInterposerTemp();
588 wxDECLARE_NO_COPY_CLASS(wxLogInterposerTemp
);
592 // include GUI log targets:
593 #include "wx/generic/logg.h"
596 // ============================================================================
598 // ============================================================================
600 // ----------------------------------------------------------------------------
601 // Log functions should be used by application instead of stdio, iostream &c
602 // for log messages for easy redirection
603 // ----------------------------------------------------------------------------
605 // ----------------------------------------------------------------------------
606 // get error code/error message from system in a portable way
607 // ----------------------------------------------------------------------------
609 // return the last system error code
610 WXDLLIMPEXP_BASE
unsigned long wxSysErrorCode();
612 // return the error message for given (or last if 0) error code
613 WXDLLIMPEXP_BASE
const wxChar
* wxSysErrorMsg(unsigned long nErrCode
= 0);
615 // ----------------------------------------------------------------------------
616 // define wxLog<level>
617 // ----------------------------------------------------------------------------
619 #define DECLARE_LOG_FUNCTION(level) \
620 extern void WXDLLIMPEXP_BASE \
621 wxDoLog##level##Wchar(const wxChar *format, ...); \
622 extern void WXDLLIMPEXP_BASE \
623 wxDoLog##level##Utf8(const char *format, ...); \
624 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
625 1, (const wxFormatString&), \
626 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
627 DECLARE_LOG_FUNCTION_WATCOM(level) \
628 extern void WXDLLIMPEXP_BASE wxVLog##level(const wxString& format, \
632 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
633 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
634 // something too big for Borland C++ to handle
635 #define DECLARE_LOG_FUNCTION_WATCOM(level) \
636 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
637 1, (const wxString&), \
638 (wxFormatString(f1))) \
639 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
640 1, (const wxCStrData&), \
641 (wxFormatString(f1))) \
642 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
644 (wxFormatString(f1))) \
645 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
646 1, (const wchar_t*), \
647 (wxFormatString(f1)))
649 #define DECLARE_LOG_FUNCTION_WATCOM(level)
653 #define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
654 extern void expdecl wxDoLog##level##Wchar(argclass arg, \
655 const wxChar *format, ...); \
656 extern void expdecl wxDoLog##level##Utf8(argclass arg, \
657 const char *format, ...); \
658 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
659 2, (argclass, const wxFormatString&), \
660 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
661 DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
662 extern void expdecl wxVLog##level(argclass arg, \
663 const wxString& format, \
667 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
668 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
669 // something too big for Borland C++ to handle
670 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
671 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
672 2, (argclass, const wxString&), \
673 (f1, wxFormatString(f2))) \
674 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
675 2, (argclass, const wxCStrData&), \
676 (f1, wxFormatString(f2))) \
677 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
678 2, (argclass, const char*), \
679 (f1, wxFormatString(f2))) \
680 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
681 2, (argclass, const wchar_t*), \
682 (f1, wxFormatString(f2)))
684 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl)
690 #undef wxUSE_LOG_DEBUG
691 #define wxUSE_LOG_DEBUG 0
693 #undef wxUSE_LOG_TRACE
694 #define wxUSE_LOG_TRACE 0
697 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
698 #define WX_WATCOM_ONLY_CODE( x ) x
700 #define WX_WATCOM_ONLY_CODE( x )
703 #if defined(__WATCOMC__) || defined(__MINGW32__)
704 // Mingw has similar problem with wxLogSysError:
705 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x ) x
707 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x )
710 // log functions do nothing at all
711 #define DECLARE_LOG_FUNCTION(level) \
712 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxString&)) \
713 WX_WATCOM_ONLY_CODE( \
714 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const char*)) \
715 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wchar_t*)) \
716 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxCStrData&)) \
718 inline void wxVLog##level(const wxString& WXUNUSED(format), \
719 va_list WXUNUSED(argptr)) { } \
721 #define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
722 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxString&)) \
723 WX_WATCOM_OR_MINGW_ONLY_CODE( \
724 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const char*)) \
725 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wchar_t*)) \
726 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxCStrData&)) \
728 inline void wxVLog##level(argclass WXUNUSED(arg), \
729 const wxString& WXUNUSED(format), \
730 va_list WXUNUSED(argptr)) {}
732 // Empty Class to fake wxLogNull
733 class WXDLLIMPEXP_BASE wxLogNull
739 // Dummy macros to replace some functions.
740 #define wxSysErrorCode() (unsigned long)0
741 #define wxSysErrorMsg( X ) (const wxChar*)NULL
743 // Fake symbolic trace masks... for those that are used frequently
744 #define wxTRACE_OleCalls wxEmptyString // OLE interface calls
746 #endif // wxUSE_LOG/!wxUSE_LOG
748 #define DECLARE_LOG_FUNCTION2(level, argclass, arg) \
749 DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, WXDLLIMPEXP_BASE)
751 // VC6 produces a warning if we a macro expanding to nothing to
752 // DECLARE_LOG_FUNCTION2:
753 #if defined(__VISUALC__) && __VISUALC__ < 1300
754 #pragma warning(push)
755 // "not enough actual parameters for macro 'DECLARE_LOG_FUNCTION2_EXP'"
756 #pragma warning(disable:4003)
759 // a generic function for all levels (level is passes as parameter)
760 DECLARE_LOG_FUNCTION2(Generic
, wxLogLevel
, level
);
762 // one function per each level
763 DECLARE_LOG_FUNCTION(FatalError
);
764 DECLARE_LOG_FUNCTION(Error
);
765 DECLARE_LOG_FUNCTION(Warning
);
766 DECLARE_LOG_FUNCTION(Message
);
767 DECLARE_LOG_FUNCTION(Info
);
768 DECLARE_LOG_FUNCTION(Verbose
);
770 // this function sends the log message to the status line of the top level
771 // application frame, if any
772 DECLARE_LOG_FUNCTION(Status
);
775 // this one is the same as previous except that it allows to explicitly
776 class WXDLLIMPEXP_FWD_CORE wxFrame
;
777 // specify the frame to which the output should go
778 DECLARE_LOG_FUNCTION2_EXP(Status
, wxFrame
*, pFrame
, WXDLLIMPEXP_CORE
);
781 // additional one: as wxLogError, but also logs last system call error code
782 // and the corresponding error message if available
783 DECLARE_LOG_FUNCTION(SysError
);
785 // and another one which also takes the error code (for those broken APIs
786 // that don't set the errno (like registry APIs in Win32))
787 DECLARE_LOG_FUNCTION2(SysError
, long, lErrCode
);
789 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
790 DECLARE_LOG_FUNCTION2(SysError
, unsigned long, lErrCode
);
794 // debug functions can be completely disabled in optimized builds
796 // if these log functions are disabled, we prefer to define them as (empty)
797 // variadic macros as this completely removes them and their argument
798 // evaluation from the object code but if this is not supported by compiler we
799 // use empty inline functions instead (defining them as nothing would result in
800 // compiler warnings)
802 // note that making wxVLogDebug/Trace() themselves (empty inline) functions is
803 // a bad idea as some compilers are stupid enough to not inline even empty
804 // functions if their parameters are complicated enough, but by defining them
805 // as an empty inline function we ensure that even dumbest compilers optimise
808 // but Borland gives "W8019: Code has no effect" for wxLogNop() so we need
809 // to define it differently for it to avoid these warnings (same problem as
810 // with wxUnusedVar())
811 #define wxLogNop() { }
813 inline void wxLogNop() { }
817 DECLARE_LOG_FUNCTION(Debug
);
818 #else // !wxUSE_LOG_DEBUG
819 #define wxVLogDebug(fmt, valist) wxLogNop()
821 #ifdef HAVE_VARIADIC_MACROS
822 #define wxLogDebug(fmt, ...) wxLogNop()
823 #else // !HAVE_VARIADIC_MACROS
824 WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug
, 1, (const wxString
&))
826 #endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
829 // this version only logs the message if the mask had been added to the
830 // list of masks with AddTraceMask()
831 DECLARE_LOG_FUNCTION2(Trace
, const wxString
&, mask
);
833 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
834 DECLARE_LOG_FUNCTION2(Trace
, const char*, mask
);
835 DECLARE_LOG_FUNCTION2(Trace
, const wchar_t*, mask
);
838 // and this one does nothing if all of level bits are not set in
839 // wxLog::GetActive()->GetTraceMask() -- it's deprecated in favour of
840 // string identifiers
841 #if WXWIN_COMPATIBILITY_2_8
842 DECLARE_LOG_FUNCTION2(Trace
, wxTraceMask
, mask
);
844 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
845 DECLARE_LOG_FUNCTION2(Trace
, int, mask
);
847 #endif // WXWIN_COMPATIBILITY_2_8
849 #else // !wxUSE_LOG_TRACE
850 #define wxVLogTrace(mask, fmt, valist) wxLogNop()
852 #ifdef HAVE_VARIADIC_MACROS
853 #define wxLogTrace(mask, fmt, ...) wxLogNop()
854 #else // !HAVE_VARIADIC_MACROS
855 #if WXWIN_COMPATIBILITY_2_8
856 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (wxTraceMask
, const wxString
&))
858 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wxString
&, const wxString
&))
860 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
861 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const char*, const char*))
862 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wchar_t*, const wchar_t*))
864 #endif // HAVE_VARIADIC_MACROS/!HAVE_VARIADIC_MACROS
865 #endif // wxUSE_LOG_TRACE/!wxUSE_LOG_TRACE
867 #if defined(__VISUALC__) && __VISUALC__ < 1300
871 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
872 // i.e. without using wxMessageBox() for example because it could crash
873 void WXDLLIMPEXP_BASE
874 wxSafeShowMessage(const wxString
& title
, const wxString
& text
);
876 // ----------------------------------------------------------------------------
877 // debug only logging functions: use them with API name and error code
878 // ----------------------------------------------------------------------------
881 // make life easier for people using VC++ IDE: clicking on the message
882 // will take us immediately to the place of the failed API
884 #define wxLogApiError(api, rc) \
885 wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
886 __FILE__, __LINE__, api, \
887 (long)rc, wxSysErrorMsg(rc))
889 #define wxLogApiError(api, rc) \
890 wxLogDebug(wxT("In file %s at line %d: '%s' failed with ") \
891 wxT("error 0x%08lx (%s)."), \
892 __FILE__, __LINE__, api, \
893 (long)rc, wxSysErrorMsg(rc))
896 #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
898 #else // !wxUSE_LOG_DEBUG
899 #define wxLogApiError(api, err) wxLogNop()
900 #define wxLogLastError(api) wxLogNop()
901 #endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
903 // wxCocoa has additiional trace masks
904 #if defined(__WXCOCOA__)
905 #include "wx/cocoa/log.h"
908 #ifdef WX_WATCOM_ONLY_CODE
909 #undef WX_WATCOM_ONLY_CODE