X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/03147cd08e78ba8a709ee019a8a51ac6b57e6f32..698052d5f125427b4ac62e1968a090f697aea8ae:/include/wx/log.h?ds=sidebyside diff --git a/include/wx/log.h b/include/wx/log.h index 5ea8d6f649..44266ab80e 100644 --- a/include/wx/log.h +++ b/include/wx/log.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: log.h +// Name: wx/log.h // Purpose: Assorted wxLogXXX functions, and wxLog (sink for logs) // Author: Vadim Zeitlin // Modified by: @@ -103,6 +103,12 @@ public: // ctor wxLog(); + // Internal buffer. + // Allow replacement of the fixed size static buffer with + // a user allocated one. Pass in NULL to restore the + // built in static buffer. + static wxChar *SetLogBuffer( wxChar *buf, size_t size = 0 ); + // these functions allow to completely disable all log messages // is logging disabled now? static bool IsEnabled() { return ms_doLog; } @@ -234,6 +240,8 @@ private: // log everything to a "FILE *", stderr by default class WXDLLEXPORT wxLogStderr : public wxLog { + DECLARE_NO_COPY_CLASS(wxLogStderr) + public: // redirect log output to a FILE wxLogStderr(FILE *fp = (FILE *) NULL); @@ -264,30 +272,6 @@ protected: #endif // wxUSE_STD_IOSTREAM -// the following log targets are only compiled in if the we're compiling the -// GUI part (andnot just the base one) of the library, they're implemented in -// src/generic/logg.cpp *and not src/common/log.cpp unlike all the rest) - -#if wxUSE_GUI - -#if wxUSE_TEXTCTRL - -// log everything to a text window (GUI only of course) -class WXDLLEXPORT wxLogTextCtrl : public wxLog -{ -public: - wxLogTextCtrl(wxTextCtrl *pTextCtrl); - -private: - // implement sink function - virtual void DoLogString(const wxChar *szString, time_t t); - - // the control we use - wxTextCtrl *m_pTextCtrl; -}; - -#endif // wxUSE_TEXTCTRL - // ---------------------------------------------------------------------------- // /dev/null log target: suppress logging until this object goes out of scope // ---------------------------------------------------------------------------- @@ -311,8 +295,8 @@ private: class WXDLLEXPORT wxLogNull { public: - wxLogNull() { m_flagOld = wxLog::EnableLogging(FALSE); } - ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld); } + wxLogNull() : m_flagOld(wxLog::EnableLogging(FALSE)) { } + ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld); } private: bool m_flagOld; // the previous value of the wxLog::ms_doLog @@ -331,7 +315,7 @@ class WXDLLEXPORT wxLogChain : public wxLog { public: wxLogChain(wxLog *logger); - virtual ~wxLogChain() { delete m_logOld; } + virtual ~wxLogChain(); // change the new log target void SetLog(wxLog *logger); @@ -368,9 +352,35 @@ private: class WXDLLEXPORT wxLogPassThrough : public wxLogChain { public: - wxLogPassThrough() : wxLogChain(this) { } + wxLogPassThrough(); }; +// ---------------------------------------------------------------------------- +// the following log targets are only compiled in if the we're compiling the +// GUI part (andnot just the base one) of the library, they're implemented in +// src/generic/logg.cpp *and not src/common/log.cpp unlike all the rest) +// ---------------------------------------------------------------------------- + +#if wxUSE_GUI + +#if wxUSE_TEXTCTRL + +// log everything to a text window (GUI only of course) +class WXDLLEXPORT wxLogTextCtrl : public wxLog +{ +public: + wxLogTextCtrl(wxTextCtrl *pTextCtrl); + +private: + // implement sink function + virtual void DoLogString(const wxChar *szString, time_t t); + + // the control we use + wxTextCtrl *m_pTextCtrl; +}; + +#endif // wxUSE_TEXTCTRL + // ---------------------------------------------------------------------------- // GUI log target, the default one for wxWindows programs // ---------------------------------------------------------------------------- @@ -466,23 +476,35 @@ private: // return the last system error code WXDLLEXPORT unsigned long wxSysErrorCode(); + // return the error message for given (or last if 0) error code WXDLLEXPORT const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0); +// ---------------------------------------------------------------------------- // define wxLog -// ------------------- +// ---------------------------------------------------------------------------- #define DECLARE_LOG_FUNCTION(level) \ -extern void WXDLLEXPORT wxLog##level(const wxChar *szFormat, ...) +extern void WXDLLEXPORT wxVLog##level(const wxChar *szFormat, \ + va_list argptr); \ +extern void WXDLLEXPORT wxLog##level(const wxChar *szFormat, \ + ...) ATTRIBUTE_PRINTF_1 #define DECLARE_LOG_FUNCTION2(level, arg1) \ -extern void WXDLLEXPORT wxLog##level(arg1, const wxChar *szFormat, ...) +extern void WXDLLEXPORT wxVLog##level(arg1, const wxChar *szFormat, \ + va_list argptr); \ +extern void WXDLLEXPORT wxLog##level(arg1, const wxChar *szFormat, \ + ...) ATTRIBUTE_PRINTF_2 #else // !wxUSE_LOG // log functions do nothing at all #define DECLARE_LOG_FUNCTION(level) \ +inline void WXDLLEXPORT wxVLog##level(const wxChar *szFormat, \ + va_list argptr) {} \ inline void WXDLLEXPORT wxLog##level(const wxChar *szFormat, ...) {} #define DECLARE_LOG_FUNCTION2(level, arg1) \ +inline void WXDLLEXPORT wxVLog##level(arg1, const wxChar *szFormat, \ + va_list argptr) {} \ inline void WXDLLEXPORT wxLog##level(arg1, const wxChar *szFormat, ...) {} #endif // wxUSE_LOG/!wxUSE_LOG @@ -518,7 +540,7 @@ DECLARE_LOG_FUNCTION2(SysError, long lErrCode); #ifdef __WXDEBUG__ DECLARE_LOG_FUNCTION(Debug); - // first king of LogTrace is uncoditional: it doesn't check the level, + // first kind of LogTrace is unconditional: it doesn't check the level, DECLARE_LOG_FUNCTION(Trace); // this second version will only log the message if the mask had been @@ -531,35 +553,38 @@ DECLARE_LOG_FUNCTION2(SysError, long lErrCode); DECLARE_LOG_FUNCTION2(Trace, wxTraceMask mask); #else //!debug // these functions do nothing in release builds + inline void wxVLogDebug(const wxChar *, va_list) { } inline void wxLogDebug(const wxChar *, ...) { } + inline void wxVLogTrace(const wxChar *, va_list) { } inline void wxLogTrace(const wxChar *, ...) { } + inline void wxVLogTrace(wxTraceMask, const wxChar *, va_list) { } inline void wxLogTrace(wxTraceMask, const wxChar *, ...) { } + inline void wxVLogTrace(const wxChar *, const wxChar *, va_list) { } inline void wxLogTrace(const wxChar *, const wxChar *, ...) { } #endif // debug/!debug +// wxLogFatalError helper: show the (fatal) error to the user in a safe way, +// i.e. without using wxMessageBox() for example because it could crash +void WXDLLEXPORT wxSafeShowMessage(const wxString& title, const wxString& text); + // ---------------------------------------------------------------------------- // debug only logging functions: use them with API name and error code // ---------------------------------------------------------------------------- -#ifndef __TFILE__ - #define __XFILE__(x) Tx) - #define __TFILE__ __XFILE__(__FILE__) -#endif - #ifdef __WXDEBUG__ // make life easier for people using VC++ IDE: clicking on the message // will take us immediately to the place of the failed API #ifdef __VISUALC__ #define wxLogApiError(api, rc) \ wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \ - __TFILE__, __LINE__, api, \ - rc, wxSysErrorMsg(rc)) + __TFILE__, __LINE__, api, \ + (long)rc, wxSysErrorMsg(rc)) #else // !VC++ #define wxLogApiError(api, rc) \ wxLogDebug(wxT("In file %s at line %d: '%s' failed with " \ - "error 0x%08lx (%s)."), \ - __TFILE__, __LINE__, api, \ - rc, wxSysErrorMsg(rc)) + "error 0x%08lx (%s)."), \ + __TFILE__, __LINE__, api, \ + (long)rc, wxSysErrorMsg(rc)) #endif // VC++/!VC++ #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode()) @@ -570,3 +595,4 @@ DECLARE_LOG_FUNCTION2(SysError, long lErrCode); #endif //debug/!debug #endif // _WX_LOG_H_ +