1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Assorted wxLogXXX functions, and wxLog (sink for logs)
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
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"
61 #include <time.h> // for time_t
64 #include "wx/dynarray.h"
65 #include "wx/hashmap.h"
68 #include "wx/thread.h"
69 #endif // wxUSE_THREADS
71 // wxUSE_LOG_DEBUG enables the debug log messages
72 #ifndef wxUSE_LOG_DEBUG
74 #define wxUSE_LOG_DEBUG 1
75 #else // !wxDEBUG_LEVEL
76 #define wxUSE_LOG_DEBUG 0
80 // wxUSE_LOG_TRACE enables the trace messages, they are disabled by default
81 #ifndef wxUSE_LOG_TRACE
83 #define wxUSE_LOG_TRACE 1
84 #else // !wxDEBUG_LEVEL
85 #define wxUSE_LOG_TRACE 0
87 #endif // wxUSE_LOG_TRACE
89 // wxLOG_COMPONENT identifies the component which generated the log record and
90 // can be #define'd to a user-defined value when compiling the user code to use
91 // component-based filtering (see wxLog::SetComponentLevel())
92 #ifndef wxLOG_COMPONENT
93 // this is a variable and not a macro in order to allow the user code to
94 // just #define wxLOG_COMPONENT without #undef'ining it first
95 extern WXDLLIMPEXP_DATA_BASE(const char *) wxLOG_COMPONENT
;
98 #define wxLOG_COMPONENT "wx"
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 // different standard log levels (you may also define your own)
107 enum wxLogLevelValues
109 wxLOG_FatalError
, // program can't continue, abort immediately
110 wxLOG_Error
, // a serious error, user must be informed about it
111 wxLOG_Warning
, // user is normally informed about it but may be ignored
112 wxLOG_Message
, // normal message (i.e. normal output of a non GUI app)
113 wxLOG_Status
, // informational: might go to the status line of GUI app
114 wxLOG_Info
, // informational message (a.k.a. 'Verbose')
115 wxLOG_Debug
, // never shown to the user, disabled in release mode
116 wxLOG_Trace
, // trace messages are also only enabled in debug mode
117 wxLOG_Progress
, // used for progress indicator (not yet)
118 wxLOG_User
= 100, // user defined levels start here
122 // symbolic trace masks - wxLogTrace("foo", "some trace message...") will be
123 // discarded unless the string "foo" has been added to the list of allowed
124 // ones with AddTraceMask()
126 #define wxTRACE_MemAlloc wxT("memalloc") // trace memory allocation (new/delete)
127 #define wxTRACE_Messages wxT("messages") // trace window messages/X callbacks
128 #define wxTRACE_ResAlloc wxT("resalloc") // trace GDI resource allocation
129 #define wxTRACE_RefCount wxT("refcount") // trace various ref counting operations
132 #define wxTRACE_OleCalls wxT("ole") // OLE interface calls
135 #include "wx/iosfwrap.h"
137 // ----------------------------------------------------------------------------
138 // information about a log record, i.e. unit of log output
139 // ----------------------------------------------------------------------------
141 class wxLogRecordInfo
144 // default ctor creates an uninitialized object
147 memset(this, 0, sizeof(*this));
150 // normal ctor, used by wxLogger specifies the location of the log
151 // statement; its time stamp and thread id are set up here
152 wxLogRecordInfo(const char *filename_
,
155 const char *component_
)
157 filename
= filename_
;
160 component
= component_
;
162 timestamp
= time(NULL
);
165 threadId
= wxThread::GetCurrentId();
166 #endif // wxUSE_THREADS
171 // we need to define copy ctor and assignment operator because of m_data
172 wxLogRecordInfo(const wxLogRecordInfo
& other
)
177 wxLogRecordInfo
& operator=(const wxLogRecordInfo
& other
)
179 if ( &other
!= this )
188 // dtor is non-virtual, this class is not meant to be derived from
195 // the file name and line number of the file where the log record was
196 // generated, if available or NULL and 0 otherwise
197 const char *filename
;
200 // the name of the function where the log record was generated (may be NULL
201 // if the compiler doesn't support __FUNCTION__)
204 // the name of the component which generated this message, may be NULL if
205 // not set (i.e. wxLOG_COMPONENT not defined)
206 const char *component
;
208 // time of record generation
212 // id of the thread which logged this record
213 wxThreadIdType threadId
;
214 #endif // wxUSE_THREADS
217 // store an arbitrary value in this record context
219 // wxWidgets always uses keys starting with "wx.", e.g. "wx.sys_error"
220 void StoreValue(const wxString
& key
, wxUIntPtr val
)
223 m_data
= new ExtraData
;
225 m_data
->numValues
[key
] = val
;
228 void StoreValue(const wxString
& key
, const wxString
& val
)
231 m_data
= new ExtraData
;
233 m_data
->strValues
[key
] = val
;
237 // these functions retrieve the value of either numeric or string key,
238 // return false if not found
239 bool GetNumValue(const wxString
& key
, wxUIntPtr
*val
) const
244 wxStringToNumHashMap::const_iterator it
= m_data
->numValues
.find(key
);
245 if ( it
== m_data
->numValues
.end() )
253 bool GetStrValue(const wxString
& key
, wxString
*val
) const
258 wxStringToStringHashMap::const_iterator it
= m_data
->strValues
.find(key
);
259 if ( it
== m_data
->strValues
.end() )
268 void Copy(const wxLogRecordInfo
& other
)
270 memcpy(this, &other
, sizeof(*this));
272 m_data
= new ExtraData(*other
.m_data
);
275 // extra data associated with the log record: this is completely optional
276 // and can be used to pass information from the log function to the log
277 // sink (e.g. wxLogSysError() uses this to pass the error code)
280 wxStringToNumHashMap numValues
;
281 wxStringToStringHashMap strValues
;
288 #define wxLOG_KEY_TRACE_MASK "wx.trace_mask"
290 // ----------------------------------------------------------------------------
291 // log record: a unit of log output
292 // ----------------------------------------------------------------------------
296 wxLogRecord(wxLogLevel level_
,
297 const wxString
& msg_
,
298 const wxLogRecordInfo
& info_
)
307 wxLogRecordInfo info
;
310 // ----------------------------------------------------------------------------
311 // Derive from this class to customize format of log messages.
312 // ----------------------------------------------------------------------------
314 class WXDLLIMPEXP_BASE wxLogFormatter
317 // Default constructor.
320 // Trivial but virtual destructor for the base class.
321 virtual ~wxLogFormatter() { }
324 // Override this method to implement custom formatting of the given log
325 // record. The default implementation simply prepends a level-dependent
326 // prefix to the message and optionally adds a time stamp.
327 virtual wxString
Format(wxLogLevel level
,
329 const wxLogRecordInfo
& info
) const;
332 // Override this method to change just the time stamp formatting. It is
333 // called by default Format() implementation.
334 virtual wxString
FormatTime(time_t t
) const;
338 // ----------------------------------------------------------------------------
339 // derive from this class to redirect (or suppress, or ...) log messages
340 // normally, only a single instance of this class exists but it's not enforced
341 // ----------------------------------------------------------------------------
343 class WXDLLIMPEXP_BASE wxLog
347 wxLog() : m_formatter(new wxLogFormatter
) { }
349 // make dtor virtual for all derived classes
353 // log messages selection
354 // ----------------------
356 // these functions allow to completely disable all log messages or disable
357 // log messages at level less important than specified for the current
360 // is logging enabled at all now?
361 static bool IsEnabled()
364 if ( !wxThread::IsMain() )
365 return IsThreadLoggingEnabled();
366 #endif // wxUSE_THREADS
371 // change the flag state, return the previous one
372 static bool EnableLogging(bool enable
= true)
375 if ( !wxThread::IsMain() )
376 return EnableThreadLogging(enable
);
377 #endif // wxUSE_THREADS
379 bool doLogOld
= ms_doLog
;
384 // return the current global log level
385 static wxLogLevel
GetLogLevel() { return ms_logLevel
; }
387 // set global log level: messages with level > logLevel will not be logged
388 static void SetLogLevel(wxLogLevel logLevel
) { ms_logLevel
= logLevel
; }
390 // set the log level for the given component
391 static void SetComponentLevel(const wxString
& component
, wxLogLevel level
);
393 // return the effective log level for this component, falling back to
394 // parent component and to the default global log level if necessary
396 // NB: component argument is passed by value and not const reference in an
397 // attempt to encourage compiler to avoid an extra copy: as we modify
398 // the component internally, we'd create one anyhow and like this it
399 // can be avoided if the string is a temporary anyhow
400 static wxLogLevel
GetComponentLevel(wxString component
);
403 // is logging of messages from this component enabled at this level?
405 // usually always called with wxLOG_COMPONENT as second argument
406 static bool IsLevelEnabled(wxLogLevel level
, wxString component
)
408 return IsEnabled() && level
<= GetComponentLevel(component
);
412 // enable/disable messages at wxLOG_Verbose level (only relevant if the
413 // current log level is greater or equal to it)
415 // notice that verbose mode can be activated by the standard command-line
416 // '--verbose' option
417 static void SetVerbose(bool bVerbose
= true) { ms_bVerbose
= bVerbose
; }
419 // check if verbose messages are enabled
420 static bool GetVerbose() { return ms_bVerbose
; }
426 // flush shows all messages if they're not logged immediately (FILE
427 // and iostream logs don't need it, but wxLogGui does to avoid showing
428 // 17 modal dialogs one after another)
429 virtual void Flush();
431 // flush the active target if any and also output any pending messages from
432 // background threads
433 static void FlushActive();
435 // only one sink is active at each moment get current log target, will call
436 // wxAppTraits::CreateLogTarget() to create one if none exists
437 static wxLog
*GetActiveTarget();
439 // change log target, logger may be NULL
440 static wxLog
*SetActiveTarget(wxLog
*logger
);
443 // change log target for the current thread only, shouldn't be called from
444 // the main thread as it doesn't use thread-specific log target
445 static wxLog
*SetThreadActiveTarget(wxLog
*logger
);
446 #endif // wxUSE_THREADS
448 // suspend the message flushing of the main target until the next call
449 // to Resume() - this is mainly for internal use (to prevent wxYield()
450 // from flashing the messages)
451 static void Suspend() { ms_suspendCount
++; }
453 // must be called for each Suspend()!
454 static void Resume() { ms_suspendCount
--; }
456 // should GetActiveTarget() try to create a new log object if the
458 static void DontCreateOnDemand();
460 // Make GetActiveTarget() create a new log object again.
461 static void DoCreateOnDemand();
463 // log the count of repeating messages instead of logging the messages
465 static void SetRepetitionCounting(bool bRepetCounting
= true)
466 { ms_bRepetCounting
= bRepetCounting
; }
468 // gets duplicate counting status
469 static bool GetRepetitionCounting() { return ms_bRepetCounting
; }
471 // add string trace mask
472 static void AddTraceMask(const wxString
& str
);
474 // add string trace mask
475 static void RemoveTraceMask(const wxString
& str
);
477 // remove all string trace masks
478 static void ClearTraceMasks();
480 // get string trace masks: note that this is MT-unsafe if other threads can
481 // call AddTraceMask() concurrently
482 static const wxArrayString
& GetTraceMasks();
484 // is this trace mask in the list?
485 static bool IsAllowedTraceMask(const wxString
& mask
);
491 // Change wxLogFormatter object used by wxLog to format the log messages.
493 // wxLog takes ownership of the pointer passed in but the caller is
494 // responsible for deleting the returned pointer.
495 wxLogFormatter
* SetFormatter(wxLogFormatter
* formatter
);
498 // All the time stamp related functions below only work when the default
499 // wxLogFormatter is being used. Defining a custom formatter overrides them
500 // as it could use its own time stamp format or format messages without
501 // using time stamp at all.
504 // sets the time stamp string format: this is used as strftime() format
505 // string for the log targets which add time stamps to the messages; set
506 // it to empty string to disable time stamping completely.
507 static void SetTimestamp(const wxString
& ts
) { ms_timestamp
= ts
; }
509 // disable time stamping of log messages
510 static void DisableTimestamp() { SetTimestamp(wxEmptyString
); }
513 // get the current timestamp format string (maybe empty)
514 static const wxString
& GetTimestamp() { return ms_timestamp
; }
518 // helpers: all functions in this section are mostly for internal use only,
519 // don't call them from your code even if they are not formally deprecated
521 // put the time stamp into the string if ms_timestamp is not empty (don't
522 // change it otherwise); the first overload uses the current time.
523 static void TimeStamp(wxString
*str
);
524 static void TimeStamp(wxString
*str
, time_t t
);
526 // these methods should only be called from derived classes DoLogRecord(),
527 // DoLogTextAtLevel() and DoLogText() implementations respectively and
528 // shouldn't be called directly, use logging functions instead
529 void LogRecord(wxLogLevel level
,
531 const wxLogRecordInfo
& info
)
533 DoLogRecord(level
, msg
, info
);
536 void LogTextAtLevel(wxLogLevel level
, const wxString
& msg
)
538 DoLogTextAtLevel(level
, msg
);
541 void LogText(const wxString
& msg
)
546 // this is a helper used by wxLogXXX() functions, don't call it directly
547 // and see DoLog() for function to overload in the derived classes
548 static void OnLog(wxLogLevel level
,
550 const wxLogRecordInfo
& info
);
552 // version called when no information about the location of the log record
553 // generation is available (but the time stamp is), it mainly exists for
554 // backwards compatibility, don't use it in new code
555 static void OnLog(wxLogLevel level
, const wxString
& msg
, time_t t
);
557 // a helper calling the above overload with current time
558 static void OnLog(wxLogLevel level
, const wxString
& msg
)
560 OnLog(level
, msg
, time(NULL
));
564 // this method exists for backwards compatibility only, don't use
565 bool HasPendingMessages() const { return true; }
567 #if WXWIN_COMPATIBILITY_2_6
568 // this function doesn't do anything any more, don't call it
569 static wxDEPRECATED_INLINE(
570 wxChar
*SetLogBuffer(wxChar
*, size_t = 0), return NULL
;
572 #endif // WXWIN_COMPATIBILITY_2_6
574 // don't use integer masks any more, use string trace masks instead
575 #if WXWIN_COMPATIBILITY_2_8
576 static wxDEPRECATED_INLINE( void SetTraceMask(wxTraceMask ulMask
),
577 ms_ulTraceMask
= ulMask
; )
579 // this one can't be marked deprecated as it's used in our own wxLogger
580 // below but it still is deprecated and shouldn't be used
581 static wxTraceMask
GetTraceMask() { return ms_ulTraceMask
; }
582 #endif // WXWIN_COMPATIBILITY_2_8
585 // the logging functions that can be overridden: DoLogRecord() is called
586 // for every "record", i.e. a unit of log output, to be logged and by
587 // default formats the message and passes it to DoLogTextAtLevel() which in
588 // turn passes it to DoLogText() by default
590 // override this method if you want to change message formatting or do
592 virtual void DoLogRecord(wxLogLevel level
,
594 const wxLogRecordInfo
& info
);
596 // override this method to redirect output to different channels depending
597 // on its level only; if even the level doesn't matter, override
598 // DoLogText() instead
599 virtual void DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
);
601 // this function is not pure virtual as it might not be needed if you do
602 // the logging in overridden DoLogRecord() or DoLogTextAtLevel() directly
603 // but if you do not override them in your derived class you must override
604 // this one as the default implementation of it simply asserts
605 virtual void DoLogText(const wxString
& msg
);
608 // the rest of the functions are for backwards compatibility only, don't
609 // use them in new code; if you're updating your existing code you need to
610 // switch to overriding DoLogRecord/Text() above (although as long as these
611 // functions exist, log classes using them will continue to work)
612 #if WXWIN_COMPATIBILITY_2_8
613 wxDEPRECATED_BUT_USED_INTERNALLY(
614 virtual void DoLog(wxLogLevel level
, const char *szString
, time_t t
)
617 wxDEPRECATED_BUT_USED_INTERNALLY(
618 virtual void DoLog(wxLogLevel level
, const wchar_t *wzString
, time_t t
)
621 // these shouldn't be used by new code
622 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
623 virtual void DoLogString(const char *WXUNUSED(szString
),
625 wxEMPTY_PARAMETER_VALUE
628 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
629 virtual void DoLogString(const wchar_t *WXUNUSED(wzString
),
631 wxEMPTY_PARAMETER_VALUE
633 #endif // WXWIN_COMPATIBILITY_2_8
636 // log a message indicating the number of times the previous message was
637 // repeated if previous repetition counter is strictly positive, does
638 // nothing otherwise; return the old value of repetition counter
639 unsigned LogLastRepeatIfNeeded();
643 // called from FlushActive() to really log any buffered messages logged
644 // from the other threads
645 void FlushThreadMessages();
647 // these functions are called for non-main thread only by IsEnabled() and
648 // EnableLogging() respectively
649 static bool IsThreadLoggingEnabled();
650 static bool EnableThreadLogging(bool enable
= true);
651 #endif // wxUSE_THREADS
653 // get the active log target for the main thread, auto-creating it if
656 // this is called from GetActiveTarget() and OnLog() when they're called
657 // from the main thread
658 static wxLog
*GetMainThreadActiveTarget();
660 // called from OnLog() if it's called from the main thread or if we have a
661 // (presumably MT-safe) thread-specific logger and by FlushThreadMessages()
662 // when it plays back the buffered messages logged from the other threads
663 void CallDoLogNow(wxLogLevel level
,
665 const wxLogRecordInfo
& info
);
671 wxLogFormatter
*m_formatter
; // We own this pointer.
677 // if true, don't log the same message multiple times, only log it once
678 // with the number of times it was repeated
679 static bool ms_bRepetCounting
;
681 static wxLog
*ms_pLogger
; // currently active log sink
682 static bool ms_doLog
; // false => all logging disabled
683 static bool ms_bAutoCreate
; // create new log targets on demand?
684 static bool ms_bVerbose
; // false => ignore LogInfo messages
686 static wxLogLevel ms_logLevel
; // limit logging to levels <= ms_logLevel
688 static size_t ms_suspendCount
; // if positive, logs are not flushed
690 // format string for strftime(), if empty, time stamping log messages is
692 static wxString ms_timestamp
;
694 #if WXWIN_COMPATIBILITY_2_8
695 static wxTraceMask ms_ulTraceMask
; // controls wxLogTrace behaviour
696 #endif // WXWIN_COMPATIBILITY_2_8
699 // ----------------------------------------------------------------------------
700 // "trivial" derivations of wxLog
701 // ----------------------------------------------------------------------------
703 // log everything except for the debug/trace messages (which are passed to
704 // wxMessageOutputDebug) to a buffer
705 class WXDLLIMPEXP_BASE wxLogBuffer
: public wxLog
710 // get the string contents with all messages logged
711 const wxString
& GetBuffer() const { return m_str
; }
713 // show the buffer contents to the user in the best possible way (this uses
714 // wxMessageOutputMessageBox) and clear it
715 virtual void Flush();
718 virtual void DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
);
723 wxDECLARE_NO_COPY_CLASS(wxLogBuffer
);
727 // log everything to a "FILE *", stderr by default
728 class WXDLLIMPEXP_BASE wxLogStderr
: public wxLog
731 // redirect log output to a FILE
732 wxLogStderr(FILE *fp
= NULL
);
735 // implement sink function
736 virtual void DoLogText(const wxString
& msg
);
740 wxDECLARE_NO_COPY_CLASS(wxLogStderr
);
743 #if wxUSE_STD_IOSTREAM
745 // log everything to an "ostream", cerr by default
746 class WXDLLIMPEXP_BASE wxLogStream
: public wxLog
749 // redirect log output to an ostream
750 wxLogStream(wxSTD ostream
*ostr
= (wxSTD ostream
*) NULL
);
753 // implement sink function
754 virtual void DoLogText(const wxString
& msg
);
756 // using ptr here to avoid including <iostream.h> from this file
757 wxSTD ostream
*m_ostr
;
760 #endif // wxUSE_STD_IOSTREAM
762 // ----------------------------------------------------------------------------
763 // /dev/null log target: suppress logging until this object goes out of scope
764 // ----------------------------------------------------------------------------
772 // wxFile.Open() normally complains if file can't be opened, we don't
776 if ( !file.Open("bar") )
777 ... process error ourselves ...
779 // ~wxLogNull called, old log sink restored
782 class WXDLLIMPEXP_BASE wxLogNull
785 wxLogNull() : m_flagOld(wxLog::EnableLogging(false)) { }
786 ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld
); }
789 bool m_flagOld
; // the previous value of the wxLog::ms_doLog
792 // ----------------------------------------------------------------------------
793 // chaining log target: installs itself as a log target and passes all
794 // messages to the real log target given to it in the ctor but also forwards
795 // them to the previously active one
797 // note that you don't have to call SetActiveTarget() with this class, it
798 // does it itself in its ctor
799 // ----------------------------------------------------------------------------
801 class WXDLLIMPEXP_BASE wxLogChain
: public wxLog
804 wxLogChain(wxLog
*logger
);
805 virtual ~wxLogChain();
807 // change the new log target
808 void SetLog(wxLog
*logger
);
810 // this can be used to temporarily disable (and then reenable) passing
811 // messages to the old logger (by default we do pass them)
812 void PassMessages(bool bDoPass
) { m_bPassMessages
= bDoPass
; }
814 // are we passing the messages to the previous log target?
815 bool IsPassingMessages() const { return m_bPassMessages
; }
817 // return the previous log target (may be NULL)
818 wxLog
*GetOldLog() const { return m_logOld
; }
820 // override base class version to flush the old logger as well
821 virtual void Flush();
823 // call to avoid destroying the old log target
824 void DetachOldLog() { m_logOld
= NULL
; }
827 // pass the record to the old logger if needed
828 virtual void DoLogRecord(wxLogLevel level
,
830 const wxLogRecordInfo
& info
);
833 // the current log target
836 // the previous log target
839 // do we pass the messages to the old logger?
840 bool m_bPassMessages
;
842 wxDECLARE_NO_COPY_CLASS(wxLogChain
);
845 // a chain log target which uses itself as the new logger
847 #define wxLogPassThrough wxLogInterposer
849 class WXDLLIMPEXP_BASE wxLogInterposer
: public wxLogChain
855 wxDECLARE_NO_COPY_CLASS(wxLogInterposer
);
858 // a temporary interposer which doesn't destroy the old log target
859 // (calls DetachOldLog)
861 class WXDLLIMPEXP_BASE wxLogInterposerTemp
: public wxLogChain
864 wxLogInterposerTemp();
867 wxDECLARE_NO_COPY_CLASS(wxLogInterposerTemp
);
871 // include GUI log targets:
872 #include "wx/generic/logg.h"
875 // ----------------------------------------------------------------------------
877 // ----------------------------------------------------------------------------
879 // wxLogger is a helper class used by wxLogXXX() functions implementation,
880 // don't use it directly as it's experimental and subject to change (OTOH it
881 // might become public in the future if it's deemed to be useful enough)
883 // contains information about the context from which a log message originates
884 // and provides Log() vararg method which forwards to wxLog::OnLog() and passes
885 // this context to it
889 // ctor takes the basic information about the log record
890 wxLogger(wxLogLevel level
,
891 const char *filename
,
894 const char *component
)
896 m_info(filename
, line
, func
, component
)
900 // store extra data in our log record and return this object itself (so
901 // that further calls to its functions could be chained)
902 template <typename T
>
903 wxLogger
& Store(const wxString
& key
, T val
)
905 m_info
.StoreValue(key
, val
);
909 // hack for "overloaded" wxLogXXX() functions: calling this method
910 // indicates that we may have an extra first argument preceding the format
911 // string and that if we do have it, we should store it in m_info using the
912 // given key (while by default 0 value will be used)
913 wxLogger
& MaybeStore(const wxString
& key
, wxUIntPtr value
= 0)
915 wxASSERT_MSG( m_optKey
.empty(), "can only have one optional value" );
918 m_info
.StoreValue(key
, value
);
923 // non-vararg function used by wxVLogXXX():
925 // log the message at the level specified in the ctor if this log message
927 void LogV(const wxString
& format
, va_list argptr
)
929 // remember that fatal errors can't be disabled
930 if ( m_level
== wxLOG_FatalError
||
931 wxLog::IsLevelEnabled(m_level
, m_info
.component
) )
932 DoCallOnLog(format
, argptr
);
935 // overloads used by functions with optional leading arguments (whose
936 // values are stored in the key passed to MaybeStore())
937 void LogV(long num
, const wxString
& format
, va_list argptr
)
939 Store(m_optKey
, num
);
941 LogV(format
, argptr
);
944 void LogV(void *ptr
, const wxString
& format
, va_list argptr
)
946 Store(m_optKey
, wxPtrToUInt(ptr
));
948 LogV(format
, argptr
);
951 void LogVTrace(const wxString
& mask
, const wxString
& format
, va_list argptr
)
953 if ( !wxLog::IsAllowedTraceMask(mask
) )
956 Store(wxLOG_KEY_TRACE_MASK
, mask
);
958 LogV(format
, argptr
);
962 // vararg functions used by wxLogXXX():
964 // will log the message at the level specified in the ctor
966 // notice that this function supposes that the caller already checked that
967 // the level was enabled and does no checks itself
968 WX_DEFINE_VARARG_FUNC_VOID
971 1, (const wxFormatString
&),
975 // same as Log() but with an extra numeric or pointer parameters: this is
976 // used to pass an optional value by storing it in m_info under the name
977 // passed to MaybeStore() and is required to support "overloaded" versions
978 // of wxLogStatus() and wxLogSysError()
979 WX_DEFINE_VARARG_FUNC_VOID
982 2, (long, const wxFormatString
&),
983 DoLogWithNum
, DoLogWithNumUtf8
986 // unfortunately we can't use "void *" here as we get overload ambiguities
987 // with Log(wxFormatString, ...) when the first argument is a "char *" or
988 // "wchar_t *" then -- so we only allow passing wxObject here, which is
989 // ugly but fine in practice as this overload is only used by wxLogStatus()
990 // whose first argument is a wxFrame
991 WX_DEFINE_VARARG_FUNC_VOID
994 2, (wxObject
*, const wxFormatString
&),
995 DoLogWithPtr
, DoLogWithPtrUtf8
998 // log the message at the level specified as its first argument
1000 // as the macros don't have access to the level argument in this case, this
1001 // function does check that the level is enabled itself
1002 WX_DEFINE_VARARG_FUNC_VOID
1005 2, (wxLogLevel
, const wxFormatString
&),
1006 DoLogAtLevel
, DoLogAtLevelUtf8
1009 // special versions for wxLogTrace() which is passed either string or
1010 // integer mask as first argument determining whether the message should be
1012 WX_DEFINE_VARARG_FUNC_VOID
1015 2, (const wxString
&, const wxFormatString
&),
1016 DoLogTrace
, DoLogTraceUtf8
1019 #if WXWIN_COMPATIBILITY_2_8
1020 WX_DEFINE_VARARG_FUNC_VOID
1023 2, (wxTraceMask
, const wxFormatString
&),
1024 DoLogTraceMask
, DoLogTraceMaskUtf8
1026 #endif // WXWIN_COMPATIBILITY_2_8
1029 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1030 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1031 1, (const wxString
&),
1032 (wxFormatString(f1
)))
1033 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1034 1, (const wxCStrData
&),
1035 (wxFormatString(f1
)))
1036 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1038 (wxFormatString(f1
)))
1039 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1040 1, (const wchar_t*),
1041 (wxFormatString(f1
)))
1043 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1044 2, (long, const wxString
&),
1045 (f1
, wxFormatString(f2
)))
1046 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1047 2, (long, const wxCStrData
&),
1048 (f1
, wxFormatString(f2
)))
1049 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1050 2, (long, const char *),
1051 (f1
, wxFormatString(f2
)))
1052 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1053 2, (long, const wchar_t *),
1054 (f1
, wxFormatString(f2
)))
1056 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1057 2, (wxObject
*, const wxString
&),
1058 (f1
, wxFormatString(f2
)))
1059 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1060 2, (wxObject
*, const wxCStrData
&),
1061 (f1
, wxFormatString(f2
)))
1062 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1063 2, (wxObject
*, const char *),
1064 (f1
, wxFormatString(f2
)))
1065 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1066 2, (wxObject
*, const wchar_t *),
1067 (f1
, wxFormatString(f2
)))
1069 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel
,
1070 2, (wxLogLevel
, const wxString
&),
1071 (f1
, wxFormatString(f2
)))
1072 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel
,
1073 2, (wxLogLevel
, const wxCStrData
&),
1074 (f1
, wxFormatString(f2
)))
1075 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel
,
1076 2, (wxLogLevel
, const char *),
1077 (f1
, wxFormatString(f2
)))
1078 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel
,
1079 2, (wxLogLevel
, const wchar_t *),
1080 (f1
, wxFormatString(f2
)))
1082 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1083 2, (const wxString
&, const wxString
&),
1084 (f1
, wxFormatString(f2
)))
1085 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1086 2, (const wxString
&, const wxCStrData
&),
1087 (f1
, wxFormatString(f2
)))
1088 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1089 2, (const wxString
&, const char *),
1090 (f1
, wxFormatString(f2
)))
1091 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1092 2, (const wxString
&, const wchar_t *),
1093 (f1
, wxFormatString(f2
)))
1095 #if WXWIN_COMPATIBILITY_2_8
1096 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1097 2, (wxTraceMask
, wxTraceMask
),
1098 (f1
, wxFormatString(f2
)))
1099 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1100 2, (wxTraceMask
, const wxCStrData
&),
1101 (f1
, wxFormatString(f2
)))
1102 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1103 2, (wxTraceMask
, const char *),
1104 (f1
, wxFormatString(f2
)))
1105 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1106 2, (wxTraceMask
, const wchar_t *),
1107 (f1
, wxFormatString(f2
)))
1108 #endif // WXWIN_COMPATIBILITY_2_8
1109 #endif // __WATCOMC__
1112 #if !wxUSE_UTF8_LOCALE_ONLY
1113 void DoLog(const wxChar
*format
, ...)
1116 va_start(argptr
, format
);
1117 DoCallOnLog(format
, argptr
);
1121 void DoLogWithNum(long num
, const wxChar
*format
, ...)
1123 Store(m_optKey
, num
);
1126 va_start(argptr
, format
);
1127 DoCallOnLog(format
, argptr
);
1131 void DoLogWithPtr(void *ptr
, const wxChar
*format
, ...)
1133 Store(m_optKey
, wxPtrToUInt(ptr
));
1136 va_start(argptr
, format
);
1137 DoCallOnLog(format
, argptr
);
1141 void DoLogAtLevel(wxLogLevel level
, const wxChar
*format
, ...)
1143 if ( !wxLog::IsLevelEnabled(level
, m_info
.component
) )
1147 va_start(argptr
, format
);
1148 DoCallOnLog(level
, format
, argptr
);
1152 void DoLogTrace(const wxString
& mask
, const wxChar
*format
, ...)
1154 if ( !wxLog::IsAllowedTraceMask(mask
) )
1157 Store(wxLOG_KEY_TRACE_MASK
, mask
);
1160 va_start(argptr
, format
);
1161 DoCallOnLog(format
, argptr
);
1165 #if WXWIN_COMPATIBILITY_2_8
1166 void DoLogTraceMask(wxTraceMask mask
, const wxChar
*format
, ...)
1168 if ( (wxLog::GetTraceMask() & mask
) != mask
)
1171 Store(wxLOG_KEY_TRACE_MASK
, mask
);
1174 va_start(argptr
, format
);
1175 DoCallOnLog(format
, argptr
);
1178 #endif // WXWIN_COMPATIBILITY_2_8
1179 #endif // !wxUSE_UTF8_LOCALE_ONLY
1181 #if wxUSE_UNICODE_UTF8
1182 void DoLogUtf8(const char *format
, ...)
1185 va_start(argptr
, format
);
1186 DoCallOnLog(format
, argptr
);
1190 void DoLogWithNumUtf8(long num
, const char *format
, ...)
1192 Store(m_optKey
, num
);
1195 va_start(argptr
, format
);
1196 DoCallOnLog(format
, argptr
);
1200 void DoLogWithPtrUtf8(void *ptr
, const char *format
, ...)
1202 Store(m_optKey
, wxPtrToUInt(ptr
));
1205 va_start(argptr
, format
);
1206 DoCallOnLog(format
, argptr
);
1210 void DoLogAtLevelUtf8(wxLogLevel level
, const char *format
, ...)
1212 if ( !wxLog::IsLevelEnabled(level
, m_info
.component
) )
1216 va_start(argptr
, format
);
1217 DoCallOnLog(level
, format
, argptr
);
1221 void DoLogTraceUtf8(const wxString
& mask
, const char *format
, ...)
1223 if ( !wxLog::IsAllowedTraceMask(mask
) )
1226 Store(wxLOG_KEY_TRACE_MASK
, mask
);
1229 va_start(argptr
, format
);
1230 DoCallOnLog(format
, argptr
);
1234 #if WXWIN_COMPATIBILITY_2_8
1235 void DoLogTraceMaskUtf8(wxTraceMask mask
, const char *format
, ...)
1237 if ( (wxLog::GetTraceMask() & mask
) != mask
)
1240 Store(wxLOG_KEY_TRACE_MASK
, mask
);
1243 va_start(argptr
, format
);
1244 DoCallOnLog(format
, argptr
);
1247 #endif // WXWIN_COMPATIBILITY_2_8
1248 #endif // wxUSE_UNICODE_UTF8
1250 void DoCallOnLog(wxLogLevel level
, const wxString
& format
, va_list argptr
)
1252 wxLog::OnLog(level
, wxString::FormatV(format
, argptr
), m_info
);
1255 void DoCallOnLog(const wxString
& format
, va_list argptr
)
1257 DoCallOnLog(m_level
, format
, argptr
);
1261 const wxLogLevel m_level
;
1262 wxLogRecordInfo m_info
;
1266 wxDECLARE_NO_COPY_CLASS(wxLogger
);
1269 // ============================================================================
1271 // ============================================================================
1273 // ----------------------------------------------------------------------------
1274 // get error code/error message from system in a portable way
1275 // ----------------------------------------------------------------------------
1277 // return the last system error code
1278 WXDLLIMPEXP_BASE
unsigned long wxSysErrorCode();
1280 // return the error message for given (or last if 0) error code
1281 WXDLLIMPEXP_BASE
const wxChar
* wxSysErrorMsg(unsigned long nErrCode
= 0);
1283 // ----------------------------------------------------------------------------
1284 // define wxLog<level>() functions which can be used by application instead of
1285 // stdio, iostream &c for log messages for easy redirection
1286 // ----------------------------------------------------------------------------
1289 The code below is unreadable because it (unfortunately unavoidably)
1290 contains a lot of macro magic but all it does is to define wxLogXXX() such
1291 that you can call them as vararg functions to log a message at the
1292 corresponding level.
1294 More precisely, it defines:
1296 - wxLog{FatalError,Error,Warning,Message,Verbose,Debug}() functions
1297 taking the format string and additional vararg arguments if needed.
1298 - wxLogGeneric(wxLogLevel level, const wxString& format, ...) which
1299 takes the log level explicitly.
1300 - wxLogSysError(const wxString& format, ...) and wxLogSysError(long
1301 err, const wxString& format, ...) which log a wxLOG_Error severity
1302 message with the error message corresponding to the system error code
1303 err or the last error.
1304 - wxLogStatus(const wxString& format, ...) which logs the message into
1305 the status bar of the main application window and its overload
1306 wxLogStatus(wxFrame *frame, const wxString& format, ...) which logs it
1307 into the status bar of the specified frame.
1308 - wxLogTrace(Mask mask, const wxString& format, ...) which only logs
1309 the message is the specified mask is enabled. This comes in two kinds:
1310 Mask can be a wxString or a long. Both are deprecated.
1312 In addition, wxVLogXXX() versions of all the functions above are also
1313 defined. They take a va_list argument instead of "...".
1316 // creates wxLogger object for the current location
1317 #define wxMAKE_LOGGER(level) \
1318 wxLogger(wxLOG_##level, __FILE__, __LINE__, __WXFUNCTION__, wxLOG_COMPONENT)
1320 // this macro generates the expression which logs whatever follows it in
1321 // parentheses at the level specified as argument
1322 #define wxDO_LOG(level) wxMAKE_LOGGER(level).Log
1324 // this is the non-vararg equivalent
1325 #define wxDO_LOGV(level, format, argptr) \
1326 wxMAKE_LOGGER(level).LogV(format, argptr)
1328 // this macro declares wxLog<level>() macro which logs whatever follows it if
1329 // logging at specified level is enabled (notice that if it is false, the
1330 // following arguments are not even evaluated which is good as it avoids
1331 // unnecessary overhead)
1333 // Note: the strange (because executing at most once) for() loop because we
1334 // must arrange for wxDO_LOG() to be at the end of the macro and using a
1335 // more natural "if (IsLevelEnabled()) wxDO_LOG()" would result in wrong
1336 // behaviour for the following code ("else" would bind to the wrong "if"):
1339 // wxLogError("!!!");
1343 // See also #11829 for the problems with other simpler approaches,
1344 // notably the need for two macros due to buggy __LINE__ in MSVC.
1346 // Note 2: Unfortunately we can't use the same solution for all compilers
1347 // because the loop-based one results in problems with MSVC6 due to its
1348 // wrong (pre-C++98) rules for the scope of the variables declared
1349 // inside the loop, as this prevents us from using wxLogXXX() in switch
1350 // statement clauses ("initialization of loopvar skipped by case"). So
1351 // for now, i.e. while we still support VC6, use the previous solution
1352 // for it (FIXME-VC6).
1354 #define wxDO_LOG_IF_ENABLED(level) \
1355 if ( !wxLog::IsLevelEnabled(wxLOG_##level, wxLOG_COMPONENT) ) \
1360 #define wxDO_LOG_IF_ENABLED_HELPER(level, loopvar) \
1361 for ( bool loopvar = false; \
1362 !loopvar && wxLog::IsLevelEnabled(wxLOG_##level, wxLOG_COMPONENT); \
1366 #define wxDO_LOG_IF_ENABLED(level) \
1367 wxDO_LOG_IF_ENABLED_HELPER(level, wxMAKE_UNIQUE_NAME(wxlogcheck))
1370 // wxLogFatalError() is special as it can't be disabled
1371 #define wxLogFatalError wxDO_LOG(FatalError)
1372 #define wxVLogFatalError(format, argptr) wxDO_LOGV(FatalError, format, argptr)
1374 #define wxLogError wxDO_LOG_IF_ENABLED(Error)
1375 #define wxVLogError(format, argptr) wxDO_LOGV(Error, format, argptr)
1377 #define wxLogWarning wxDO_LOG_IF_ENABLED(Warning)
1378 #define wxVLogWarning(format, argptr) wxDO_LOGV(Warning, format, argptr)
1380 #define wxLogMessage wxDO_LOG_IF_ENABLED(Message)
1381 #define wxVLogMessage(format, argptr) wxDO_LOGV(Message, format, argptr)
1383 // this one is special as it only logs if we're in verbose mode
1384 #define wxLogVerbose \
1385 if ( !(wxLog::IsLevelEnabled(wxLOG_Info, wxLOG_COMPONENT) && \
1386 wxLog::GetVerbose()) ) \
1390 #define wxVLogVerbose(format, argptr) \
1391 if ( !(wxLog::IsLevelEnabled(wxLOG_Info, wxLOG_COMPONENT) && \
1392 wxLog::GetVerbose()) ) \
1395 wxDO_LOGV(Info, format, argptr)
1397 // deprecated synonyms for wxLogVerbose() and wxVLogVerbose()
1398 #define wxLogInfo wxLogVerbose
1399 #define wxVLogInfo wxVLogVerbose
1402 // another special case: the level is passed as first argument of the function
1403 // and so is not available to the macro
1405 // notice that because of this, arguments of wxLogGeneric() are currently
1406 // always evaluated, unlike for the other log functions
1407 #define wxLogGeneric wxMAKE_LOGGER(Max).LogAtLevel
1408 #define wxVLogGeneric(level, format, argptr) \
1409 if ( !wxLog::IsLevelEnabled(wxLOG_##level, wxLOG_COMPONENT) ) \
1412 wxDO_LOGV(level, format, argptr)
1415 // wxLogSysError() needs to stash the error code value in the log record info
1416 // so it needs special handling too; additional complications arise because the
1417 // error code may or not be present as the first argument
1419 // notice that we unfortunately can't avoid the call to wxSysErrorCode() even
1420 // though it may be unneeded if an explicit error code is passed to us because
1421 // the message might not be logged immediately (e.g. it could be queued for
1422 // logging from the main thread later) and so we can't to wait until it is
1423 // logged to determine whether we have last error or not as it will be too late
1424 // and it will have changed already by then (in fact it even changes when
1425 // wxString::Format() is called because of vsnprintf() inside it so it can
1426 // change even much sooner)
1427 #define wxLOG_KEY_SYS_ERROR_CODE "wx.sys_error"
1429 #define wxLogSysError \
1430 if ( !wxLog::IsLevelEnabled(wxLOG_Error, wxLOG_COMPONENT) ) \
1433 wxMAKE_LOGGER(Error).MaybeStore(wxLOG_KEY_SYS_ERROR_CODE, \
1434 wxSysErrorCode()).Log
1436 // unfortunately we can't have overloaded macros so we can't define versions
1437 // both with and without error code argument and have to rely on LogV()
1438 // overloads in wxLogger to select between them
1439 #define wxVLogSysError \
1440 wxMAKE_LOGGER(Error).MaybeStore(wxLOG_KEY_SYS_ERROR_CODE, \
1441 wxSysErrorCode()).LogV
1444 // wxLogStatus() is similar to wxLogSysError() as it allows to optionally
1445 // specify the frame to which the message should go
1446 #define wxLOG_KEY_FRAME "wx.frame"
1448 #define wxLogStatus \
1449 if ( !wxLog::IsLevelEnabled(wxLOG_Status, wxLOG_COMPONENT) ) \
1452 wxMAKE_LOGGER(Status).MaybeStore(wxLOG_KEY_FRAME).Log
1454 #define wxVLogStatus \
1455 wxMAKE_LOGGER(Status).MaybeStore(wxLOG_KEY_FRAME).LogV
1461 #undef wxUSE_LOG_DEBUG
1462 #define wxUSE_LOG_DEBUG 0
1464 #undef wxUSE_LOG_TRACE
1465 #define wxUSE_LOG_TRACE 0
1467 #if defined(__WATCOMC__) || defined(__MINGW32__)
1468 // Mingw has similar problem with wxLogSysError:
1469 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x ) x
1471 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x )
1474 // define macros for defining log functions which do nothing at all
1476 // WX_WATCOM_ONLY_CODE is needed to work around
1477 // http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1478 #define wxDEFINE_EMPTY_LOG_FUNCTION(level) \
1479 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxFormatString&)) \
1480 WX_WATCOM_ONLY_CODE( \
1481 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const char*)) \
1482 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wchar_t*)) \
1483 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxCStrData&)) \
1485 inline void wxVLog##level(const wxFormatString& WXUNUSED(format), \
1486 va_list WXUNUSED(argptr)) { } \
1488 #define wxDEFINE_EMPTY_LOG_FUNCTION2(level, argclass) \
1489 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxFormatString&)) \
1490 WX_WATCOM_OR_MINGW_ONLY_CODE( \
1491 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const char*)) \
1492 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wchar_t*)) \
1493 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxCStrData&)) \
1495 inline void wxVLog##level(argclass WXUNUSED(arg), \
1496 const wxFormatString& WXUNUSED(format), \
1497 va_list WXUNUSED(argptr)) {}
1499 wxDEFINE_EMPTY_LOG_FUNCTION(FatalError
);
1500 wxDEFINE_EMPTY_LOG_FUNCTION(Error
);
1501 wxDEFINE_EMPTY_LOG_FUNCTION(SysError
);
1502 wxDEFINE_EMPTY_LOG_FUNCTION2(SysError
, long);
1503 wxDEFINE_EMPTY_LOG_FUNCTION(Warning
);
1504 wxDEFINE_EMPTY_LOG_FUNCTION(Message
);
1505 wxDEFINE_EMPTY_LOG_FUNCTION(Info
);
1506 wxDEFINE_EMPTY_LOG_FUNCTION(Verbose
);
1508 wxDEFINE_EMPTY_LOG_FUNCTION2(Generic
, wxLogLevel
);
1511 wxDEFINE_EMPTY_LOG_FUNCTION(Status
);
1512 wxDEFINE_EMPTY_LOG_FUNCTION2(Status
, wxFrame
*);
1515 // Empty Class to fake wxLogNull
1516 class WXDLLIMPEXP_BASE wxLogNull
1522 // Dummy macros to replace some functions.
1523 #define wxSysErrorCode() (unsigned long)0
1524 #define wxSysErrorMsg( X ) (const wxChar*)NULL
1526 // Fake symbolic trace masks... for those that are used frequently
1527 #define wxTRACE_OleCalls wxEmptyString // OLE interface calls
1529 #endif // wxUSE_LOG/!wxUSE_LOG
1532 // debug functions can be completely disabled in optimized builds
1534 // if these log functions are disabled, we prefer to define them as (empty)
1535 // variadic macros as this completely removes them and their argument
1536 // evaluation from the object code but if this is not supported by compiler we
1537 // use empty inline functions instead (defining them as nothing would result in
1538 // compiler warnings)
1540 // note that making wxVLogDebug/Trace() themselves (empty inline) functions is
1541 // a bad idea as some compilers are stupid enough to not inline even empty
1542 // functions if their parameters are complicated enough, but by defining them
1543 // as an empty inline function we ensure that even dumbest compilers optimise
1546 // but Borland gives "W8019: Code has no effect" for wxLogNop() so we need
1547 // to define it differently for it to avoid these warnings (same problem as
1548 // with wxUnusedVar())
1549 #define wxLogNop() { }
1551 inline void wxLogNop() { }
1555 #define wxLogDebug wxDO_LOG_IF_ENABLED(Debug)
1556 #define wxVLogDebug(format, argptr) wxDO_LOGV(Debug, format, argptr)
1557 #else // !wxUSE_LOG_DEBUG
1558 #define wxVLogDebug(fmt, valist) wxLogNop()
1560 #ifdef HAVE_VARIADIC_MACROS
1561 #define wxLogDebug(fmt, ...) wxLogNop()
1562 #else // !HAVE_VARIADIC_MACROS
1563 WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug
, 1, (const wxFormatString
&))
1565 #endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
1568 #define wxLogTrace \
1569 if ( !wxLog::IsLevelEnabled(wxLOG_Trace, wxLOG_COMPONENT) ) \
1572 wxMAKE_LOGGER(Trace).LogTrace
1573 #define wxVLogTrace \
1574 if ( !wxLog::IsLevelEnabled(wxLOG_Trace, wxLOG_COMPONENT) ) \
1577 wxMAKE_LOGGER(Trace).LogVTrace
1578 #else // !wxUSE_LOG_TRACE
1579 #define wxVLogTrace(mask, fmt, valist) wxLogNop()
1581 #ifdef HAVE_VARIADIC_MACROS
1582 #define wxLogTrace(mask, fmt, ...) wxLogNop()
1583 #else // !HAVE_VARIADIC_MACROS
1584 #if WXWIN_COMPATIBILITY_2_8
1585 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (wxTraceMask
, const wxFormatString
&))
1587 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wxString
&, const wxFormatString
&))
1589 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1590 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const char*, const char*))
1591 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wchar_t*, const wchar_t*))
1593 #endif // HAVE_VARIADIC_MACROS/!HAVE_VARIADIC_MACROS
1594 #endif // wxUSE_LOG_TRACE/!wxUSE_LOG_TRACE
1596 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
1597 // i.e. without using wxMessageBox() for example because it could crash
1598 void WXDLLIMPEXP_BASE
1599 wxSafeShowMessage(const wxString
& title
, const wxString
& text
);
1601 // ----------------------------------------------------------------------------
1602 // debug only logging functions: use them with API name and error code
1603 // ----------------------------------------------------------------------------
1606 // make life easier for people using VC++ IDE: clicking on the message
1607 // will take us immediately to the place of the failed API
1609 #define wxLogApiError(api, rc) \
1610 wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
1611 __FILE__, __LINE__, api, \
1612 (long)rc, wxSysErrorMsg(rc))
1614 #define wxLogApiError(api, rc) \
1615 wxLogDebug(wxT("In file %s at line %d: '%s' failed with ") \
1616 wxT("error 0x%08lx (%s)."), \
1617 __FILE__, __LINE__, api, \
1618 (long)rc, wxSysErrorMsg(rc))
1619 #endif // VC++/!VC++
1621 #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
1623 #else // !wxUSE_LOG_DEBUG
1624 #define wxLogApiError(api, err) wxLogNop()
1625 #define wxLogLastError(api) wxLogNop()
1626 #endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
1628 // wxCocoa has additiional trace masks
1629 #if defined(__WXCOCOA__)
1630 #include "wx/cocoa/log.h"
1633 #ifdef WX_WATCOM_ONLY_CODE
1634 #undef WX_WATCOM_ONLY_CODE
1637 // macro which disables debug logging in release builds: this is done by
1638 // default by wxIMPLEMENT_APP() so usually it doesn't need to be used explicitly
1639 #if defined(NDEBUG) && wxUSE_LOG_DEBUG
1640 #define wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD() \
1641 wxLog::SetLogLevel(wxLOG_Info)
1643 #define wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD()
1644 #endif // NDEBUG/!NDEBUG
1646 #endif // _WX_LOG_H_