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 /////////////////////////////////////////////////////////////////////////////
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // NB: this is needed even if wxUSE_LOG == 0
21 typedef unsigned long wxLogLevel
;
23 // the trace masks have been superseded by symbolic trace constants, they're
24 // for compatibility only and will be removed soon - do NOT use them
25 #if WXWIN_COMPATIBILITY_2_8
26 #define wxTraceMemAlloc 0x0001 // trace memory allocation (new/delete)
27 #define wxTraceMessages 0x0002 // trace window messages/X callbacks
28 #define wxTraceResAlloc 0x0004 // trace GDI resource allocation
29 #define wxTraceRefCount 0x0008 // trace various ref counting operations
32 #define wxTraceOleCalls 0x0100 // OLE interface calls
35 typedef unsigned long wxTraceMask
;
36 #endif // WXWIN_COMPATIBILITY_2_8
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 #include "wx/string.h"
43 #include "wx/strvararg.h"
45 // ----------------------------------------------------------------------------
46 // forward declarations
47 // ----------------------------------------------------------------------------
49 class WXDLLIMPEXP_FWD_BASE wxObject
;
52 class WXDLLIMPEXP_FWD_CORE wxFrame
;
57 #include "wx/arrstr.h"
60 #include <time.h> // for time_t
63 #include "wx/dynarray.h"
64 #include "wx/hashmap.h"
67 #include "wx/thread.h"
68 #endif // wxUSE_THREADS
70 // wxUSE_LOG_DEBUG enables the debug log messages
71 #ifndef wxUSE_LOG_DEBUG
73 #define wxUSE_LOG_DEBUG 1
74 #else // !wxDEBUG_LEVEL
75 #define wxUSE_LOG_DEBUG 0
79 // wxUSE_LOG_TRACE enables the trace messages, they are disabled by default
80 #ifndef wxUSE_LOG_TRACE
82 #define wxUSE_LOG_TRACE 1
83 #else // !wxDEBUG_LEVEL
84 #define wxUSE_LOG_TRACE 0
86 #endif // wxUSE_LOG_TRACE
88 // wxLOG_COMPONENT identifies the component which generated the log record and
89 // can be #define'd to a user-defined value when compiling the user code to use
90 // component-based filtering (see wxLog::SetComponentLevel())
91 #ifndef wxLOG_COMPONENT
92 // this is a variable and not a macro in order to allow the user code to
93 // just #define wxLOG_COMPONENT without #undef'ining it first
94 extern WXDLLIMPEXP_DATA_BASE(const char *) wxLOG_COMPONENT
;
97 #define wxLOG_COMPONENT "wx"
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
105 // different standard log levels (you may also define your own)
106 enum wxLogLevelValues
108 wxLOG_FatalError
, // program can't continue, abort immediately
109 wxLOG_Error
, // a serious error, user must be informed about it
110 wxLOG_Warning
, // user is normally informed about it but may be ignored
111 wxLOG_Message
, // normal message (i.e. normal output of a non GUI app)
112 wxLOG_Status
, // informational: might go to the status line of GUI app
113 wxLOG_Info
, // informational message (a.k.a. 'Verbose')
114 wxLOG_Debug
, // never shown to the user, disabled in release mode
115 wxLOG_Trace
, // trace messages are also only enabled in debug mode
116 wxLOG_Progress
, // used for progress indicator (not yet)
117 wxLOG_User
= 100, // user defined levels start here
121 // symbolic trace masks - wxLogTrace("foo", "some trace message...") will be
122 // discarded unless the string "foo" has been added to the list of allowed
123 // ones with AddTraceMask()
125 #define wxTRACE_MemAlloc wxT("memalloc") // trace memory allocation (new/delete)
126 #define wxTRACE_Messages wxT("messages") // trace window messages/X callbacks
127 #define wxTRACE_ResAlloc wxT("resalloc") // trace GDI resource allocation
128 #define wxTRACE_RefCount wxT("refcount") // trace various ref counting operations
131 #define wxTRACE_OleCalls wxT("ole") // OLE interface calls
134 #include "wx/iosfwrap.h"
136 // ----------------------------------------------------------------------------
137 // information about a log record, i.e. unit of log output
138 // ----------------------------------------------------------------------------
140 class wxLogRecordInfo
143 // default ctor creates an uninitialized object
146 memset(this, 0, sizeof(*this));
149 // normal ctor, used by wxLogger specifies the location of the log
150 // statement; its time stamp and thread id are set up here
151 wxLogRecordInfo(const char *filename_
,
154 const char *component_
)
156 filename
= filename_
;
159 component
= component_
;
161 timestamp
= time(NULL
);
164 threadId
= wxThread::GetCurrentId();
165 #endif // wxUSE_THREADS
170 // we need to define copy ctor and assignment operator because of m_data
171 wxLogRecordInfo(const wxLogRecordInfo
& other
)
176 wxLogRecordInfo
& operator=(const wxLogRecordInfo
& other
)
178 if ( &other
!= this )
187 // dtor is non-virtual, this class is not meant to be derived from
194 // the file name and line number of the file where the log record was
195 // generated, if available or NULL and 0 otherwise
196 const char *filename
;
199 // the name of the function where the log record was generated (may be NULL
200 // if the compiler doesn't support __FUNCTION__)
203 // the name of the component which generated this message, may be NULL if
204 // not set (i.e. wxLOG_COMPONENT not defined)
205 const char *component
;
207 // time of record generation
211 // id of the thread which logged this record
212 wxThreadIdType threadId
;
213 #endif // wxUSE_THREADS
216 // store an arbitrary value in this record context
218 // wxWidgets always uses keys starting with "wx.", e.g. "wx.sys_error"
219 void StoreValue(const wxString
& key
, wxUIntPtr val
)
222 m_data
= new ExtraData
;
224 m_data
->numValues
[key
] = val
;
227 void StoreValue(const wxString
& key
, const wxString
& val
)
230 m_data
= new ExtraData
;
232 m_data
->strValues
[key
] = val
;
236 // these functions retrieve the value of either numeric or string key,
237 // return false if not found
238 bool GetNumValue(const wxString
& key
, wxUIntPtr
*val
) const
243 wxStringToNumHashMap::const_iterator it
= m_data
->numValues
.find(key
);
244 if ( it
== m_data
->numValues
.end() )
252 bool GetStrValue(const wxString
& key
, wxString
*val
) const
257 wxStringToStringHashMap::const_iterator it
= m_data
->strValues
.find(key
);
258 if ( it
== m_data
->strValues
.end() )
267 void Copy(const wxLogRecordInfo
& other
)
269 memcpy(this, &other
, sizeof(*this));
271 m_data
= new ExtraData(*other
.m_data
);
274 // extra data associated with the log record: this is completely optional
275 // and can be used to pass information from the log function to the log
276 // sink (e.g. wxLogSysError() uses this to pass the error code)
279 wxStringToNumHashMap numValues
;
280 wxStringToStringHashMap strValues
;
287 #define wxLOG_KEY_TRACE_MASK "wx.trace_mask"
289 // ----------------------------------------------------------------------------
290 // log record: a unit of log output
291 // ----------------------------------------------------------------------------
295 wxLogRecord(wxLogLevel level_
,
296 const wxString
& msg_
,
297 const wxLogRecordInfo
& info_
)
306 wxLogRecordInfo info
;
309 // ----------------------------------------------------------------------------
310 // Derive from this class to customize format of log messages.
311 // ----------------------------------------------------------------------------
313 class WXDLLIMPEXP_BASE wxLogFormatter
316 // Default constructor.
319 // Trivial but virtual destructor for the base class.
320 virtual ~wxLogFormatter() { }
323 // Override this method to implement custom formatting of the given log
324 // record. The default implementation simply prepends a level-dependent
325 // prefix to the message and optionally adds a time stamp.
326 virtual wxString
Format(wxLogLevel level
,
328 const wxLogRecordInfo
& info
) const;
331 // Override this method to change just the time stamp formatting. It is
332 // called by default Format() implementation.
333 virtual wxString
FormatTime(time_t t
) const;
337 // ----------------------------------------------------------------------------
338 // derive from this class to redirect (or suppress, or ...) log messages
339 // normally, only a single instance of this class exists but it's not enforced
340 // ----------------------------------------------------------------------------
342 class WXDLLIMPEXP_BASE wxLog
346 wxLog() : m_formatter(new wxLogFormatter
) { }
348 // make dtor virtual for all derived classes
352 // log messages selection
353 // ----------------------
355 // these functions allow to completely disable all log messages or disable
356 // log messages at level less important than specified for the current
359 // is logging enabled at all now?
360 static bool IsEnabled()
363 if ( !wxThread::IsMain() )
364 return IsThreadLoggingEnabled();
365 #endif // wxUSE_THREADS
370 // change the flag state, return the previous one
371 static bool EnableLogging(bool enable
= true)
374 if ( !wxThread::IsMain() )
375 return EnableThreadLogging(enable
);
376 #endif // wxUSE_THREADS
378 bool doLogOld
= ms_doLog
;
383 // return the current global log level
384 static wxLogLevel
GetLogLevel() { return ms_logLevel
; }
386 // set global log level: messages with level > logLevel will not be logged
387 static void SetLogLevel(wxLogLevel logLevel
) { ms_logLevel
= logLevel
; }
389 // set the log level for the given component
390 static void SetComponentLevel(const wxString
& component
, wxLogLevel level
);
392 // return the effective log level for this component, falling back to
393 // parent component and to the default global log level if necessary
395 // NB: component argument is passed by value and not const reference in an
396 // attempt to encourage compiler to avoid an extra copy: as we modify
397 // the component internally, we'd create one anyhow and like this it
398 // can be avoided if the string is a temporary anyhow
399 static wxLogLevel
GetComponentLevel(wxString component
);
402 // is logging of messages from this component enabled at this level?
404 // usually always called with wxLOG_COMPONENT as second argument
405 static bool IsLevelEnabled(wxLogLevel level
, wxString component
)
407 return IsEnabled() && level
<= GetComponentLevel(component
);
411 // enable/disable messages at wxLOG_Verbose level (only relevant if the
412 // current log level is greater or equal to it)
414 // notice that verbose mode can be activated by the standard command-line
415 // '--verbose' option
416 static void SetVerbose(bool bVerbose
= true) { ms_bVerbose
= bVerbose
; }
418 // check if verbose messages are enabled
419 static bool GetVerbose() { return ms_bVerbose
; }
425 // flush shows all messages if they're not logged immediately (FILE
426 // and iostream logs don't need it, but wxLogGui does to avoid showing
427 // 17 modal dialogs one after another)
428 virtual void Flush();
430 // flush the active target if any and also output any pending messages from
431 // background threads
432 static void FlushActive();
434 // only one sink is active at each moment get current log target, will call
435 // wxAppTraits::CreateLogTarget() to create one if none exists
436 static wxLog
*GetActiveTarget();
438 // change log target, logger may be NULL
439 static wxLog
*SetActiveTarget(wxLog
*logger
);
442 // change log target for the current thread only, shouldn't be called from
443 // the main thread as it doesn't use thread-specific log target
444 static wxLog
*SetThreadActiveTarget(wxLog
*logger
);
445 #endif // wxUSE_THREADS
447 // suspend the message flushing of the main target until the next call
448 // to Resume() - this is mainly for internal use (to prevent wxYield()
449 // from flashing the messages)
450 static void Suspend() { ms_suspendCount
++; }
452 // must be called for each Suspend()!
453 static void Resume() { ms_suspendCount
--; }
455 // should GetActiveTarget() try to create a new log object if the
457 static void DontCreateOnDemand();
459 // Make GetActiveTarget() create a new log object again.
460 static void DoCreateOnDemand();
462 // log the count of repeating messages instead of logging the messages
464 static void SetRepetitionCounting(bool bRepetCounting
= true)
465 { ms_bRepetCounting
= bRepetCounting
; }
467 // gets duplicate counting status
468 static bool GetRepetitionCounting() { return ms_bRepetCounting
; }
470 // add string trace mask
471 static void AddTraceMask(const wxString
& str
);
473 // add string trace mask
474 static void RemoveTraceMask(const wxString
& str
);
476 // remove all string trace masks
477 static void ClearTraceMasks();
479 // get string trace masks: note that this is MT-unsafe if other threads can
480 // call AddTraceMask() concurrently
481 static const wxArrayString
& GetTraceMasks();
483 // is this trace mask in the list?
484 static bool IsAllowedTraceMask(const wxString
& mask
);
490 // Change wxLogFormatter object used by wxLog to format the log messages.
492 // wxLog takes ownership of the pointer passed in but the caller is
493 // responsible for deleting the returned pointer.
494 wxLogFormatter
* SetFormatter(wxLogFormatter
* formatter
);
497 // All the time stamp related functions below only work when the default
498 // wxLogFormatter is being used. Defining a custom formatter overrides them
499 // as it could use its own time stamp format or format messages without
500 // using time stamp at all.
503 // sets the time stamp string format: this is used as strftime() format
504 // string for the log targets which add time stamps to the messages; set
505 // it to empty string to disable time stamping completely.
506 static void SetTimestamp(const wxString
& ts
) { ms_timestamp
= ts
; }
508 // disable time stamping of log messages
509 static void DisableTimestamp() { SetTimestamp(wxEmptyString
); }
512 // get the current timestamp format string (maybe empty)
513 static const wxString
& GetTimestamp() { return ms_timestamp
; }
517 // helpers: all functions in this section are mostly for internal use only,
518 // don't call them from your code even if they are not formally deprecated
520 // put the time stamp into the string if ms_timestamp is not empty (don't
521 // change it otherwise); the first overload uses the current time.
522 static void TimeStamp(wxString
*str
);
523 static void TimeStamp(wxString
*str
, time_t t
);
525 // these methods should only be called from derived classes DoLogRecord(),
526 // DoLogTextAtLevel() and DoLogText() implementations respectively and
527 // shouldn't be called directly, use logging functions instead
528 void LogRecord(wxLogLevel level
,
530 const wxLogRecordInfo
& info
)
532 DoLogRecord(level
, msg
, info
);
535 void LogTextAtLevel(wxLogLevel level
, const wxString
& msg
)
537 DoLogTextAtLevel(level
, msg
);
540 void LogText(const wxString
& msg
)
545 // this is a helper used by wxLogXXX() functions, don't call it directly
546 // and see DoLog() for function to overload in the derived classes
547 static void OnLog(wxLogLevel level
,
549 const wxLogRecordInfo
& info
);
551 // version called when no information about the location of the log record
552 // generation is available (but the time stamp is), it mainly exists for
553 // backwards compatibility, don't use it in new code
554 static void OnLog(wxLogLevel level
, const wxString
& msg
, time_t t
);
556 // a helper calling the above overload with current time
557 static void OnLog(wxLogLevel level
, const wxString
& msg
)
559 OnLog(level
, msg
, time(NULL
));
563 // this method exists for backwards compatibility only, don't use
564 bool HasPendingMessages() const { return true; }
566 #if WXWIN_COMPATIBILITY_2_6
567 // this function doesn't do anything any more, don't call it
568 static wxDEPRECATED_INLINE(
569 wxChar
*SetLogBuffer(wxChar
*, size_t = 0), return NULL
;
571 #endif // WXWIN_COMPATIBILITY_2_6
573 // don't use integer masks any more, use string trace masks instead
574 #if WXWIN_COMPATIBILITY_2_8
575 static wxDEPRECATED_INLINE( void SetTraceMask(wxTraceMask ulMask
),
576 ms_ulTraceMask
= ulMask
; )
578 // this one can't be marked deprecated as it's used in our own wxLogger
579 // below but it still is deprecated and shouldn't be used
580 static wxTraceMask
GetTraceMask() { return ms_ulTraceMask
; }
581 #endif // WXWIN_COMPATIBILITY_2_8
584 // the logging functions that can be overridden: DoLogRecord() is called
585 // for every "record", i.e. a unit of log output, to be logged and by
586 // default formats the message and passes it to DoLogTextAtLevel() which in
587 // turn passes it to DoLogText() by default
589 // override this method if you want to change message formatting or do
591 virtual void DoLogRecord(wxLogLevel level
,
593 const wxLogRecordInfo
& info
);
595 // override this method to redirect output to different channels depending
596 // on its level only; if even the level doesn't matter, override
597 // DoLogText() instead
598 virtual void DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
);
600 // this function is not pure virtual as it might not be needed if you do
601 // the logging in overridden DoLogRecord() or DoLogTextAtLevel() directly
602 // but if you do not override them in your derived class you must override
603 // this one as the default implementation of it simply asserts
604 virtual void DoLogText(const wxString
& msg
);
607 // the rest of the functions are for backwards compatibility only, don't
608 // use them in new code; if you're updating your existing code you need to
609 // switch to overriding DoLogRecord/Text() above (although as long as these
610 // functions exist, log classes using them will continue to work)
611 #if WXWIN_COMPATIBILITY_2_8
612 wxDEPRECATED_BUT_USED_INTERNALLY(
613 virtual void DoLog(wxLogLevel level
, const char *szString
, time_t t
)
616 wxDEPRECATED_BUT_USED_INTERNALLY(
617 virtual void DoLog(wxLogLevel level
, const wchar_t *wzString
, time_t t
)
620 // these shouldn't be used by new code
621 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
622 virtual void DoLogString(const char *WXUNUSED(szString
),
624 wxEMPTY_PARAMETER_VALUE
627 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
628 virtual void DoLogString(const wchar_t *WXUNUSED(wzString
),
630 wxEMPTY_PARAMETER_VALUE
632 #endif // WXWIN_COMPATIBILITY_2_8
635 // log a message indicating the number of times the previous message was
636 // repeated if previous repetition counter is strictly positive, does
637 // nothing otherwise; return the old value of repetition counter
638 unsigned LogLastRepeatIfNeeded();
642 // called from FlushActive() to really log any buffered messages logged
643 // from the other threads
644 void FlushThreadMessages();
646 // these functions are called for non-main thread only by IsEnabled() and
647 // EnableLogging() respectively
648 static bool IsThreadLoggingEnabled();
649 static bool EnableThreadLogging(bool enable
= true);
650 #endif // wxUSE_THREADS
652 // get the active log target for the main thread, auto-creating it if
655 // this is called from GetActiveTarget() and OnLog() when they're called
656 // from the main thread
657 static wxLog
*GetMainThreadActiveTarget();
659 // called from OnLog() if it's called from the main thread or if we have a
660 // (presumably MT-safe) thread-specific logger and by FlushThreadMessages()
661 // when it plays back the buffered messages logged from the other threads
662 void CallDoLogNow(wxLogLevel level
,
664 const wxLogRecordInfo
& info
);
670 wxLogFormatter
*m_formatter
; // We own this pointer.
676 // if true, don't log the same message multiple times, only log it once
677 // with the number of times it was repeated
678 static bool ms_bRepetCounting
;
680 static wxLog
*ms_pLogger
; // currently active log sink
681 static bool ms_doLog
; // false => all logging disabled
682 static bool ms_bAutoCreate
; // create new log targets on demand?
683 static bool ms_bVerbose
; // false => ignore LogInfo messages
685 static wxLogLevel ms_logLevel
; // limit logging to levels <= ms_logLevel
687 static size_t ms_suspendCount
; // if positive, logs are not flushed
689 // format string for strftime(), if empty, time stamping log messages is
691 static wxString ms_timestamp
;
693 #if WXWIN_COMPATIBILITY_2_8
694 static wxTraceMask ms_ulTraceMask
; // controls wxLogTrace behaviour
695 #endif // WXWIN_COMPATIBILITY_2_8
698 // ----------------------------------------------------------------------------
699 // "trivial" derivations of wxLog
700 // ----------------------------------------------------------------------------
702 // log everything except for the debug/trace messages (which are passed to
703 // wxMessageOutputDebug) to a buffer
704 class WXDLLIMPEXP_BASE wxLogBuffer
: public wxLog
709 // get the string contents with all messages logged
710 const wxString
& GetBuffer() const { return m_str
; }
712 // show the buffer contents to the user in the best possible way (this uses
713 // wxMessageOutputMessageBox) and clear it
714 virtual void Flush();
717 virtual void DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
);
722 wxDECLARE_NO_COPY_CLASS(wxLogBuffer
);
726 // log everything to a "FILE *", stderr by default
727 class WXDLLIMPEXP_BASE wxLogStderr
: public wxLog
730 // redirect log output to a FILE
731 wxLogStderr(FILE *fp
= NULL
);
734 // implement sink function
735 virtual void DoLogText(const wxString
& msg
);
739 wxDECLARE_NO_COPY_CLASS(wxLogStderr
);
742 #if wxUSE_STD_IOSTREAM
744 // log everything to an "ostream", cerr by default
745 class WXDLLIMPEXP_BASE wxLogStream
: public wxLog
748 // redirect log output to an ostream
749 wxLogStream(wxSTD ostream
*ostr
= (wxSTD ostream
*) NULL
);
752 // implement sink function
753 virtual void DoLogText(const wxString
& msg
);
755 // using ptr here to avoid including <iostream.h> from this file
756 wxSTD ostream
*m_ostr
;
759 #endif // wxUSE_STD_IOSTREAM
761 // ----------------------------------------------------------------------------
762 // /dev/null log target: suppress logging until this object goes out of scope
763 // ----------------------------------------------------------------------------
771 // wxFile.Open() normally complains if file can't be opened, we don't
775 if ( !file.Open("bar") )
776 ... process error ourselves ...
778 // ~wxLogNull called, old log sink restored
781 class WXDLLIMPEXP_BASE wxLogNull
784 wxLogNull() : m_flagOld(wxLog::EnableLogging(false)) { }
785 ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld
); }
788 bool m_flagOld
; // the previous value of the wxLog::ms_doLog
791 // ----------------------------------------------------------------------------
792 // chaining log target: installs itself as a log target and passes all
793 // messages to the real log target given to it in the ctor but also forwards
794 // them to the previously active one
796 // note that you don't have to call SetActiveTarget() with this class, it
797 // does it itself in its ctor
798 // ----------------------------------------------------------------------------
800 class WXDLLIMPEXP_BASE wxLogChain
: public wxLog
803 wxLogChain(wxLog
*logger
);
804 virtual ~wxLogChain();
806 // change the new log target
807 void SetLog(wxLog
*logger
);
809 // this can be used to temporarily disable (and then reenable) passing
810 // messages to the old logger (by default we do pass them)
811 void PassMessages(bool bDoPass
) { m_bPassMessages
= bDoPass
; }
813 // are we passing the messages to the previous log target?
814 bool IsPassingMessages() const { return m_bPassMessages
; }
816 // return the previous log target (may be NULL)
817 wxLog
*GetOldLog() const { return m_logOld
; }
819 // override base class version to flush the old logger as well
820 virtual void Flush();
822 // call to avoid destroying the old log target
823 void DetachOldLog() { m_logOld
= NULL
; }
826 // pass the record to the old logger if needed
827 virtual void DoLogRecord(wxLogLevel level
,
829 const wxLogRecordInfo
& info
);
832 // the current log target
835 // the previous log target
838 // do we pass the messages to the old logger?
839 bool m_bPassMessages
;
841 wxDECLARE_NO_COPY_CLASS(wxLogChain
);
844 // a chain log target which uses itself as the new logger
846 #define wxLogPassThrough wxLogInterposer
848 class WXDLLIMPEXP_BASE wxLogInterposer
: public wxLogChain
854 wxDECLARE_NO_COPY_CLASS(wxLogInterposer
);
857 // a temporary interposer which doesn't destroy the old log target
858 // (calls DetachOldLog)
860 class WXDLLIMPEXP_BASE wxLogInterposerTemp
: public wxLogChain
863 wxLogInterposerTemp();
866 wxDECLARE_NO_COPY_CLASS(wxLogInterposerTemp
);
870 // include GUI log targets:
871 #include "wx/generic/logg.h"
874 // ----------------------------------------------------------------------------
876 // ----------------------------------------------------------------------------
878 // wxLogger is a helper class used by wxLogXXX() functions implementation,
879 // don't use it directly as it's experimental and subject to change (OTOH it
880 // might become public in the future if it's deemed to be useful enough)
882 // contains information about the context from which a log message originates
883 // and provides Log() vararg method which forwards to wxLog::OnLog() and passes
884 // this context to it
888 // ctor takes the basic information about the log record
889 wxLogger(wxLogLevel level
,
890 const char *filename
,
893 const char *component
)
895 m_info(filename
, line
, func
, component
)
899 // store extra data in our log record and return this object itself (so
900 // that further calls to its functions could be chained)
901 template <typename T
>
902 wxLogger
& Store(const wxString
& key
, T val
)
904 m_info
.StoreValue(key
, val
);
908 // hack for "overloaded" wxLogXXX() functions: calling this method
909 // indicates that we may have an extra first argument preceding the format
910 // string and that if we do have it, we should store it in m_info using the
911 // given key (while by default 0 value will be used)
912 wxLogger
& MaybeStore(const wxString
& key
, wxUIntPtr value
= 0)
914 wxASSERT_MSG( m_optKey
.empty(), "can only have one optional value" );
917 m_info
.StoreValue(key
, value
);
922 // non-vararg function used by wxVLogXXX():
924 // log the message at the level specified in the ctor if this log message
926 void LogV(const wxString
& format
, va_list argptr
)
928 // remember that fatal errors can't be disabled
929 if ( m_level
== wxLOG_FatalError
||
930 wxLog::IsLevelEnabled(m_level
, m_info
.component
) )
931 DoCallOnLog(format
, argptr
);
934 // overloads used by functions with optional leading arguments (whose
935 // values are stored in the key passed to MaybeStore())
936 void LogV(long num
, const wxString
& format
, va_list argptr
)
938 Store(m_optKey
, num
);
940 LogV(format
, argptr
);
943 void LogV(void *ptr
, const wxString
& format
, va_list argptr
)
945 Store(m_optKey
, wxPtrToUInt(ptr
));
947 LogV(format
, argptr
);
950 void LogVTrace(const wxString
& mask
, const wxString
& format
, va_list argptr
)
952 if ( !wxLog::IsAllowedTraceMask(mask
) )
955 Store(wxLOG_KEY_TRACE_MASK
, mask
);
957 LogV(format
, argptr
);
961 // vararg functions used by wxLogXXX():
963 // will log the message at the level specified in the ctor
965 // notice that this function supposes that the caller already checked that
966 // the level was enabled and does no checks itself
967 WX_DEFINE_VARARG_FUNC_VOID
970 1, (const wxFormatString
&),
974 // same as Log() but with an extra numeric or pointer parameters: this is
975 // used to pass an optional value by storing it in m_info under the name
976 // passed to MaybeStore() and is required to support "overloaded" versions
977 // of wxLogStatus() and wxLogSysError()
978 WX_DEFINE_VARARG_FUNC_VOID
981 2, (long, const wxFormatString
&),
982 DoLogWithNum
, DoLogWithNumUtf8
985 // unfortunately we can't use "void *" here as we get overload ambiguities
986 // with Log(wxFormatString, ...) when the first argument is a "char *" or
987 // "wchar_t *" then -- so we only allow passing wxObject here, which is
988 // ugly but fine in practice as this overload is only used by wxLogStatus()
989 // whose first argument is a wxFrame
990 WX_DEFINE_VARARG_FUNC_VOID
993 2, (wxObject
*, const wxFormatString
&),
994 DoLogWithPtr
, DoLogWithPtrUtf8
997 // log the message at the level specified as its first argument
999 // as the macros don't have access to the level argument in this case, this
1000 // function does check that the level is enabled itself
1001 WX_DEFINE_VARARG_FUNC_VOID
1004 2, (wxLogLevel
, const wxFormatString
&),
1005 DoLogAtLevel
, DoLogAtLevelUtf8
1008 // special versions for wxLogTrace() which is passed either string or
1009 // integer mask as first argument determining whether the message should be
1011 WX_DEFINE_VARARG_FUNC_VOID
1014 2, (const wxString
&, const wxFormatString
&),
1015 DoLogTrace
, DoLogTraceUtf8
1018 #if WXWIN_COMPATIBILITY_2_8
1019 WX_DEFINE_VARARG_FUNC_VOID
1022 2, (wxTraceMask
, const wxFormatString
&),
1023 DoLogTraceMask
, DoLogTraceMaskUtf8
1025 #endif // WXWIN_COMPATIBILITY_2_8
1028 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1029 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1030 1, (const wxString
&),
1031 (wxFormatString(f1
)))
1032 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1033 1, (const wxCStrData
&),
1034 (wxFormatString(f1
)))
1035 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1037 (wxFormatString(f1
)))
1038 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1039 1, (const wchar_t*),
1040 (wxFormatString(f1
)))
1042 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1043 2, (long, const wxString
&),
1044 (f1
, wxFormatString(f2
)))
1045 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1046 2, (long, const wxCStrData
&),
1047 (f1
, wxFormatString(f2
)))
1048 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1049 2, (long, const char *),
1050 (f1
, wxFormatString(f2
)))
1051 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1052 2, (long, const wchar_t *),
1053 (f1
, wxFormatString(f2
)))
1055 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1056 2, (wxObject
*, const wxString
&),
1057 (f1
, wxFormatString(f2
)))
1058 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1059 2, (wxObject
*, const wxCStrData
&),
1060 (f1
, wxFormatString(f2
)))
1061 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1062 2, (wxObject
*, const char *),
1063 (f1
, wxFormatString(f2
)))
1064 WX_VARARG_WATCOM_WORKAROUND(void, Log
,
1065 2, (wxObject
*, const wchar_t *),
1066 (f1
, wxFormatString(f2
)))
1068 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel
,
1069 2, (wxLogLevel
, const wxString
&),
1070 (f1
, wxFormatString(f2
)))
1071 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel
,
1072 2, (wxLogLevel
, const wxCStrData
&),
1073 (f1
, wxFormatString(f2
)))
1074 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel
,
1075 2, (wxLogLevel
, const char *),
1076 (f1
, wxFormatString(f2
)))
1077 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel
,
1078 2, (wxLogLevel
, const wchar_t *),
1079 (f1
, wxFormatString(f2
)))
1081 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1082 2, (const wxString
&, const wxString
&),
1083 (f1
, wxFormatString(f2
)))
1084 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1085 2, (const wxString
&, const wxCStrData
&),
1086 (f1
, wxFormatString(f2
)))
1087 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1088 2, (const wxString
&, const char *),
1089 (f1
, wxFormatString(f2
)))
1090 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1091 2, (const wxString
&, const wchar_t *),
1092 (f1
, wxFormatString(f2
)))
1094 #if WXWIN_COMPATIBILITY_2_8
1095 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1096 2, (wxTraceMask
, wxTraceMask
),
1097 (f1
, wxFormatString(f2
)))
1098 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1099 2, (wxTraceMask
, const wxCStrData
&),
1100 (f1
, wxFormatString(f2
)))
1101 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1102 2, (wxTraceMask
, const char *),
1103 (f1
, wxFormatString(f2
)))
1104 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace
,
1105 2, (wxTraceMask
, const wchar_t *),
1106 (f1
, wxFormatString(f2
)))
1107 #endif // WXWIN_COMPATIBILITY_2_8
1108 #endif // __WATCOMC__
1111 #if !wxUSE_UTF8_LOCALE_ONLY
1112 void DoLog(const wxChar
*format
, ...)
1115 va_start(argptr
, format
);
1116 DoCallOnLog(format
, argptr
);
1120 void DoLogWithNum(long num
, const wxChar
*format
, ...)
1122 Store(m_optKey
, num
);
1125 va_start(argptr
, format
);
1126 DoCallOnLog(format
, argptr
);
1130 void DoLogWithPtr(void *ptr
, const wxChar
*format
, ...)
1132 Store(m_optKey
, wxPtrToUInt(ptr
));
1135 va_start(argptr
, format
);
1136 DoCallOnLog(format
, argptr
);
1140 void DoLogAtLevel(wxLogLevel level
, const wxChar
*format
, ...)
1142 if ( !wxLog::IsLevelEnabled(level
, m_info
.component
) )
1146 va_start(argptr
, format
);
1147 DoCallOnLog(level
, format
, argptr
);
1151 void DoLogTrace(const wxString
& mask
, const wxChar
*format
, ...)
1153 if ( !wxLog::IsAllowedTraceMask(mask
) )
1156 Store(wxLOG_KEY_TRACE_MASK
, mask
);
1159 va_start(argptr
, format
);
1160 DoCallOnLog(format
, argptr
);
1164 #if WXWIN_COMPATIBILITY_2_8
1165 void DoLogTraceMask(wxTraceMask mask
, const wxChar
*format
, ...)
1167 if ( (wxLog::GetTraceMask() & mask
) != mask
)
1170 Store(wxLOG_KEY_TRACE_MASK
, mask
);
1173 va_start(argptr
, format
);
1174 DoCallOnLog(format
, argptr
);
1177 #endif // WXWIN_COMPATIBILITY_2_8
1178 #endif // !wxUSE_UTF8_LOCALE_ONLY
1180 #if wxUSE_UNICODE_UTF8
1181 void DoLogUtf8(const char *format
, ...)
1184 va_start(argptr
, format
);
1185 DoCallOnLog(format
, argptr
);
1189 void DoLogWithNumUtf8(long num
, const char *format
, ...)
1191 Store(m_optKey
, num
);
1194 va_start(argptr
, format
);
1195 DoCallOnLog(format
, argptr
);
1199 void DoLogWithPtrUtf8(void *ptr
, const char *format
, ...)
1201 Store(m_optKey
, wxPtrToUInt(ptr
));
1204 va_start(argptr
, format
);
1205 DoCallOnLog(format
, argptr
);
1209 void DoLogAtLevelUtf8(wxLogLevel level
, const char *format
, ...)
1211 if ( !wxLog::IsLevelEnabled(level
, m_info
.component
) )
1215 va_start(argptr
, format
);
1216 DoCallOnLog(level
, format
, argptr
);
1220 void DoLogTraceUtf8(const wxString
& mask
, const char *format
, ...)
1222 if ( !wxLog::IsAllowedTraceMask(mask
) )
1225 Store(wxLOG_KEY_TRACE_MASK
, mask
);
1228 va_start(argptr
, format
);
1229 DoCallOnLog(format
, argptr
);
1233 #if WXWIN_COMPATIBILITY_2_8
1234 void DoLogTraceMaskUtf8(wxTraceMask mask
, const char *format
, ...)
1236 if ( (wxLog::GetTraceMask() & mask
) != mask
)
1239 Store(wxLOG_KEY_TRACE_MASK
, mask
);
1242 va_start(argptr
, format
);
1243 DoCallOnLog(format
, argptr
);
1246 #endif // WXWIN_COMPATIBILITY_2_8
1247 #endif // wxUSE_UNICODE_UTF8
1249 void DoCallOnLog(wxLogLevel level
, const wxString
& format
, va_list argptr
)
1251 wxLog::OnLog(level
, wxString::FormatV(format
, argptr
), m_info
);
1254 void DoCallOnLog(const wxString
& format
, va_list argptr
)
1256 DoCallOnLog(m_level
, format
, argptr
);
1260 const wxLogLevel m_level
;
1261 wxLogRecordInfo m_info
;
1265 wxDECLARE_NO_COPY_CLASS(wxLogger
);
1268 // ============================================================================
1270 // ============================================================================
1272 // ----------------------------------------------------------------------------
1273 // get error code/error message from system in a portable way
1274 // ----------------------------------------------------------------------------
1276 // return the last system error code
1277 WXDLLIMPEXP_BASE
unsigned long wxSysErrorCode();
1279 // return the error message for given (or last if 0) error code
1280 WXDLLIMPEXP_BASE
const wxChar
* wxSysErrorMsg(unsigned long nErrCode
= 0);
1282 // ----------------------------------------------------------------------------
1283 // define wxLog<level>() functions which can be used by application instead of
1284 // stdio, iostream &c for log messages for easy redirection
1285 // ----------------------------------------------------------------------------
1288 The code below is unreadable because it (unfortunately unavoidably)
1289 contains a lot of macro magic but all it does is to define wxLogXXX() such
1290 that you can call them as vararg functions to log a message at the
1291 corresponding level.
1293 More precisely, it defines:
1295 - wxLog{FatalError,Error,Warning,Message,Verbose,Debug}() functions
1296 taking the format string and additional vararg arguments if needed.
1297 - wxLogGeneric(wxLogLevel level, const wxString& format, ...) which
1298 takes the log level explicitly.
1299 - wxLogSysError(const wxString& format, ...) and wxLogSysError(long
1300 err, const wxString& format, ...) which log a wxLOG_Error severity
1301 message with the error message corresponding to the system error code
1302 err or the last error.
1303 - wxLogStatus(const wxString& format, ...) which logs the message into
1304 the status bar of the main application window and its overload
1305 wxLogStatus(wxFrame *frame, const wxString& format, ...) which logs it
1306 into the status bar of the specified frame.
1307 - wxLogTrace(Mask mask, const wxString& format, ...) which only logs
1308 the message is the specified mask is enabled. This comes in two kinds:
1309 Mask can be a wxString or a long. Both are deprecated.
1311 In addition, wxVLogXXX() versions of all the functions above are also
1312 defined. They take a va_list argument instead of "...".
1315 // creates wxLogger object for the current location
1316 #define wxMAKE_LOGGER(level) \
1317 wxLogger(wxLOG_##level, __FILE__, __LINE__, __WXFUNCTION__, wxLOG_COMPONENT)
1319 // this macro generates the expression which logs whatever follows it in
1320 // parentheses at the level specified as argument
1321 #define wxDO_LOG(level) wxMAKE_LOGGER(level).Log
1323 // this is the non-vararg equivalent
1324 #define wxDO_LOGV(level, format, argptr) \
1325 wxMAKE_LOGGER(level).LogV(format, argptr)
1327 // this macro declares wxLog<level>() macro which logs whatever follows it if
1328 // logging at specified level is enabled (notice that if it is false, the
1329 // following arguments are not even evaluated which is good as it avoids
1330 // unnecessary overhead)
1332 // Note: the strange if/else construct is needed to make the following code
1335 // wxLogError("!!!");
1339 // work as expected, without it the second "else" would match the "if"
1340 // inside wxLogError(). Unfortunately code like
1343 // wxLogError("!!!");
1345 // now provokes "suggest explicit braces to avoid ambiguous 'else'"
1346 // warnings from g++ 4.3 and later with -Wparentheses on but they can be
1347 // easily fixed by adding curly braces around wxLogError() and at least
1348 // the code still does do the right thing.
1349 #define wxDO_LOG_IF_ENABLED(level) \
1350 if ( !wxLog::IsLevelEnabled(wxLOG_##level, wxLOG_COMPONENT) ) \
1355 // wxLogFatalError() is special as it can't be disabled
1356 #define wxLogFatalError wxDO_LOG(FatalError)
1357 #define wxVLogFatalError(format, argptr) wxDO_LOGV(FatalError, format, argptr)
1359 #define wxLogError wxDO_LOG_IF_ENABLED(Error)
1360 #define wxVLogError(format, argptr) wxDO_LOGV(Error, format, argptr)
1362 #define wxLogWarning wxDO_LOG_IF_ENABLED(Warning)
1363 #define wxVLogWarning(format, argptr) wxDO_LOGV(Warning, format, argptr)
1365 #define wxLogMessage wxDO_LOG_IF_ENABLED(Message)
1366 #define wxVLogMessage(format, argptr) wxDO_LOGV(Message, format, argptr)
1368 // this one is special as it only logs if we're in verbose mode
1369 #define wxLogVerbose \
1370 if ( !(wxLog::IsLevelEnabled(wxLOG_Info, wxLOG_COMPONENT) && \
1371 wxLog::GetVerbose()) ) \
1375 #define wxVLogVerbose(format, argptr) \
1376 if ( !(wxLog::IsLevelEnabled(wxLOG_Info, wxLOG_COMPONENT) && \
1377 wxLog::GetVerbose()) ) \
1380 wxDO_LOGV(Info, format, argptr)
1382 // deprecated synonyms for wxLogVerbose() and wxVLogVerbose()
1383 #define wxLogInfo wxLogVerbose
1384 #define wxVLogInfo wxVLogVerbose
1387 // another special case: the level is passed as first argument of the function
1388 // and so is not available to the macro
1390 // notice that because of this, arguments of wxLogGeneric() are currently
1391 // always evaluated, unlike for the other log functions
1392 #define wxLogGeneric wxMAKE_LOGGER(Max).LogAtLevel
1393 #define wxVLogGeneric(level, format, argptr) \
1394 if ( !wxLog::IsLevelEnabled(wxLOG_##level, wxLOG_COMPONENT) ) \
1397 wxDO_LOGV(level, format, argptr)
1400 // wxLogSysError() needs to stash the error code value in the log record info
1401 // so it needs special handling too; additional complications arise because the
1402 // error code may or not be present as the first argument
1404 // notice that we unfortunately can't avoid the call to wxSysErrorCode() even
1405 // though it may be unneeded if an explicit error code is passed to us because
1406 // the message might not be logged immediately (e.g. it could be queued for
1407 // logging from the main thread later) and so we can't to wait until it is
1408 // logged to determine whether we have last error or not as it will be too late
1409 // and it will have changed already by then (in fact it even changes when
1410 // wxString::Format() is called because of vsnprintf() inside it so it can
1411 // change even much sooner)
1412 #define wxLOG_KEY_SYS_ERROR_CODE "wx.sys_error"
1414 #define wxLogSysError \
1415 if ( !wxLog::IsLevelEnabled(wxLOG_Error, wxLOG_COMPONENT) ) \
1418 wxMAKE_LOGGER(Error).MaybeStore(wxLOG_KEY_SYS_ERROR_CODE, \
1419 wxSysErrorCode()).Log
1421 // unfortunately we can't have overloaded macros so we can't define versions
1422 // both with and without error code argument and have to rely on LogV()
1423 // overloads in wxLogger to select between them
1424 #define wxVLogSysError \
1425 wxMAKE_LOGGER(Error).MaybeStore(wxLOG_KEY_SYS_ERROR_CODE, \
1426 wxSysErrorCode()).LogV
1429 // wxLogStatus() is similar to wxLogSysError() as it allows to optionally
1430 // specify the frame to which the message should go
1431 #define wxLOG_KEY_FRAME "wx.frame"
1433 #define wxLogStatus \
1434 if ( !wxLog::IsLevelEnabled(wxLOG_Status, wxLOG_COMPONENT) ) \
1437 wxMAKE_LOGGER(Status).MaybeStore(wxLOG_KEY_FRAME).Log
1439 #define wxVLogStatus \
1440 wxMAKE_LOGGER(Status).MaybeStore(wxLOG_KEY_FRAME).LogV
1446 #undef wxUSE_LOG_DEBUG
1447 #define wxUSE_LOG_DEBUG 0
1449 #undef wxUSE_LOG_TRACE
1450 #define wxUSE_LOG_TRACE 0
1452 #if defined(__WATCOMC__) || defined(__MINGW32__)
1453 // Mingw has similar problem with wxLogSysError:
1454 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x ) x
1456 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x )
1459 // define macros for defining log functions which do nothing at all
1461 // WX_WATCOM_ONLY_CODE is needed to work around
1462 // http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1463 #define wxDEFINE_EMPTY_LOG_FUNCTION(level) \
1464 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxFormatString&)) \
1465 WX_WATCOM_ONLY_CODE( \
1466 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const char*)) \
1467 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wchar_t*)) \
1468 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxCStrData&)) \
1470 inline void wxVLog##level(const wxFormatString& WXUNUSED(format), \
1471 va_list WXUNUSED(argptr)) { } \
1473 #define wxDEFINE_EMPTY_LOG_FUNCTION2(level, argclass) \
1474 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxFormatString&)) \
1475 WX_WATCOM_OR_MINGW_ONLY_CODE( \
1476 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const char*)) \
1477 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wchar_t*)) \
1478 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxCStrData&)) \
1480 inline void wxVLog##level(argclass WXUNUSED(arg), \
1481 const wxFormatString& WXUNUSED(format), \
1482 va_list WXUNUSED(argptr)) {}
1484 wxDEFINE_EMPTY_LOG_FUNCTION(FatalError
);
1485 wxDEFINE_EMPTY_LOG_FUNCTION(Error
);
1486 wxDEFINE_EMPTY_LOG_FUNCTION(SysError
);
1487 wxDEFINE_EMPTY_LOG_FUNCTION2(SysError
, long);
1488 wxDEFINE_EMPTY_LOG_FUNCTION(Warning
);
1489 wxDEFINE_EMPTY_LOG_FUNCTION(Message
);
1490 wxDEFINE_EMPTY_LOG_FUNCTION(Info
);
1491 wxDEFINE_EMPTY_LOG_FUNCTION(Verbose
);
1493 wxDEFINE_EMPTY_LOG_FUNCTION2(Generic
, wxLogLevel
);
1496 wxDEFINE_EMPTY_LOG_FUNCTION(Status
);
1497 wxDEFINE_EMPTY_LOG_FUNCTION2(Status
, wxFrame
*);
1500 // Empty Class to fake wxLogNull
1501 class WXDLLIMPEXP_BASE wxLogNull
1507 // Dummy macros to replace some functions.
1508 #define wxSysErrorCode() (unsigned long)0
1509 #define wxSysErrorMsg( X ) (const wxChar*)NULL
1511 // Fake symbolic trace masks... for those that are used frequently
1512 #define wxTRACE_OleCalls wxEmptyString // OLE interface calls
1514 #endif // wxUSE_LOG/!wxUSE_LOG
1517 // debug functions can be completely disabled in optimized builds
1519 // if these log functions are disabled, we prefer to define them as (empty)
1520 // variadic macros as this completely removes them and their argument
1521 // evaluation from the object code but if this is not supported by compiler we
1522 // use empty inline functions instead (defining them as nothing would result in
1523 // compiler warnings)
1525 // note that making wxVLogDebug/Trace() themselves (empty inline) functions is
1526 // a bad idea as some compilers are stupid enough to not inline even empty
1527 // functions if their parameters are complicated enough, but by defining them
1528 // as an empty inline function we ensure that even dumbest compilers optimise
1531 // but Borland gives "W8019: Code has no effect" for wxLogNop() so we need
1532 // to define it differently for it to avoid these warnings (same problem as
1533 // with wxUnusedVar())
1534 #define wxLogNop() { }
1536 inline void wxLogNop() { }
1540 #define wxLogDebug wxDO_LOG_IF_ENABLED(Debug)
1541 #define wxVLogDebug(format, argptr) wxDO_LOGV(Debug, format, argptr)
1542 #else // !wxUSE_LOG_DEBUG
1543 #define wxVLogDebug(fmt, valist) wxLogNop()
1545 #ifdef HAVE_VARIADIC_MACROS
1546 #define wxLogDebug(fmt, ...) wxLogNop()
1547 #else // !HAVE_VARIADIC_MACROS
1548 WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug
, 1, (const wxFormatString
&))
1550 #endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
1553 #define wxLogTrace \
1554 if ( !wxLog::IsLevelEnabled(wxLOG_Trace, wxLOG_COMPONENT) ) \
1557 wxMAKE_LOGGER(Trace).LogTrace
1558 #define wxVLogTrace \
1559 if ( !wxLog::IsLevelEnabled(wxLOG_Trace, wxLOG_COMPONENT) ) \
1562 wxMAKE_LOGGER(Trace).LogVTrace
1563 #else // !wxUSE_LOG_TRACE
1564 #define wxVLogTrace(mask, fmt, valist) wxLogNop()
1566 #ifdef HAVE_VARIADIC_MACROS
1567 #define wxLogTrace(mask, fmt, ...) wxLogNop()
1568 #else // !HAVE_VARIADIC_MACROS
1569 #if WXWIN_COMPATIBILITY_2_8
1570 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (wxTraceMask
, const wxFormatString
&))
1572 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wxString
&, const wxFormatString
&))
1574 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1575 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const char*, const char*))
1576 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace
, 2, (const wchar_t*, const wchar_t*))
1578 #endif // HAVE_VARIADIC_MACROS/!HAVE_VARIADIC_MACROS
1579 #endif // wxUSE_LOG_TRACE/!wxUSE_LOG_TRACE
1581 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
1582 // i.e. without using wxMessageBox() for example because it could crash
1583 void WXDLLIMPEXP_BASE
1584 wxSafeShowMessage(const wxString
& title
, const wxString
& text
);
1586 // ----------------------------------------------------------------------------
1587 // debug only logging functions: use them with API name and error code
1588 // ----------------------------------------------------------------------------
1591 // make life easier for people using VC++ IDE: clicking on the message
1592 // will take us immediately to the place of the failed API
1594 #define wxLogApiError(api, rc) \
1595 wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
1596 __FILE__, __LINE__, api, \
1597 (long)rc, wxSysErrorMsg(rc))
1599 #define wxLogApiError(api, rc) \
1600 wxLogDebug(wxT("In file %s at line %d: '%s' failed with ") \
1601 wxT("error 0x%08lx (%s)."), \
1602 __FILE__, __LINE__, api, \
1603 (long)rc, wxSysErrorMsg(rc))
1604 #endif // VC++/!VC++
1606 #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
1608 #else // !wxUSE_LOG_DEBUG
1609 #define wxLogApiError(api, err) wxLogNop()
1610 #define wxLogLastError(api) wxLogNop()
1611 #endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
1613 // wxCocoa has additiional trace masks
1614 #if defined(__WXCOCOA__)
1615 #include "wx/cocoa/log.h"
1618 #ifdef WX_WATCOM_ONLY_CODE
1619 #undef WX_WATCOM_ONLY_CODE
1622 // macro which disables debug logging in release builds: this is done by
1623 // default by wxIMPLEMENT_APP() so usually it doesn't need to be used explicitly
1624 #if defined(NDEBUG) && wxUSE_LOG_DEBUG
1625 #define wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD() \
1626 wxLog::SetLogLevel(wxLOG_Info)
1628 #define wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD()
1629 #endif // NDEBUG/!NDEBUG
1631 #endif // _WX_LOG_H_