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 enabled at all now?
168 static bool IsEnabled() { return ms_doLog
; }
170 // is logging at this level enabled?
171 static bool IsLevelEnabled(wxLogLevel level
)
172 { return IsEnabled() && level
<= ms_logLevel
; }
174 // change the flag state, return the previous one
175 static bool EnableLogging(bool doIt
= true)
176 { bool doLogOld
= ms_doLog
; ms_doLog
= doIt
; return doLogOld
; }
180 // flush shows all messages if they're not logged immediately (FILE
181 // and iostream logs don't need it, but wxGuiLog does to avoid showing
182 // 17 modal dialogs one after another)
183 virtual void Flush();
185 // flush the active target if any
186 static void FlushActive()
188 if ( !ms_suspendCount
)
190 wxLog
*log
= GetActiveTarget();
196 // only one sink is active at each moment
197 // get current log target, will call wxApp::CreateLogTarget() to
198 // create one if none exists
199 static wxLog
*GetActiveTarget();
201 // change log target, pLogger may be NULL
202 static wxLog
*SetActiveTarget(wxLog
*pLogger
);
204 // suspend the message flushing of the main target until the next call
205 // to Resume() - this is mainly for internal use (to prevent wxYield()
206 // from flashing the messages)
207 static void Suspend() { ms_suspendCount
++; }
209 // must be called for each Suspend()!
210 static void Resume() { ms_suspendCount
--; }
212 // functions controlling the default wxLog behaviour
213 // verbose mode is activated by standard command-line '--verbose'
215 static void SetVerbose(bool bVerbose
= true) { ms_bVerbose
= bVerbose
; }
217 // Set log level. Log messages with level > logLevel will not be logged.
218 static void SetLogLevel(wxLogLevel logLevel
) { ms_logLevel
= logLevel
; }
220 // should GetActiveTarget() try to create a new log object if the
222 static void DontCreateOnDemand();
224 // Make GetActiveTarget() create a new log object again.
225 static void DoCreateOnDemand();
227 // log the count of repeating messages instead of logging the messages
229 static void SetRepetitionCounting(bool bRepetCounting
= true)
230 { ms_bRepetCounting
= bRepetCounting
; }
232 // gets duplicate counting status
233 static bool GetRepetitionCounting() { return ms_bRepetCounting
; }
235 // add string trace mask
236 static void AddTraceMask(const wxString
& str
);
238 // add string trace mask
239 static void RemoveTraceMask(const wxString
& str
);
241 // remove all string trace masks
242 static void ClearTraceMasks();
244 // get string trace masks: note that this is MT-unsafe if other threads can
245 // call AddTraceMask() concurrently
246 static const wxArrayString
& GetTraceMasks() { return ms_aTraceMasks
; }
248 // sets the time stamp string format: this is used as strftime() format
249 // string for the log targets which add time stamps to the messages; set
250 // it to empty string to disable time stamping completely.
251 static void SetTimestamp(const wxString
& ts
) { ms_timestamp
= ts
; }
253 // disable time stamping of log messages
254 static void DisableTimestamp() { SetTimestamp(wxEmptyString
); }
259 // gets the verbose status
260 static bool GetVerbose() { return ms_bVerbose
; }
262 // is this trace mask in the list?
263 static bool IsAllowedTraceMask(const wxString
& mask
);
265 // return the current loglevel limit
266 static wxLogLevel
GetLogLevel() { return ms_logLevel
; }
268 // get the current timestamp format string (maybe empty)
269 static const wxString
& GetTimestamp() { return ms_timestamp
; }
273 // helpers: all functions in this section are mostly for internal use only,
274 // don't call them from your code even if they are not formally deprecated
276 // put the time stamp into the string if ms_timestamp != NULL (don't
277 // change it otherwise)
278 static void TimeStamp(wxString
*str
);
280 // these methods should only be called from derived classes DoLogRecord(),
281 // DoLogTextAtLevel() and DoLogText() implementations respectively and
282 // shouldn't be called directly, use logging functions instead
283 void LogRecord(wxLogLevel level
,
285 const wxLogRecordInfo
& info
)
287 DoLogRecord(level
, msg
, info
);
290 void LogTextAtLevel(wxLogLevel level
, const wxString
& msg
)
292 DoLogTextAtLevel(level
, msg
);
295 void LogText(const wxString
& msg
)
300 // this is a helper used by wxLogXXX() functions, don't call it directly
301 // and see DoLog() for function to overload in the derived classes
302 static void OnLog(wxLogLevel level
,
304 const wxLogRecordInfo
& info
);
306 // version called when no information about the location of the log record
307 // generation is available (but the time stamp is), it mainly exists for
308 // backwards compatibility, don't use it in new code
309 static void OnLog(wxLogLevel level
, const wxString
& msg
, time_t t
);
311 // a helper calling the above overload with current time
312 static void OnLog(wxLogLevel level
, const wxString
& msg
)
314 OnLog(level
, msg
, time(NULL
));
318 // this method exists for backwards compatibility only, don't use
319 bool HasPendingMessages() const { return true; }
321 #if WXWIN_COMPATIBILITY_2_6
322 // this function doesn't do anything any more, don't call it
324 static wxChar
*SetLogBuffer(wxChar
*, size_t = 0), return NULL
;
326 #endif // WXWIN_COMPATIBILITY_2_6
328 // don't use integer masks any more, use string trace masks instead
329 #if WXWIN_COMPATIBILITY_2_8
330 wxDEPRECATED_INLINE( static void SetTraceMask(wxTraceMask ulMask
),
331 ms_ulTraceMask
= ulMask
; )
332 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE( static wxTraceMask
GetTraceMask(),
333 return ms_ulTraceMask
; )
334 #endif // WXWIN_COMPATIBILITY_2_8
337 // the logging functions that can be overridden: DoLogRecord() is called
338 // for every "record", i.e. a unit of log output, to be logged and by
339 // default formats the message and passes it to DoLogTextAtLevel() which in
340 // turn passes it to DoLogText() by default
342 // override this method if you want to change message formatting or do
344 virtual void DoLogRecord(wxLogLevel level
,
346 const wxLogRecordInfo
& info
);
348 // override this method to redirect output to different channels depending
349 // on its level only; if even the level doesn't matter, override
350 // DoLogText() instead
351 virtual void DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
);
353 // this function is not pure virtual as it might not be needed if you do
354 // the logging in overridden DoLogRecord() or DoLogTextAtLevel() directly
355 // but if you do not override them in your derived class you must override
356 // this one as the default implementation of it simply asserts
357 virtual void DoLogText(const wxString
& msg
);
360 // the rest of the functions are for backwards compatibility only, don't
361 // use them in new code; if you're updating your existing code you need to
362 // switch to overriding DoLogRecord/Text() above (although as long as these
363 // functions exist, log classes using them will continue to work)
364 #if WXWIN_COMPATIBILITY_2_8
365 wxDEPRECATED_BUT_USED_INTERNALLY(
366 virtual void DoLog(wxLogLevel level
, const char *szString
, time_t t
)
369 wxDEPRECATED_BUT_USED_INTERNALLY(
370 virtual void DoLog(wxLogLevel level
, const wchar_t *wzString
, time_t t
)
373 // these shouldn't be used by new code
374 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
375 virtual void DoLogString(const char *WXUNUSED(szString
),
379 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
380 virtual void DoLogString(const wchar_t *WXUNUSED(wzString
),
383 #endif // WXWIN_COMPATIBILITY_2_8
386 // log a message indicating the number of times the previous message was
387 // repeated if previous repetition counter is strictly positive, does
388 // nothing otherwise; return the old value of repetition counter
389 unsigned LogLastRepeatIfNeeded();
392 // implement of LogLastRepeatIfNeeded(): it assumes that the
393 // caller had already locked GetPreviousLogCS()
394 unsigned LogLastRepeatIfNeededUnlocked();
399 // if true, don't log the same message multiple times, only log it once
400 // with the number of times it was repeated
401 static bool ms_bRepetCounting
;
403 static wxLog
*ms_pLogger
; // currently active log sink
404 static bool ms_doLog
; // false => all logging disabled
405 static bool ms_bAutoCreate
; // create new log targets on demand?
406 static bool ms_bVerbose
; // false => ignore LogInfo messages
408 static wxLogLevel ms_logLevel
; // limit logging to levels <= ms_logLevel
410 static size_t ms_suspendCount
; // if positive, logs are not flushed
412 // format string for strftime(), if empty, time stamping log messages is
414 static wxString ms_timestamp
;
416 #if WXWIN_COMPATIBILITY_2_8
417 static wxTraceMask ms_ulTraceMask
; // controls wxLogTrace behaviour
418 #endif // WXWIN_COMPATIBILITY_2_8
420 // currently enabled trace masks
421 static wxArrayString ms_aTraceMasks
;
424 // ----------------------------------------------------------------------------
425 // "trivial" derivations of wxLog
426 // ----------------------------------------------------------------------------
428 // log everything except for the debug/trace messages (which are passed to
429 // wxMessageOutputDebug) to a buffer
430 class WXDLLIMPEXP_BASE wxLogBuffer
: public wxLog
435 // get the string contents with all messages logged
436 const wxString
& GetBuffer() const { return m_str
; }
438 // show the buffer contents to the user in the best possible way (this uses
439 // wxMessageOutputMessageBox) and clear it
440 virtual void Flush();
443 virtual void DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
);
448 wxDECLARE_NO_COPY_CLASS(wxLogBuffer
);
452 // log everything to a "FILE *", stderr by default
453 class WXDLLIMPEXP_BASE wxLogStderr
: public wxLog
456 // redirect log output to a FILE
457 wxLogStderr(FILE *fp
= NULL
);
460 // implement sink function
461 virtual void DoLogText(const wxString
& msg
);
465 wxDECLARE_NO_COPY_CLASS(wxLogStderr
);
468 #if wxUSE_STD_IOSTREAM
470 // log everything to an "ostream", cerr by default
471 class WXDLLIMPEXP_BASE wxLogStream
: public wxLog
474 // redirect log output to an ostream
475 wxLogStream(wxSTD ostream
*ostr
= (wxSTD ostream
*) NULL
);
478 // implement sink function
479 virtual void DoLogText(const wxString
& msg
);
481 // using ptr here to avoid including <iostream.h> from this file
482 wxSTD ostream
*m_ostr
;
485 #endif // wxUSE_STD_IOSTREAM
487 // ----------------------------------------------------------------------------
488 // /dev/null log target: suppress logging until this object goes out of scope
489 // ----------------------------------------------------------------------------
497 // wxFile.Open() normally complains if file can't be opened, we don't
501 if ( !file.Open("bar") )
502 ... process error ourselves ...
504 // ~wxLogNull called, old log sink restored
507 class WXDLLIMPEXP_BASE wxLogNull
510 wxLogNull() : m_flagOld(wxLog::EnableLogging(false)) { }
511 ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld
); }
514 bool m_flagOld
; // the previous value of the wxLog::ms_doLog
517 // ----------------------------------------------------------------------------
518 // chaining log target: installs itself as a log target and passes all
519 // messages to the real log target given to it in the ctor but also forwards
520 // them to the previously active one
522 // note that you don't have to call SetActiveTarget() with this class, it
523 // does it itself in its ctor
524 // ----------------------------------------------------------------------------
526 class WXDLLIMPEXP_BASE wxLogChain
: public wxLog
529 wxLogChain(wxLog
*logger
);
530 virtual ~wxLogChain();
532 // change the new log target
533 void SetLog(wxLog
*logger
);
535 // this can be used to temporarily disable (and then reenable) passing
536 // messages to the old logger (by default we do pass them)
537 void PassMessages(bool bDoPass
) { m_bPassMessages
= bDoPass
; }
539 // are we passing the messages to the previous log target?
540 bool IsPassingMessages() const { return m_bPassMessages
; }
542 // return the previous log target (may be NULL)
543 wxLog
*GetOldLog() const { return m_logOld
; }
545 // override base class version to flush the old logger as well
546 virtual void Flush();
548 // call to avoid destroying the old log target
549 void DetachOldLog() { m_logOld
= NULL
; }
552 // pass the record to the old logger if needed
553 virtual void DoLogRecord(wxLogLevel level
,
555 const wxLogRecordInfo
& info
);
558 // the current log target
561 // the previous log target
564 // do we pass the messages to the old logger?
565 bool m_bPassMessages
;
567 wxDECLARE_NO_COPY_CLASS(wxLogChain
);
570 // a chain log target which uses itself as the new logger
572 #define wxLogPassThrough wxLogInterposer
574 class WXDLLIMPEXP_BASE wxLogInterposer
: public wxLogChain
580 wxDECLARE_NO_COPY_CLASS(wxLogInterposer
);
583 // a temporary interposer which doesn't destroy the old log target
584 // (calls DetachOldLog)
586 class WXDLLIMPEXP_BASE wxLogInterposerTemp
: public wxLogChain
589 wxLogInterposerTemp();
592 wxDECLARE_NO_COPY_CLASS(wxLogInterposerTemp
);
596 // include GUI log targets:
597 #include "wx/generic/logg.h"
600 // ============================================================================
602 // ============================================================================
604 // ----------------------------------------------------------------------------
605 // Log functions should be used by application instead of stdio, iostream &c
606 // for log messages for easy redirection
607 // ----------------------------------------------------------------------------
609 // ----------------------------------------------------------------------------
610 // get error code/error message from system in a portable way
611 // ----------------------------------------------------------------------------
613 // return the last system error code
614 WXDLLIMPEXP_BASE
unsigned long wxSysErrorCode();
616 // return the error message for given (or last if 0) error code
617 WXDLLIMPEXP_BASE
const wxChar
* wxSysErrorMsg(unsigned long nErrCode
= 0);
619 // ----------------------------------------------------------------------------
620 // define wxLog<level>
621 // ----------------------------------------------------------------------------
623 #define DECLARE_LOG_FUNCTION(level) \
624 extern void WXDLLIMPEXP_BASE \
625 wxDoLog##level##Wchar(const wxChar *format, ...); \
626 extern void WXDLLIMPEXP_BASE \
627 wxDoLog##level##Utf8(const char *format, ...); \
628 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
629 1, (const wxFormatString&), \
630 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
631 DECLARE_LOG_FUNCTION_WATCOM(level) \
632 extern void WXDLLIMPEXP_BASE wxVLog##level(const wxString& format, \
636 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
637 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
638 // something too big for Borland C++ to handle
639 #define DECLARE_LOG_FUNCTION_WATCOM(level) \
640 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
641 1, (const wxString&), \
642 (wxFormatString(f1))) \
643 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
644 1, (const wxCStrData&), \
645 (wxFormatString(f1))) \
646 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
648 (wxFormatString(f1))) \
649 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
650 1, (const wchar_t*), \
651 (wxFormatString(f1)))
653 #define DECLARE_LOG_FUNCTION_WATCOM(level)
657 #define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
658 extern void expdecl wxDoLog##level##Wchar(argclass arg, \
659 const wxChar *format, ...); \
660 extern void expdecl wxDoLog##level##Utf8(argclass arg, \
661 const char *format, ...); \
662 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
663 2, (argclass, const wxFormatString&), \
664 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
665 DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
666 extern void expdecl wxVLog##level(argclass arg, \
667 const wxString& format, \
671 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
672 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
673 // something too big for Borland C++ to handle
674 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
675 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
676 2, (argclass, const wxString&), \
677 (f1, wxFormatString(f2))) \
678 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
679 2, (argclass, const wxCStrData&), \
680 (f1, wxFormatString(f2))) \
681 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
682 2, (argclass, const char*), \
683 (f1, wxFormatString(f2))) \
684 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
685 2, (argclass, const wchar_t*), \
686 (f1, wxFormatString(f2)))
688 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl)
694 #undef wxUSE_LOG_DEBUG
695 #define wxUSE_LOG_DEBUG 0
697 #undef wxUSE_LOG_TRACE
698 #define wxUSE_LOG_TRACE 0
701 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
702 #define WX_WATCOM_ONLY_CODE( x ) x
704 #define WX_WATCOM_ONLY_CODE( x )
707 #if defined(__WATCOMC__) || defined(__MINGW32__)
708 // Mingw has similar problem with wxLogSysError:
709 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x ) x
711 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x )
714 // log functions do nothing at all
715 #define DECLARE_LOG_FUNCTION(level) \
716 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxString&)) \
717 WX_WATCOM_ONLY_CODE( \
718 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const char*)) \
719 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wchar_t*)) \
720 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxCStrData&)) \
722 inline void wxVLog##level(const wxString& WXUNUSED(format), \
723 va_list WXUNUSED(argptr)) { } \
725 #define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
726 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxString&)) \
727 WX_WATCOM_OR_MINGW_ONLY_CODE( \
728 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const char*)) \
729 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wchar_t*)) \
730 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxCStrData&)) \
732 inline void wxVLog##level(argclass WXUNUSED(arg), \
733 const wxString& WXUNUSED(format), \
734 va_list WXUNUSED(argptr)) {}
736 // Empty Class to fake wxLogNull
737 class WXDLLIMPEXP_BASE wxLogNull
743 // Dummy macros to replace some functions.
744 #define wxSysErrorCode() (unsigned long)0
745 #define wxSysErrorMsg( X ) (const wxChar*)NULL
747 // Fake symbolic trace masks... for those that are used frequently
748 #define wxTRACE_OleCalls wxEmptyString // OLE interface calls
750 #endif // wxUSE_LOG/!wxUSE_LOG
752 #define DECLARE_LOG_FUNCTION2(level, argclass, arg) \
753 DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, WXDLLIMPEXP_BASE)
755 // VC6 produces a warning if we a macro expanding to nothing to
756 // DECLARE_LOG_FUNCTION2:
757 #if defined(__VISUALC__) && __VISUALC__ < 1300
758 #pragma warning(push)
759 // "not enough actual parameters for macro 'DECLARE_LOG_FUNCTION2_EXP'"
760 #pragma warning(disable:4003)
763 // a generic function for all levels (level is passes as parameter)
764 DECLARE_LOG_FUNCTION2(Generic
, wxLogLevel
, level
);
766 // one function per each level
767 DECLARE_LOG_FUNCTION(FatalError
);
768 DECLARE_LOG_FUNCTION(Error
);
769 DECLARE_LOG_FUNCTION(Warning
);
770 DECLARE_LOG_FUNCTION(Message
);
771 DECLARE_LOG_FUNCTION(Info
);
772 DECLARE_LOG_FUNCTION(Verbose
);
774 // this function sends the log message to the status line of the top level
775 // application frame, if any
776 DECLARE_LOG_FUNCTION(Status
);
779 // this one is the same as previous except that it allows to explicitly
780 class WXDLLIMPEXP_FWD_CORE wxFrame
;
781 // specify the frame to which the output should go
782 DECLARE_LOG_FUNCTION2_EXP(Status
, wxFrame
*, pFrame
, WXDLLIMPEXP_CORE
);
785 // additional one: as wxLogError, but also logs last system call error code
786 // and the corresponding error message if available
787 DECLARE_LOG_FUNCTION(SysError
);
789 // and another one which also takes the error code (for those broken APIs
790 // that don't set the errno (like registry APIs in Win32))
791 DECLARE_LOG_FUNCTION2(SysError
, long, lErrCode
);
793 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
794 DECLARE_LOG_FUNCTION2(SysError
, unsigned long, lErrCode
);
798 // debug functions can be completely disabled in optimized builds
800 // if these log functions are disabled, we prefer to define them as (empty)
801 // variadic macros as this completely removes them and their argument
802 // evaluation from the object code but if this is not supported by compiler we
803 // use empty inline functions instead (defining them as nothing would result in
804 // compiler warnings)
806 // note that making wxVLogDebug/Trace() themselves (empty inline) functions is
807 // a bad idea as some compilers are stupid enough to not inline even empty
808 // functions if their parameters are complicated enough, but by defining them
809 // as an empty inline function we ensure that even dumbest compilers optimise
812 // but Borland gives "W8019: Code has no effect" for wxLogNop() so we need
813 // to define it differently for it to avoid these warnings (same problem as
814 // with wxUnusedVar())
815 #define wxLogNop() { }
817 inline void wxLogNop() { }
821 DECLARE_LOG_FUNCTION(Debug
);
822 #else // !wxUSE_LOG_DEBUG
823 #define wxVLogDebug(fmt, valist) wxLogNop()
825 #ifdef HAVE_VARIADIC_MACROS
826 #define wxLogDebug(fmt, ...) wxLogNop()
827 #else // !HAVE_VARIADIC_MACROS
828 WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug
, 1, (const wxString
&))
830 #endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
833 // this version only logs the message if the mask had been added to the
834 // list of masks with AddTraceMask()
835 DECLARE_LOG_FUNCTION2(Trace
, const wxString
&, mask
);
837 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
838 DECLARE_LOG_FUNCTION2(Trace
, const char*, mask
);
839 DECLARE_LOG_FUNCTION2(Trace
, const wchar_t*, mask
);
842 // and this one does nothing if all of level bits are not set in
843 // wxLog::GetActive()->GetTraceMask() -- it's deprecated in favour of
844 // string identifiers
845 #if WXWIN_COMPATIBILITY_2_8
846 DECLARE_LOG_FUNCTION2(Trace
, wxTraceMask
, mask
);
848 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
849 DECLARE_LOG_FUNCTION2(Trace
, int, mask
);
851 #endif // WXWIN_COMPATIBILITY_2_8
853 #else // !wxUSE_LOG_TRACE
854 #define wxVLogTrace(mask, fmt, valist) wxLogNop()
856 #ifdef HAVE_VARIADIC_MACROS
857 #define wxLogTrace(mask, fmt, ...) wxLogNop()
858 #else // !HAVE_VARIADIC_MACROS
859 #if WXWIN_COMPATIBILITY_2_8
860 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (wxTraceMask
, const wxString
&))
862 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wxString
&, const wxString
&))
864 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
865 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const char*, const char*))
866 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wchar_t*, const wchar_t*))
868 #endif // HAVE_VARIADIC_MACROS/!HAVE_VARIADIC_MACROS
869 #endif // wxUSE_LOG_TRACE/!wxUSE_LOG_TRACE
871 #if defined(__VISUALC__) && __VISUALC__ < 1300
875 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
876 // i.e. without using wxMessageBox() for example because it could crash
877 void WXDLLIMPEXP_BASE
878 wxSafeShowMessage(const wxString
& title
, const wxString
& text
);
880 // ----------------------------------------------------------------------------
881 // debug only logging functions: use them with API name and error code
882 // ----------------------------------------------------------------------------
885 // make life easier for people using VC++ IDE: clicking on the message
886 // will take us immediately to the place of the failed API
888 #define wxLogApiError(api, rc) \
889 wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
890 __FILE__, __LINE__, api, \
891 (long)rc, wxSysErrorMsg(rc))
893 #define wxLogApiError(api, rc) \
894 wxLogDebug(wxT("In file %s at line %d: '%s' failed with ") \
895 wxT("error 0x%08lx (%s)."), \
896 __FILE__, __LINE__, api, \
897 (long)rc, wxSysErrorMsg(rc))
900 #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
902 #else // !wxUSE_LOG_DEBUG
903 #define wxLogApiError(api, err) wxLogNop()
904 #define wxLogLastError(api) wxLogNop()
905 #endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
907 // wxCocoa has additiional trace masks
908 #if defined(__WXCOCOA__)
909 #include "wx/cocoa/log.h"
912 #ifdef WX_WATCOM_ONLY_CODE
913 #undef WX_WATCOM_ONLY_CODE