X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ff46415213f7435aa64ab4f5b7dfdbb7b31f3796..c564ca3c975aba89f8b911ace0f240c0aaf4cf73:/include/wx/log.h diff --git a/include/wx/log.h b/include/wx/log.h index 41933e8534..90dde5e6b4 100644 --- a/include/wx/log.h +++ b/include/wx/log.h @@ -29,7 +29,7 @@ typedef unsigned long wxLogLevel; #define wxTraceResAlloc 0x0004 // trace GDI resource allocation #define wxTraceRefCount 0x0008 // trace various ref counting operations - #ifdef __WXMSW__ + #ifdef __WINDOWS__ #define wxTraceOleCalls 0x0100 // OLE interface calls #endif @@ -57,11 +57,9 @@ class WXDLLIMPEXP_FWD_BASE wxObject; #include "wx/arrstr.h" -#ifndef __WXPALMOS5__ #ifndef __WXWINCE__ #include // for time_t #endif -#endif // ! __WXPALMOS5__ #include "wx/dynarray.h" #include "wx/hashmap.h" @@ -130,7 +128,7 @@ enum wxLogLevelValues #define wxTRACE_ResAlloc wxT("resalloc") // trace GDI resource allocation #define wxTRACE_RefCount wxT("refcount") // trace various ref counting operations -#ifdef __WXMSW__ +#ifdef __WINDOWS__ #define wxTRACE_OleCalls wxT("ole") // OLE interface calls #endif @@ -309,6 +307,34 @@ struct wxLogRecord wxLogRecordInfo info; }; +// ---------------------------------------------------------------------------- +// Derive from this class to customize format of log messages. +// ---------------------------------------------------------------------------- + +class WXDLLIMPEXP_BASE wxLogFormatter +{ +public: + // Default constructor. + wxLogFormatter() { } + + // Trivial but virtual destructor for the base class. + virtual ~wxLogFormatter() { } + + + // Override this method to implement custom formatting of the given log + // record. The default implementation simply prepends a level-dependent + // prefix to the message and optionally adds a time stamp. + virtual wxString Format(wxLogLevel level, + const wxString& msg, + const wxLogRecordInfo& info) const; + +protected: + // Override this method to change just the time stamp formatting. It is + // called by default Format() implementation. + virtual wxString FormatTime(time_t t) const; +}; + + // ---------------------------------------------------------------------------- // derive from this class to redirect (or suppress, or ...) log messages // normally, only a single instance of this class exists but it's not enforced @@ -318,7 +344,7 @@ class WXDLLIMPEXP_BASE wxLog { public: // ctor - wxLog() { } + wxLog() : m_formatter(new wxLogFormatter) { } // make dtor virtual for all derived classes virtual ~wxLog(); @@ -455,6 +481,26 @@ public: // call AddTraceMask() concurrently static const wxArrayString& GetTraceMasks(); + // is this trace mask in the list? + static bool IsAllowedTraceMask(const wxString& mask); + + + // log formatting + // ----------------- + + // Change wxLogFormatter object used by wxLog to format the log messages. + // + // wxLog takes ownership of the pointer passed in but the caller is + // responsible for deleting the returned pointer. + wxLogFormatter* SetFormatter(wxLogFormatter* formatter); + + + // All the time stamp related functions below only work when the default + // wxLogFormatter is being used. Defining a custom formatter overrides them + // as it could use its own time stamp format or format messages without + // using time stamp at all. + + // sets the time stamp string format: this is used as strftime() format // string for the log targets which add time stamps to the messages; set // it to empty string to disable time stamping completely. @@ -464,9 +510,6 @@ public: static void DisableTimestamp() { SetTimestamp(wxEmptyString); } - // is this trace mask in the list? - static bool IsAllowedTraceMask(const wxString& mask); - // get the current timestamp format string (maybe empty) static const wxString& GetTimestamp() { return ms_timestamp; } @@ -475,9 +518,10 @@ public: // helpers: all functions in this section are mostly for internal use only, // don't call them from your code even if they are not formally deprecated - // put the time stamp into the string if ms_timestamp != NULL (don't - // change it otherwise) + // put the time stamp into the string if ms_timestamp is not empty (don't + // change it otherwise); the first overload uses the current time. static void TimeStamp(wxString *str); + static void TimeStamp(wxString *str, time_t t); // these methods should only be called from derived classes DoLogRecord(), // DoLogTextAtLevel() and DoLogText() implementations respectively and @@ -522,14 +566,14 @@ public: #if WXWIN_COMPATIBILITY_2_6 // this function doesn't do anything any more, don't call it - wxDEPRECATED_INLINE( - static wxChar *SetLogBuffer(wxChar *, size_t = 0), return NULL; + static wxDEPRECATED_INLINE( + wxChar *SetLogBuffer(wxChar *, size_t = 0), return NULL; ); #endif // WXWIN_COMPATIBILITY_2_6 // don't use integer masks any more, use string trace masks instead #if WXWIN_COMPATIBILITY_2_8 - wxDEPRECATED_INLINE( static void SetTraceMask(wxTraceMask ulMask), + static wxDEPRECATED_INLINE( void SetTraceMask(wxTraceMask ulMask), ms_ulTraceMask = ulMask; ) // this one can't be marked deprecated as it's used in our own wxLogger @@ -621,6 +665,12 @@ private: const wxLogRecordInfo& info); + // variables + // ---------------- + + wxLogFormatter *m_formatter; // We own this pointer. + + // static variables // ---------------- @@ -1571,7 +1621,7 @@ wxSafeShowMessage(const wxString& title, const wxString& text); #endif // macro which disables debug logging in release builds: this is done by -// default by IMPLEMENT_APP() so usually it doesn't need to be used explicitly +// default by wxIMPLEMENT_APP() so usually it doesn't need to be used explicitly #if defined(NDEBUG) && wxUSE_LOG_DEBUG #define wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD() \ wxLog::SetLogLevel(wxLOG_Info)