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"
46 // ----------------------------------------------------------------------------
47 // forward declarations
48 // ----------------------------------------------------------------------------
50 class WXDLLIMPEXP_FWD_BASE wxObject
;
53 class WXDLLIMPEXP_FWD_CORE wxFrame
;
58 #include "wx/arrstr.h"
62 #include <time.h> // for time_t
64 #endif // ! __WXPALMOS5__
66 #include "wx/dynarray.h"
67 #include "wx/hashmap.h"
70 #include "wx/thread.h"
71 #endif // wxUSE_THREADS
73 // wxUSE_LOG_DEBUG enables the debug log messages
74 #ifndef wxUSE_LOG_DEBUG
76 #define wxUSE_LOG_DEBUG 1
77 #else // !wxDEBUG_LEVEL
78 #define wxUSE_LOG_DEBUG 0
82 // wxUSE_LOG_TRACE enables the trace messages, they are disabled by default
83 #ifndef wxUSE_LOG_TRACE
85 #define wxUSE_LOG_TRACE 1
86 #else // !wxDEBUG_LEVEL
87 #define wxUSE_LOG_TRACE 0
89 #endif // wxUSE_LOG_TRACE
91 // wxLOG_COMPONENT identifies the component which generated the log record and
92 // can be #define'd to a user-defined value when compiling the user code to use
93 // component-based filtering (see wxLog::SetComponentLevel())
94 #ifndef wxLOG_COMPONENT
95 // this is a variable and not a macro in order to allow the user code to
96 // just #define wxLOG_COMPONENT without #undef'ining it first
97 extern WXDLLIMPEXP_DATA_BASE(const char *) wxLOG_COMPONENT
;
100 #define wxLOG_COMPONENT "wx"
104 // ----------------------------------------------------------------------------
106 // ----------------------------------------------------------------------------
108 // different standard log levels (you may also define your own)
109 enum wxLogLevelValues
111 wxLOG_FatalError
, // program can't continue, abort immediately
112 wxLOG_Error
, // a serious error, user must be informed about it
113 wxLOG_Warning
, // user is normally informed about it but may be ignored
114 wxLOG_Message
, // normal message (i.e. normal output of a non GUI app)
115 wxLOG_Status
, // informational: might go to the status line of GUI app
116 wxLOG_Info
, // informational message (a.k.a. 'Verbose')
117 wxLOG_Debug
, // never shown to the user, disabled in release mode
118 wxLOG_Trace
, // trace messages are also only enabled in debug mode
119 wxLOG_Progress
, // used for progress indicator (not yet)
120 wxLOG_User
= 100, // user defined levels start here
124 // symbolic trace masks - wxLogTrace("foo", "some trace message...") will be
125 // discarded unless the string "foo" has been added to the list of allowed
126 // ones with AddTraceMask()
128 #define wxTRACE_MemAlloc wxT("memalloc") // trace memory allocation (new/delete)
129 #define wxTRACE_Messages wxT("messages") // trace window messages/X callbacks
130 #define wxTRACE_ResAlloc wxT("resalloc") // trace GDI resource allocation
131 #define wxTRACE_RefCount wxT("refcount") // trace various ref counting operations
134 #define wxTRACE_OleCalls wxT("ole") // OLE interface calls
137 #include "wx/iosfwrap.h"
139 // ----------------------------------------------------------------------------
140 // information about a log record, i.e. unit of log output
141 // ----------------------------------------------------------------------------
143 class wxLogRecordInfo
146 // default ctor creates an uninitialized object
149 memset(this, 0, sizeof(*this));
152 // normal ctor, used by wxLogger specifies the location of the log
153 // statement; its time stamp and thread id are set up here
154 wxLogRecordInfo(const char *filename_
,
157 const char *component_
)
159 filename
= filename_
;
162 component
= component_
;
164 timestamp
= time(NULL
);
167 threadId
= wxThread::GetCurrentId();
168 #endif // wxUSE_THREADS
173 // we need to define copy ctor and assignment operator because of m_data
174 wxLogRecordInfo(const wxLogRecordInfo
& other
)
179 wxLogRecordInfo
& operator=(const wxLogRecordInfo
& other
)
181 if ( &other
!= this )
190 // dtor is non-virtual, this class is not meant to be derived from
197 // the file name and line number of the file where the log record was
198 // generated, if available or NULL and 0 otherwise
199 const char *filename
;
202 // the name of the function where the log record was generated (may be NULL
203 // if the compiler doesn't support __FUNCTION__)
206 // the name of the component which generated this message, may be NULL if
207 // not set (i.e. wxLOG_COMPONENT not defined)
208 const char *component
;
210 // time of record generation
214 // id of the thread which logged this record
215 wxThreadIdType threadId
;
216 #endif // wxUSE_THREADS
219 // store an arbitrary value in this record context
221 // wxWidgets always uses keys starting with "wx.", e.g. "wx.sys_error"
222 void StoreValue(const wxString
& key
, wxUIntPtr val
)
225 m_data
= new ExtraData
;
227 m_data
->numValues
[key
] = val
;
230 void StoreValue(const wxString
& key
, const wxString
& val
)
233 m_data
= new ExtraData
;
235 m_data
->strValues
[key
] = val
;
239 // these functions retrieve the value of either numeric or string key,
240 // return false if not found
241 bool GetNumValue(const wxString
& key
, wxUIntPtr
*val
) const
246 wxStringToNumHashMap::const_iterator it
= m_data
->numValues
.find(key
);
247 if ( it
== m_data
->numValues
.end() )
255 bool GetStrValue(const wxString
& key
, wxString
*val
) const
260 wxStringToStringHashMap::const_iterator it
= m_data
->strValues
.find(key
);
261 if ( it
== m_data
->strValues
.end() )
270 void Copy(const wxLogRecordInfo
& other
)
272 memcpy(this, &other
, sizeof(*this));
274 m_data
= new ExtraData(*other
.m_data
);
277 // extra data associated with the log record: this is completely optional
278 // and can be used to pass information from the log function to the log
279 // sink (e.g. wxLogSysError() uses this to pass the error code)
282 wxStringToNumHashMap numValues
;
283 wxStringToStringHashMap strValues
;
290 #define wxLOG_KEY_TRACE_MASK "wx.trace_mask"
292 // ----------------------------------------------------------------------------
293 // log record: a unit of log output
294 // ----------------------------------------------------------------------------
298 wxLogRecord(wxLogLevel level_
,
299 const wxString
& msg_
,
300 const wxLogRecordInfo
& info_
)
309 wxLogRecordInfo info
;
312 // ----------------------------------------------------------------------------
313 // Derive from this class to customize format of log messages.
314 // ----------------------------------------------------------------------------
316 class WXDLLIMPEXP_BASE wxLogFormatter
319 // Default constructor.
322 // Trivial but virtual destructor for the base class.
323 virtual ~wxLogFormatter() { }
326 // Override this method to implement custom formatting of the given log
327 // record. The default implementation simply prepends a level-dependent
328 // prefix to the message and optionally adds a time stamp.
329 virtual wxString
Format(wxLogLevel level
,
331 const wxLogRecordInfo
& info
) const;
334 // Override this method to change just the time stamp formatting. It is
335 // called by default Format() implementation.
336 virtual wxString
FormatTime(time_t t
) const;
340 // ----------------------------------------------------------------------------
341 // derive from this class to redirect (or suppress, or ...) log messages
342 // normally, only a single instance of this class exists but it's not enforced
343 // ----------------------------------------------------------------------------
345 class WXDLLIMPEXP_BASE wxLog
349 wxLog() : m_formatter(new wxLogFormatter
) { }
351 // make dtor virtual for all derived classes
355 // log messages selection
356 // ----------------------
358 // these functions allow to completely disable all log messages or disable
359 // log messages at level less important than specified for the current
362 // is logging enabled at all now?
363 static bool IsEnabled()
366 if ( !wxThread::IsMain() )
367 return IsThreadLoggingEnabled();
368 #endif // wxUSE_THREADS
373 // change the flag state, return the previous one
374 static bool EnableLogging(bool enable
= true)
377 if ( !wxThread::IsMain() )
378 return EnableThreadLogging(enable
);
379 #endif // wxUSE_THREADS
381 bool doLogOld
= ms_doLog
;
386 // return the current global log level
387 static wxLogLevel
GetLogLevel() { return ms_logLevel
; }
389 // set global log level: messages with level > logLevel will not be logged
390 static void SetLogLevel(wxLogLevel logLevel
) { ms_logLevel
= logLevel
; }
392 // set the log level for the given component
393 static void SetComponentLevel(const wxString
& component
, wxLogLevel level
);
395 // return the effective log level for this component, falling back to
396 // parent component and to the default global log level if necessary
398 // NB: component argument is passed by value and not const reference in an
399 // attempt to encourage compiler to avoid an extra copy: as we modify
400 // the component internally, we'd create one anyhow and like this it
401 // can be avoided if the string is a temporary anyhow
402 static wxLogLevel
GetComponentLevel(wxString component
);
405 // is logging of messages from this component enabled at this level?
407 // usually always called with wxLOG_COMPONENT as second argument
408 static bool IsLevelEnabled(wxLogLevel level
, wxString component
)
410 return IsEnabled() && level
<= GetComponentLevel(component
);
414 // enable/disable messages at wxLOG_Verbose level (only relevant if the
415 // current log level is greater or equal to it)
417 // notice that verbose mode can be activated by the standard command-line
418 // '--verbose' option
419 static void SetVerbose(bool bVerbose
= true) { ms_bVerbose
= bVerbose
; }
421 // check if verbose messages are enabled
422 static bool GetVerbose() { return ms_bVerbose
; }
428 // flush shows all messages if they're not logged immediately (FILE
429 // and iostream logs don't need it, but wxLogGui does to avoid showing
430 // 17 modal dialogs one after another)
431 virtual void Flush();
433 // flush the active target if any and also output any pending messages from
434 // background threads
435 static void FlushActive();
437 // only one sink is active at each moment get current log target, will call
438 // wxAppTraits::CreateLogTarget() to create one if none exists
439 static wxLog
*GetActiveTarget();
441 // change log target, logger may be NULL
442 static wxLog
*SetActiveTarget(wxLog
*logger
);
445 // change log target for the current thread only, shouldn't be called from
446 // the main thread as it doesn't use thread-specific log target
447 static wxLog
*SetThreadActiveTarget(wxLog
*logger
);
448 #endif // wxUSE_THREADS
450 // suspend the message flushing of the main target until the next call
451 // to Resume() - this is mainly for internal use (to prevent wxYield()
452 // from flashing the messages)
453 static void Suspend() { ms_suspendCount
++; }
455 // must be called for each Suspend()!
456 static void Resume() { ms_suspendCount
--; }
458 // should GetActiveTarget() try to create a new log object if the
460 static void DontCreateOnDemand();
462 // Make GetActiveTarget() create a new log object again.
463 static void DoCreateOnDemand();
465 // log the count of repeating messages instead of logging the messages
467 static void SetRepetitionCounting(bool bRepetCounting
= true)
468 { ms_bRepetCounting
= bRepetCounting
; }
470 // gets duplicate counting status
471 static bool GetRepetitionCounting() { return ms_bRepetCounting
; }
473 // add string trace mask
474 static void AddTraceMask(const wxString
& str
);
476 // add string trace mask
477 static void RemoveTraceMask(const wxString
& str
);
479 // remove all string trace masks
480 static void ClearTraceMasks();
482 // get string trace masks: note that this is MT-unsafe if other threads can
483 // call AddTraceMask() concurrently
484 static const wxArrayString
& GetTraceMasks();
486 // is this trace mask in the list?
487 static bool IsAllowedTraceMask(const wxString
& mask
);
493 // Change wxLogFormatter object used by wxLog to format the log messages.
495 // wxLog takes ownership of the pointer passed in but the caller is
496 // responsible for deleting the returned pointer.
497 wxLogFormatter
* SetFormatter(wxLogFormatter
* formatter
);
500 // All the time stamp related functions below only work when the default
501 // wxLogFormatter is being used. Defining a custom formatter overrides them
502 // as it could use its own time stamp format or format messages without
503 // using time stamp at all.
506 // sets the time stamp string format: this is used as strftime() format
507 // string for the log targets which add time stamps to the messages; set
508 // it to empty string to disable time stamping completely.
509 static void SetTimestamp(const wxString
& ts
) { ms_timestamp
= ts
; }
511 // disable time stamping of log messages
512 static void DisableTimestamp() { SetTimestamp(wxEmptyString
); }
515 // get the current timestamp format string (maybe empty)
516 static const wxString
& GetTimestamp() { return ms_timestamp
; }
520 // helpers: all functions in this section are mostly for internal use only,
521 // don't call them from your code even if they are not formally deprecated
523 // put the time stamp into the string if ms_timestamp is not empty (don't
524 // change it otherwise); the first overload uses the current time.
525 static void TimeStamp(wxString
*str
);
526 static void TimeStamp(wxString
*str
, time_t t
);
528 // these methods should only be called from derived classes DoLogRecord(),
529 // DoLogTextAtLevel() and DoLogText() implementations respectively and
530 // shouldn't be called directly, use logging functions instead
531 void LogRecord(wxLogLevel level
,
533 const wxLogRecordInfo
& info
)
535 DoLogRecord(level
, msg
, info
);
538 void LogTextAtLevel(wxLogLevel level
, const wxString
& msg
)
540 DoLogTextAtLevel(level
, msg
);
543 void LogText(const wxString
& msg
)
548 // this is a helper used by wxLogXXX() functions, don't call it directly
549 // and see DoLog() for function to overload in the derived classes
550 static void OnLog(wxLogLevel level
,
552 const wxLogRecordInfo
& info
);
554 // version called when no information about the location of the log record
555 // generation is available (but the time stamp is), it mainly exists for
556 // backwards compatibility, don't use it in new code
557 static void OnLog(wxLogLevel level
, const wxString
& msg
, time_t t
);
559 // a helper calling the above overload with current time
560 static void OnLog(wxLogLevel level
, const wxString
& msg
)
562 OnLog(level
, msg
, time(NULL
));
566 // this method exists for backwards compatibility only, don't use
567 bool HasPendingMessages() const { return true; }
569 #if WXWIN_COMPATIBILITY_2_6
570 // this function doesn't do anything any more, don't call it
571 static wxDEPRECATED_INLINE(
572 wxChar
*SetLogBuffer(wxChar
*, size_t = 0), return NULL
;
574 #endif // WXWIN_COMPATIBILITY_2_6
576 // don't use integer masks any more, use string trace masks instead
577 #if WXWIN_COMPATIBILITY_2_8
578 static wxDEPRECATED_INLINE( void SetTraceMask(wxTraceMask ulMask
),
579 ms_ulTraceMask
= ulMask
; )
581 // this one can't be marked deprecated as it's used in our own wxLogger
582 // below but it still is deprecated and shouldn't be used
583 static wxTraceMask
GetTraceMask() { return ms_ulTraceMask
; }
584 #endif // WXWIN_COMPATIBILITY_2_8
587 // the logging functions that can be overridden: DoLogRecord() is called
588 // for every "record", i.e. a unit of log output, to be logged and by
589 // default formats the message and passes it to DoLogTextAtLevel() which in
590 // turn passes it to DoLogText() by default
592 // override this method if you want to change message formatting or do
594 virtual void DoLogRecord(wxLogLevel level
,
596 const wxLogRecordInfo
& info
);
598 // override this method to redirect output to different channels depending
599 // on its level only; if even the level doesn't matter, override
600 // DoLogText() instead
601 virtual void DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
);
603 // this function is not pure virtual as it might not be needed if you do
604 // the logging in overridden DoLogRecord() or DoLogTextAtLevel() directly
605 // but if you do not override them in your derived class you must override
606 // this one as the default implementation of it simply asserts
607 virtual void DoLogText(const wxString
& msg
);
610 // the rest of the functions are for backwards compatibility only, don't
611 // use them in new code; if you're updating your existing code you need to
612 // switch to overriding DoLogRecord/Text() above (although as long as these
613 // functions exist, log classes using them will continue to work)
614 #if WXWIN_COMPATIBILITY_2_8
615 wxDEPRECATED_BUT_USED_INTERNALLY(
616 virtual void DoLog(wxLogLevel level
, const char *szString
, time_t t
)
619 wxDEPRECATED_BUT_USED_INTERNALLY(
620 virtual void DoLog(wxLogLevel level
, const wchar_t *wzString
, time_t t
)
623 // these shouldn't be used by new code
624 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
625 virtual void DoLogString(const char *WXUNUSED(szString
),
627 wxEMPTY_PARAMETER_VALUE
630 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
631 virtual void DoLogString(const wchar_t *WXUNUSED(wzString
),
633 wxEMPTY_PARAMETER_VALUE
635 #endif // WXWIN_COMPATIBILITY_2_8
638 // log a message indicating the number of times the previous message was
639 // repeated if previous repetition counter is strictly positive, does
640 // nothing otherwise; return the old value of repetition counter
641 unsigned LogLastRepeatIfNeeded();
645 // called from FlushActive() to really log any buffered messages logged
646 // from the other threads
647 void FlushThreadMessages();
649 // these functions are called for non-main thread only by IsEnabled() and
650 // EnableLogging() respectively
651 static bool IsThreadLoggingEnabled();
652 static bool EnableThreadLogging(bool enable
= true);
653 #endif // wxUSE_THREADS
655 // get the active log target for the main thread, auto-creating it if
658 // this is called from GetActiveTarget() and OnLog() when they're called
659 // from the main thread
660 static wxLog
*GetMainThreadActiveTarget();
662 // called from OnLog() if it's called from the main thread or if we have a
663 // (presumably MT-safe) thread-specific logger and by FlushThreadMessages()
664 // when it plays back the buffered messages logged from the other threads
665 void CallDoLogNow(wxLogLevel level
,
667 const wxLogRecordInfo
& info
);
673 wxLogFormatter
*m_formatter
; // We own this pointer.
679 // if true, don't log the same message multiple times, only log it once
680 // with the number of times it was repeated
681 static bool ms_bRepetCounting
;
683 static wxLog
*ms_pLogger
; // currently active log sink
684 static bool ms_doLog
; // false => all logging disabled
685 static bool ms_bAutoCreate
; // create new log targets on demand?
686 static bool ms_bVerbose
; // false => ignore LogInfo messages
688 static wxLogLevel ms_logLevel
; // limit logging to levels <= ms_logLevel
690 static size_t ms_suspendCount
; // if positive, logs are not flushed
692 // format string for strftime(), if empty, time stamping log messages is
694 static wxString ms_timestamp
;
696 #if WXWIN_COMPATIBILITY_2_8
697 static wxTraceMask ms_ulTraceMask
; // controls wxLogTrace behaviour
698 #endif // WXWIN_COMPATIBILITY_2_8
701 // ----------------------------------------------------------------------------
702 // "trivial" derivations of wxLog
703 // ----------------------------------------------------------------------------
705 // log everything except for the debug/trace messages (which are passed to
706 // wxMessageOutputDebug) to a buffer
707 class WXDLLIMPEXP_BASE wxLogBuffer
: public wxLog
712 // get the string contents with all messages logged
713 const wxString
& GetBuffer() const { return m_str
; }
715 // show the buffer contents to the user in the best possible way (this uses
716 // wxMessageOutputMessageBox) and clear it
717 virtual void Flush();
720 virtual void DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
);
725 wxDECLARE_NO_COPY_CLASS(wxLogBuffer
);
729 // log everything to a "FILE *", stderr by default
730 class WXDLLIMPEXP_BASE wxLogStderr
: public wxLog
733 // redirect log output to a FILE
734 wxLogStderr(FILE *fp
= NULL
);
737 // implement sink function
738 virtual void DoLogText(const wxString
& msg
);
742 wxDECLARE_NO_COPY_CLASS(wxLogStderr
);
745 #if wxUSE_STD_IOSTREAM
747 // log everything to an "ostream", cerr by default
748 class WXDLLIMPEXP_BASE wxLogStream
: public wxLog
751 // redirect log output to an ostream
752 wxLogStream(wxSTD ostream
*ostr
= (wxSTD ostream
*) NULL
);
755 // implement sink function
756 virtual void DoLogText(const wxString
& msg
);
758 // using ptr here to avoid including <iostream.h> from this file
759 wxSTD ostream
*m_ostr
;
762 #endif // wxUSE_STD_IOSTREAM
764 // ----------------------------------------------------------------------------
765 // /dev/null log target: suppress logging until this object goes out of scope
766 // ----------------------------------------------------------------------------
774 // wxFile.Open() normally complains if file can't be opened, we don't
778 if ( !file.Open("bar") )
779 ... process error ourselves ...
781 // ~wxLogNull called, old log sink restored
784 class WXDLLIMPEXP_BASE wxLogNull
787 wxLogNull() : m_flagOld(wxLog::EnableLogging(false)) { }
788 ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld
); }
791 bool m_flagOld
; // the previous value of the wxLog::ms_doLog
794 // ----------------------------------------------------------------------------
795 // chaining log target: installs itself as a log target and passes all
796 // messages to the real log target given to it in the ctor but also forwards
797 // them to the previously active one
799 // note that you don't have to call SetActiveTarget() with this class, it
800 // does it itself in its ctor
801 // ----------------------------------------------------------------------------
803 class WXDLLIMPEXP_BASE wxLogChain
: public wxLog
806 wxLogChain(wxLog
*logger
);
807 virtual ~wxLogChain();
809 // change the new log target
810 void SetLog(wxLog
*logger
);
812 // this can be used to temporarily disable (and then reenable) passing
813 // messages to the old logger (by default we do pass them)
814 void PassMessages(bool bDoPass
) { m_bPassMessages
= bDoPass
; }
816 // are we passing the messages to the previous log target?
817 bool IsPassingMessages() const { return m_bPassMessages
; }
819 // return the previous log target (may be NULL)
820 wxLog
*GetOldLog() const { return m_logOld
; }
822 // override base class version to flush the old logger as well
823 virtual void Flush();
825 // call to avoid destroying the old log target
826 void DetachOldLog() { m_logOld
= NULL
; }
829 // pass the record to the old logger if needed
830 virtual void DoLogRecord(wxLogLevel level
,
832 const wxLogRecordInfo
& info
);
835 // the current log target
838 // the previous log target
841 // do we pass the messages to the old logger?
842 bool m_bPassMessages
;
844 wxDECLARE_NO_COPY_CLASS(wxLogChain
);
847 // a chain log target which uses itself as the new logger
849 #define wxLogPassThrough wxLogInterposer
851 class WXDLLIMPEXP_BASE wxLogInterposer
: public wxLogChain
857 wxDECLARE_NO_COPY_CLASS(wxLogInterposer
);
860 // a temporary interposer which doesn't destroy the old log target
861 // (calls DetachOldLog)
863 class WXDLLIMPEXP_BASE wxLogInterposerTemp
: public wxLogChain
866 wxLogInterposerTemp();
869 wxDECLARE_NO_COPY_CLASS(wxLogInterposerTemp
);
873 // include GUI log targets:
874 #include "wx/generic/logg.h"
877 // ----------------------------------------------------------------------------
879 // ----------------------------------------------------------------------------
881 // wxLogger is a helper class used by wxLogXXX() functions implementation,
882 // don't use it directly as it's experimental and subject to change (OTOH it
883 // might become public in the future if it's deemed to be useful enough)
885 // contains information about the context from which a log message originates
886 // and provides Log() vararg method which forwards to wxLog::OnLog() and passes
887 // this context to it
891 // ctor takes the basic information about the log record
892 wxLogger(wxLogLevel level
,
893 const char *filename
,
896 const char *component
)
898 m_info(filename
, line
, func
, component
)
902 // store extra data in our log record and return this object itself (so
903 // that further calls to its functions could be chained)
904 template <typename T
>
905 wxLogger
& Store(const wxString
& key
, T val
)
907 m_info
.StoreValue(key
, val
);
911 // hack for "overloaded" wxLogXXX() functions: calling this method
912 // indicates that we may have an extra first argument preceding the format
913 // string and that if we do have it, we should store it in m_info using the
914 // given key (while by default 0 value will be used)
915 wxLogger
& MaybeStore(const wxString
& key
, wxUIntPtr value
= 0)
917 wxASSERT_MSG( m_optKey
.empty(), "can only have one optional value" );
920 m_info
.StoreValue(key
, value
);
925 // non-vararg function used by wxVLogXXX():
927 // log the message at the level specified in the ctor if this log message
929 void LogV(const wxString
& format
, va_list argptr
)
931 // remember that fatal errors can't be disabled
932 if ( m_level
== wxLOG_FatalError
||
933 wxLog::IsLevelEnabled(m_level
, m_info
.component
) )
934 DoCallOnLog(format
, argptr
);
937 // overloads used by functions with optional leading arguments (whose
938 // values are stored in the key passed to MaybeStore())
939 void LogV(long num
, const wxString
& format
, va_list argptr
)
941 Store(m_optKey
, num
);
943 LogV(format
, argptr
);
946 void LogV(void *ptr
, const wxString
& format
, va_list argptr
)
948 Store(m_optKey
, wxPtrToUInt(ptr
));
950 LogV(format
, argptr
);
953 void LogVTrace(const wxString
& mask
, const wxString
& format
, va_list argptr
)
955 if ( !wxLog::IsAllowedTraceMask(mask
) )
958 Store(wxLOG_KEY_TRACE_MASK
, mask
);
960 LogV(format
, argptr
);
964 // vararg functions used by wxLogXXX():
966 // will log the message at the level specified in the ctor
968 // notice that this function supposes that the caller already checked that
969 // the level was enabled and does no checks itself
970 WX_DEFINE_VARARG_FUNC_VOID
973 1, (const wxFormatString
&),
977 // same as Log() but with an extra numeric or pointer parameters: this is
978 // used to pass an optional value by storing it in m_info under the name
979 // passed to MaybeStore() and is required to support "overloaded" versions
980 // of wxLogStatus() and wxLogSysError()
981 WX_DEFINE_VARARG_FUNC_VOID
984 2, (long, const wxFormatString
&),
985 DoLogWithNum
, DoLogWithNumUtf8
988 // unfortunately we can't use "void *" here as we get overload ambiguities
989 // with Log(wxFormatString, ...) when the first argument is a "char *" or
990 // "wchar_t *" then -- so we only allow passing wxObject here, which is
991 // ugly but fine in practice as this overload is only used by wxLogStatus()
992 // whose first argument is a wxFrame
993 WX_DEFINE_VARARG_FUNC_VOID
996 2, (wxObject
*, const wxFormatString
&),
997 DoLogWithPtr
, DoLogWithPtrUtf8
1000 // log the message at the level specified as its first argument
1002 // as the macros don't have access to the level argument in this case, this
1003 // function does check that the level is enabled itself
1004 WX_DEFINE_VARARG_FUNC_VOID
1007 2, (wxLogLevel
, const wxFormatString
&),
1008 DoLogAtLevel
, DoLogAtLevelUtf8
1011 // special versions for wxLogTrace() which is passed either string or
1012 // integer mask as first argument determining whether the message should be
1014 WX_DEFINE_VARARG_FUNC_VOID
1017 2, (const wxString
&, const wxFormatString
&),
1018 DoLogTrace
, DoLogTraceUtf8
1021 #if WXWIN_COMPATIBILITY_2_8
1022 WX_DEFINE_VARARG_FUNC_VOID
1025 2, (wxTraceMask
, const wxFormatString
&),
1026 DoLogTraceMask
, DoLogTraceMaskUtf8
1028 #endif // WXWIN_COMPATIBILITY_2_8
1031 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1032 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1033 1, (const wxString
&),
1034 (wxFormatString(f1
)))
1035 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1036 1, (const wxCStrData
&),
1037 (wxFormatString(f1
)))
1038 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1040 (wxFormatString(f1
)))
1041 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1042 1, (const wchar_t*),
1043 (wxFormatString(f1
)))
1045 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1046 2, (long, const wxString
&),
1047 (f1
, wxFormatString(f2
)))
1048 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1049 2, (long, const wxCStrData
&),
1050 (f1
, wxFormatString(f2
)))
1051 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1052 2, (long, const char *),
1053 (f1
, wxFormatString(f2
)))
1054 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1055 2, (long, const wchar_t *),
1056 (f1
, wxFormatString(f2
)))
1058 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1059 2, (wxObject
*, const wxString
&),
1060 (f1
, wxFormatString(f2
)))
1061 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1062 2, (wxObject
*, const wxCStrData
&),
1063 (f1
, wxFormatString(f2
)))
1064 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1065 2, (wxObject
*, const char *),
1066 (f1
, wxFormatString(f2
)))
1067 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1068 2, (wxObject
*, const wchar_t *),
1069 (f1
, wxFormatString(f2
)))
1071 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel
,
1072 2, (wxLogLevel
, const wxString
&),
1073 (f1
, wxFormatString(f2
)))
1074 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel
,
1075 2, (wxLogLevel
, const wxCStrData
&),
1076 (f1
, wxFormatString(f2
)))
1077 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel
,
1078 2, (wxLogLevel
, const char *),
1079 (f1
, wxFormatString(f2
)))
1080 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel
,
1081 2, (wxLogLevel
, const wchar_t *),
1082 (f1
, wxFormatString(f2
)))
1084 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1085 2, (const wxString
&, const wxString
&),
1086 (f1
, wxFormatString(f2
)))
1087 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1088 2, (const wxString
&, const wxCStrData
&),
1089 (f1
, wxFormatString(f2
)))
1090 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1091 2, (const wxString
&, const char *),
1092 (f1
, wxFormatString(f2
)))
1093 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1094 2, (const wxString
&, const wchar_t *),
1095 (f1
, wxFormatString(f2
)))
1097 #if WXWIN_COMPATIBILITY_2_8
1098 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1099 2, (wxTraceMask
, wxTraceMask
),
1100 (f1
, wxFormatString(f2
)))
1101 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1102 2, (wxTraceMask
, const wxCStrData
&),
1103 (f1
, wxFormatString(f2
)))
1104 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1105 2, (wxTraceMask
, const char *),
1106 (f1
, wxFormatString(f2
)))
1107 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1108 2, (wxTraceMask
, const wchar_t *),
1109 (f1
, wxFormatString(f2
)))
1110 #endif // WXWIN_COMPATIBILITY_2_8
1111 #endif // __WATCOMC__
1114 #if !wxUSE_UTF8_LOCALE_ONLY
1115 void DoLog(const wxChar
*format
, ...)
1118 va_start(argptr
, format
);
1119 DoCallOnLog(format
, argptr
);
1123 void DoLogWithNum(long num
, const wxChar
*format
, ...)
1125 Store(m_optKey
, num
);
1128 va_start(argptr
, format
);
1129 DoCallOnLog(format
, argptr
);
1133 void DoLogWithPtr(void *ptr
, const wxChar
*format
, ...)
1135 Store(m_optKey
, wxPtrToUInt(ptr
));
1138 va_start(argptr
, format
);
1139 DoCallOnLog(format
, argptr
);
1143 void DoLogAtLevel(wxLogLevel level
, const wxChar
*format
, ...)
1145 if ( !wxLog::IsLevelEnabled(level
, m_info
.component
) )
1149 va_start(argptr
, format
);
1150 DoCallOnLog(level
, format
, argptr
);
1154 void DoLogTrace(const wxString
& mask
, const wxChar
*format
, ...)
1156 if ( !wxLog::IsAllowedTraceMask(mask
) )
1159 Store(wxLOG_KEY_TRACE_MASK
, mask
);
1162 va_start(argptr
, format
);
1163 DoCallOnLog(format
, argptr
);
1167 #if WXWIN_COMPATIBILITY_2_8
1168 void DoLogTraceMask(wxTraceMask mask
, const wxChar
*format
, ...)
1170 if ( (wxLog::GetTraceMask() & mask
) != mask
)
1173 Store(wxLOG_KEY_TRACE_MASK
, mask
);
1176 va_start(argptr
, format
);
1177 DoCallOnLog(format
, argptr
);
1180 #endif // WXWIN_COMPATIBILITY_2_8
1181 #endif // !wxUSE_UTF8_LOCALE_ONLY
1183 #if wxUSE_UNICODE_UTF8
1184 void DoLogUtf8(const char *format
, ...)
1187 va_start(argptr
, format
);
1188 DoCallOnLog(format
, argptr
);
1192 void DoLogWithNumUtf8(long num
, const char *format
, ...)
1194 Store(m_optKey
, num
);
1197 va_start(argptr
, format
);
1198 DoCallOnLog(format
, argptr
);
1202 void DoLogWithPtrUtf8(void *ptr
, const char *format
, ...)
1204 Store(m_optKey
, wxPtrToUInt(ptr
));
1207 va_start(argptr
, format
);
1208 DoCallOnLog(format
, argptr
);
1212 void DoLogAtLevelUtf8(wxLogLevel level
, const char *format
, ...)
1214 if ( !wxLog::IsLevelEnabled(level
, m_info
.component
) )
1218 va_start(argptr
, format
);
1219 DoCallOnLog(level
, format
, argptr
);
1223 void DoLogTraceUtf8(const wxString
& mask
, const char *format
, ...)
1225 if ( !wxLog::IsAllowedTraceMask(mask
) )
1228 Store(wxLOG_KEY_TRACE_MASK
, mask
);
1231 va_start(argptr
, format
);
1232 DoCallOnLog(format
, argptr
);
1236 #if WXWIN_COMPATIBILITY_2_8
1237 void DoLogTraceMaskUtf8(wxTraceMask mask
, const char *format
, ...)
1239 if ( (wxLog::GetTraceMask() & mask
) != mask
)
1242 Store(wxLOG_KEY_TRACE_MASK
, mask
);
1245 va_start(argptr
, format
);
1246 DoCallOnLog(format
, argptr
);
1249 #endif // WXWIN_COMPATIBILITY_2_8
1250 #endif // wxUSE_UNICODE_UTF8
1252 void DoCallOnLog(wxLogLevel level
, const wxString
& format
, va_list argptr
)
1254 wxLog::OnLog(level
, wxString::FormatV(format
, argptr
), m_info
);
1257 void DoCallOnLog(const wxString
& format
, va_list argptr
)
1259 DoCallOnLog(m_level
, format
, argptr
);
1263 const wxLogLevel m_level
;
1264 wxLogRecordInfo m_info
;
1268 wxDECLARE_NO_COPY_CLASS(wxLogger
);
1271 // ============================================================================
1273 // ============================================================================
1275 // ----------------------------------------------------------------------------
1276 // get error code/error message from system in a portable way
1277 // ----------------------------------------------------------------------------
1279 // return the last system error code
1280 WXDLLIMPEXP_BASE
unsigned long wxSysErrorCode();
1282 // return the error message for given (or last if 0) error code
1283 WXDLLIMPEXP_BASE
const wxChar
* wxSysErrorMsg(unsigned long nErrCode
= 0);
1285 // ----------------------------------------------------------------------------
1286 // define wxLog<level>() functions which can be used by application instead of
1287 // stdio, iostream &c for log messages for easy redirection
1288 // ----------------------------------------------------------------------------
1291 The code below is unreadable because it (unfortunately unavoidably)
1292 contains a lot of macro magic but all it does is to define wxLogXXX() such
1293 that you can call them as vararg functions to log a message at the
1294 corresponding level.
1296 More precisely, it defines:
1298 - wxLog{FatalError,Error,Warning,Message,Verbose,Debug}() functions
1299 taking the format string and additional vararg arguments if needed.
1300 - wxLogGeneric(wxLogLevel level, const wxString& format, ...) which
1301 takes the log level explicitly.
1302 - wxLogSysError(const wxString& format, ...) and wxLogSysError(long
1303 err, const wxString& format, ...) which log a wxLOG_Error severity
1304 message with the error message corresponding to the system error code
1305 err or the last error.
1306 - wxLogStatus(const wxString& format, ...) which logs the message into
1307 the status bar of the main application window and its overload
1308 wxLogStatus(wxFrame *frame, const wxString& format, ...) which logs it
1309 into the status bar of the specified frame.
1310 - wxLogTrace(Mask mask, const wxString& format, ...) which only logs
1311 the message is the specified mask is enabled. This comes in two kinds:
1312 Mask can be a wxString or a long. Both are deprecated.
1314 In addition, wxVLogXXX() versions of all the functions above are also
1315 defined. They take a va_list argument instead of "...".
1318 // creates wxLogger object for the current location
1319 #define wxMAKE_LOGGER(level) \
1320 wxLogger(wxLOG_##level, __FILE__, __LINE__, __WXFUNCTION__, wxLOG_COMPONENT)
1322 // this macro generates the expression which logs whatever follows it in
1323 // parentheses at the level specified as argument
1324 #define wxDO_LOG(level) wxMAKE_LOGGER(level).Log
1326 // this is the non-vararg equivalent
1327 #define wxDO_LOGV(level, format, argptr) \
1328 wxMAKE_LOGGER(level).LogV(format, argptr)
1330 // this macro declares wxLog<level>() macro which logs whatever follows it if
1331 // logging at specified level is enabled (notice that if it is false, the
1332 // following arguments are not even evaluated which is good as it avoids
1333 // unnecessary overhead)
1335 // Note: the strange if/else construct is needed to make the following code
1338 // wxLogError("!!!");
1342 // work as expected, without it the second "else" would match the "if"
1343 // inside wxLogError(). Unfortunately code like
1346 // wxLogError("!!!");
1348 // now provokes "suggest explicit braces to avoid ambiguous 'else'"
1349 // warnings from g++ 4.3 and later with -Wparentheses on but they can be
1350 // easily fixed by adding curly braces around wxLogError() and at least
1351 // the code still does do the right thing.
1352 #define wxDO_LOG_IF_ENABLED(level) \
1353 if ( !wxLog::IsLevelEnabled(wxLOG_##level, wxLOG_COMPONENT) ) \
1358 // wxLogFatalError() is special as it can't be disabled
1359 #define wxLogFatalError wxDO_LOG(FatalError)
1360 #define wxVLogFatalError(format, argptr) wxDO_LOGV(FatalError, format, argptr)
1362 #define wxLogError wxDO_LOG_IF_ENABLED(Error)
1363 #define wxVLogError(format, argptr) wxDO_LOGV(Error, format, argptr)
1365 #define wxLogWarning wxDO_LOG_IF_ENABLED(Warning)
1366 #define wxVLogWarning(format, argptr) wxDO_LOGV(Warning, format, argptr)
1368 #define wxLogMessage wxDO_LOG_IF_ENABLED(Message)
1369 #define wxVLogMessage(format, argptr) wxDO_LOGV(Message, format, argptr)
1371 // this one is special as it only logs if we're in verbose mode
1372 #define wxLogVerbose \
1373 if ( !(wxLog::IsLevelEnabled(wxLOG_Info, wxLOG_COMPONENT) && \
1374 wxLog::GetVerbose()) ) \
1378 #define wxVLogVerbose(format, argptr) \
1379 if ( !(wxLog::IsLevelEnabled(wxLOG_Info, wxLOG_COMPONENT) && \
1380 wxLog::GetVerbose()) ) \
1383 wxDO_LOGV(Info, format, argptr)
1385 // deprecated synonyms for wxLogVerbose() and wxVLogVerbose()
1386 #define wxLogInfo wxLogVerbose
1387 #define wxVLogInfo wxVLogVerbose
1390 // another special case: the level is passed as first argument of the function
1391 // and so is not available to the macro
1393 // notice that because of this, arguments of wxLogGeneric() are currently
1394 // always evaluated, unlike for the other log functions
1395 #define wxLogGeneric wxMAKE_LOGGER(Max).LogAtLevel
1396 #define wxVLogGeneric(level, format, argptr) \
1397 if ( !wxLog::IsLevelEnabled(wxLOG_##level, wxLOG_COMPONENT) ) \
1400 wxDO_LOGV(level, format, argptr)
1403 // wxLogSysError() needs to stash the error code value in the log record info
1404 // so it needs special handling too; additional complications arise because the
1405 // error code may or not be present as the first argument
1407 // notice that we unfortunately can't avoid the call to wxSysErrorCode() even
1408 // though it may be unneeded if an explicit error code is passed to us because
1409 // the message might not be logged immediately (e.g. it could be queued for
1410 // logging from the main thread later) and so we can't to wait until it is
1411 // logged to determine whether we have last error or not as it will be too late
1412 // and it will have changed already by then (in fact it even changes when
1413 // wxString::Format() is called because of vsnprintf() inside it so it can
1414 // change even much sooner)
1415 #define wxLOG_KEY_SYS_ERROR_CODE "wx.sys_error"
1417 #define wxLogSysError \
1418 if ( !wxLog::IsLevelEnabled(wxLOG_Error, wxLOG_COMPONENT) ) \
1421 wxMAKE_LOGGER(Error).MaybeStore(wxLOG_KEY_SYS_ERROR_CODE, \
1422 wxSysErrorCode()).Log
1424 // unfortunately we can't have overloaded macros so we can't define versions
1425 // both with and without error code argument and have to rely on LogV()
1426 // overloads in wxLogger to select between them
1427 #define wxVLogSysError \
1428 wxMAKE_LOGGER(Error).MaybeStore(wxLOG_KEY_SYS_ERROR_CODE, \
1429 wxSysErrorCode()).LogV
1432 // wxLogStatus() is similar to wxLogSysError() as it allows to optionally
1433 // specify the frame to which the message should go
1434 #define wxLOG_KEY_FRAME "wx.frame"
1436 #define wxLogStatus \
1437 if ( !wxLog::IsLevelEnabled(wxLOG_Status, wxLOG_COMPONENT) ) \
1440 wxMAKE_LOGGER(Status).MaybeStore(wxLOG_KEY_FRAME).Log
1442 #define wxVLogStatus(format, argptr) \
1443 wxMAKE_LOGGER(Status).MaybeStore(wxLOG_KEY_FRAME).LogV
1449 #undef wxUSE_LOG_DEBUG
1450 #define wxUSE_LOG_DEBUG 0
1452 #undef wxUSE_LOG_TRACE
1453 #define wxUSE_LOG_TRACE 0
1455 #if defined(__WATCOMC__) || defined(__MINGW32__)
1456 // Mingw has similar problem with wxLogSysError:
1457 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x ) x
1459 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x )
1462 // define macros for defining log functions which do nothing at all
1464 // WX_WATCOM_ONLY_CODE is needed to work around
1465 // http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1466 #define wxDEFINE_EMPTY_LOG_FUNCTION(level) \
1467 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxFormatString&)) \
1468 WX_WATCOM_ONLY_CODE( \
1469 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const char*)) \
1470 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wchar_t*)) \
1471 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxCStrData&)) \
1473 inline void wxVLog##level(const wxFormatString& WXUNUSED(format), \
1474 va_list WXUNUSED(argptr)) { } \
1476 #define wxDEFINE_EMPTY_LOG_FUNCTION2(level, argclass) \
1477 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxFormatString&)) \
1478 WX_WATCOM_OR_MINGW_ONLY_CODE( \
1479 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const char*)) \
1480 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wchar_t*)) \
1481 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxCStrData&)) \
1483 inline void wxVLog##level(argclass WXUNUSED(arg), \
1484 const wxFormatString& WXUNUSED(format), \
1485 va_list WXUNUSED(argptr)) {}
1487 wxDEFINE_EMPTY_LOG_FUNCTION(FatalError
);
1488 wxDEFINE_EMPTY_LOG_FUNCTION(Error
);
1489 wxDEFINE_EMPTY_LOG_FUNCTION(SysError
);
1490 wxDEFINE_EMPTY_LOG_FUNCTION2(SysError
, long);
1491 wxDEFINE_EMPTY_LOG_FUNCTION(Warning
);
1492 wxDEFINE_EMPTY_LOG_FUNCTION(Message
);
1493 wxDEFINE_EMPTY_LOG_FUNCTION(Info
);
1494 wxDEFINE_EMPTY_LOG_FUNCTION(Verbose
);
1496 wxDEFINE_EMPTY_LOG_FUNCTION2(Generic
, wxLogLevel
);
1499 wxDEFINE_EMPTY_LOG_FUNCTION(Status
);
1500 wxDEFINE_EMPTY_LOG_FUNCTION2(Status
, wxFrame
*);
1503 // Empty Class to fake wxLogNull
1504 class WXDLLIMPEXP_BASE wxLogNull
1510 // Dummy macros to replace some functions.
1511 #define wxSysErrorCode() (unsigned long)0
1512 #define wxSysErrorMsg( X ) (const wxChar*)NULL
1514 // Fake symbolic trace masks... for those that are used frequently
1515 #define wxTRACE_OleCalls wxEmptyString // OLE interface calls
1517 #endif // wxUSE_LOG/!wxUSE_LOG
1520 // debug functions can be completely disabled in optimized builds
1522 // if these log functions are disabled, we prefer to define them as (empty)
1523 // variadic macros as this completely removes them and their argument
1524 // evaluation from the object code but if this is not supported by compiler we
1525 // use empty inline functions instead (defining them as nothing would result in
1526 // compiler warnings)
1528 // note that making wxVLogDebug/Trace() themselves (empty inline) functions is
1529 // a bad idea as some compilers are stupid enough to not inline even empty
1530 // functions if their parameters are complicated enough, but by defining them
1531 // as an empty inline function we ensure that even dumbest compilers optimise
1534 // but Borland gives "W8019: Code has no effect" for wxLogNop() so we need
1535 // to define it differently for it to avoid these warnings (same problem as
1536 // with wxUnusedVar())
1537 #define wxLogNop() { }
1539 inline void wxLogNop() { }
1543 #define wxLogDebug wxDO_LOG_IF_ENABLED(Debug)
1544 #define wxVLogDebug(format, argptr) wxDO_LOGV(Debug, format, argptr)
1545 #else // !wxUSE_LOG_DEBUG
1546 #define wxVLogDebug(fmt, valist) wxLogNop()
1548 #ifdef HAVE_VARIADIC_MACROS
1549 #define wxLogDebug(fmt, ...) wxLogNop()
1550 #else // !HAVE_VARIADIC_MACROS
1551 WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug
, 1, (const wxFormatString
&))
1553 #endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
1556 #define wxLogTrace \
1557 if ( !wxLog::IsLevelEnabled(wxLOG_Trace, wxLOG_COMPONENT) ) \
1560 wxMAKE_LOGGER(Trace).LogTrace
1561 #define wxVLogTrace \
1562 if ( !wxLog::IsLevelEnabled(wxLOG_Trace, wxLOG_COMPONENT) ) \
1565 wxMAKE_LOGGER(Trace).LogVTrace
1566 #else // !wxUSE_LOG_TRACE
1567 #define wxVLogTrace(mask, fmt, valist) wxLogNop()
1569 #ifdef HAVE_VARIADIC_MACROS
1570 #define wxLogTrace(mask, fmt, ...) wxLogNop()
1571 #else // !HAVE_VARIADIC_MACROS
1572 #if WXWIN_COMPATIBILITY_2_8
1573 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (wxTraceMask
, const wxFormatString
&))
1575 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wxString
&, const wxFormatString
&))
1577 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1578 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const char*, const char*))
1579 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wchar_t*, const wchar_t*))
1581 #endif // HAVE_VARIADIC_MACROS/!HAVE_VARIADIC_MACROS
1582 #endif // wxUSE_LOG_TRACE/!wxUSE_LOG_TRACE
1584 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
1585 // i.e. without using wxMessageBox() for example because it could crash
1586 void WXDLLIMPEXP_BASE
1587 wxSafeShowMessage(const wxString
& title
, const wxString
& text
);
1589 // ----------------------------------------------------------------------------
1590 // debug only logging functions: use them with API name and error code
1591 // ----------------------------------------------------------------------------
1594 // make life easier for people using VC++ IDE: clicking on the message
1595 // will take us immediately to the place of the failed API
1597 #define wxLogApiError(api, rc) \
1598 wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
1599 __FILE__, __LINE__, api, \
1600 (long)rc, wxSysErrorMsg(rc))
1602 #define wxLogApiError(api, rc) \
1603 wxLogDebug(wxT("In file %s at line %d: '%s' failed with ") \
1604 wxT("error 0x%08lx (%s)."), \
1605 __FILE__, __LINE__, api, \
1606 (long)rc, wxSysErrorMsg(rc))
1607 #endif // VC++/!VC++
1609 #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
1611 #else // !wxUSE_LOG_DEBUG
1612 #define wxLogApiError(api, err) wxLogNop()
1613 #define wxLogLastError(api) wxLogNop()
1614 #endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
1616 // wxCocoa has additiional trace masks
1617 #if defined(__WXCOCOA__)
1618 #include "wx/cocoa/log.h"
1621 #ifdef WX_WATCOM_ONLY_CODE
1622 #undef WX_WATCOM_ONLY_CODE
1625 // macro which disables debug logging in release builds: this is done by
1626 // default by wxIMPLEMENT_APP() so usually it doesn't need to be used explicitly
1627 #if defined(NDEBUG) && wxUSE_LOG_DEBUG
1628 #define wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD() \
1629 wxLog::SetLogLevel(wxLOG_Info)
1631 #define wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD()
1632 #endif // NDEBUG/!NDEBUG
1634 #endif // _WX_LOG_H_