]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxLog functions with a variable argument list pointer
authorGilles Depeyrot <gilles_depeyrot@mac.com>
Mon, 14 Jan 2002 07:10:34 +0000 (07:10 +0000)
committerGilles Depeyrot <gilles_depeyrot@mac.com>
Mon, 14 Jan 2002 07:10:34 +0000 (07:10 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13562 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/function.tex
docs/latex/wx/tlog.tex
include/wx/log.h
src/common/log.cpp

index db1360ce7999b19d73c2d0a94a37fb864164b70d..1a0b6d83b44478169dd93c3b5ff72feea7373adf 100644 (file)
@@ -1186,7 +1186,7 @@ Converts the character to upper case. This is implemented as a macro for efficie
 
 \membersection{::wxVsnprintf}\label{wxvsnprintf}
 
-\func{int}{wxVsnprintf}{\param{wxChar *}{buf}, \param{size\_t }{len}, \param{const wxChar *}{format}, \param{va\_list }{argptr}}
+\func{int}{wxVsnprintf}{\param{wxChar *}{buf}, \param{size\_t }{len}, \param{const wxChar *}{format}, \param{va\_list }{argPtr}}
 
 The same as \helpref{wxSnprintf}{wxsnprintf} but takes a {\tt va\_list}
 argument instead of arbitrary number of parameters.
@@ -2955,14 +2955,16 @@ wxWindows errors. See also \helpref{wxError}{wxerror}.
 \membersection{::wxLogError}\label{wxlogerror}
 
 \func{void}{wxLogError}{\param{const char*}{ formatString}, \param{...}{}}
+\func{void}{wxLogError}{\param{const char*}{ formatString}, \param{va_list}{argPtr}}
 
-The function to use for error messages, i.e. the messages that must be shown
+The functions to use for error messages, i.e. the messages that must be shown
 to the user. The default processing is to pop up a message box to inform the
 user about it.
 
 \membersection{::wxLogFatalError}\label{wxlogfatalerror}
 
 \func{void}{wxLogFatalError}{\param{const char*}{ formatString}, \param{...}{}}
+\func{void}{wxLogFatalError}{\param{const char*}{ formatString}, \param{va_list}{argPtr}}
 
 Like \helpref{wxLogError}{wxlogerror}, but also
 terminates the program with the exit code 3. Using {\it abort()} standard
@@ -2971,6 +2973,7 @@ function also terminates the program with this exit code.
 \membersection{::wxLogWarning}\label{wxlogwarning}
 
 \func{void}{wxLogWarning}{\param{const char*}{ formatString}, \param{...}{}}
+\func{void}{wxLogWarning}{\param{const char*}{ formatString}, \param{va_list}{argPtr}}
 
 For warnings - they are also normally shown to the user, but don't interrupt
 the program work.
@@ -2978,8 +2981,9 @@ the program work.
 \membersection{::wxLogMessage}\label{wxlogmessage}
 
 \func{void}{wxLogMessage}{\param{const char*}{ formatString}, \param{...}{}}
+\func{void}{wxLogMessage}{\param{const char*}{ formatString}, \param{va_list}{argPtr}}
 
-for all normal, informational messages. They also appear in a message box by
+For all normal, informational messages. They also appear in a message box by
 default (but it can be changed). Notice that the standard behaviour is to not
 show informational messages if there are any errors later - the logic being
 that the later error messages make the informational messages preceding them
@@ -2988,6 +2992,7 @@ meaningless.
 \membersection{::wxLogVerbose}\label{wxlogverbose}
 
 \func{void}{wxLogVerbose}{\param{const char*}{ formatString}, \param{...}{}}
+\func{void}{wxLogVerbose}{\param{const char*}{ formatString}, \param{va_list}{argPtr}}
 
 For verbose output. Normally, it is suppressed, but
 might be activated if the user wishes to know more details about the program
@@ -2996,18 +3001,21 @@ progress (another, but possibly confusing name for the same function is {\bf wxL
 \membersection{::wxLogStatus}\label{wxlogstatus}
 
 \func{void}{wxLogStatus}{\param{wxFrame *}{frame}, \param{const char*}{ formatString}, \param{...}{}}
+\func{void}{wxLogStatus}{\param{wxFrame *}{frame}, \param{const char*}{ formatString}, \param{va_list}{argPtr}}
 
 \func{void}{wxLogStatus}{\param{const char*}{ formatString}, \param{...}{}}
+\func{void}{wxLogStatus}{\param{const char*}{ formatString}, \param{va_list}{argPtr}}
 
-Messages logged by this function will appear in the statusbar of the {\it
+Messages logged by these functions will appear in the statusbar of the {\it
 frame} or of the top level application window by default (i.e. when using
-the second version of the function).
+the second version of the functions).
 
 If the target frame doesn't have a statusbar, the message will be lost.
 
 \membersection{::wxLogSysError}\label{wxlogsyserror}
 
 \func{void}{wxLogSysError}{\param{const char*}{ formatString}, \param{...}{}}
+\func{void}{wxLogSysError}{\param{const char*}{ formatString}, \param{va_list}{argPtr}}
 
 Mostly used by wxWindows itself, but might be handy for logging errors after
 system call (API function) failure. It logs the specified message text as well
@@ -3023,18 +3031,22 @@ of this function takes the error code explicitly as the first argument.
 \membersection{::wxLogDebug}\label{wxlogdebug}
 
 \func{void}{wxLogDebug}{\param{const char*}{ formatString}, \param{...}{}}
+\func{void}{wxLogDebug}{\param{const char*}{ formatString}, \param{va_list}{argPtr}}
 
-The right function for debug output. It only does anything at all in the debug
-mode (when the preprocessor symbol \_\_WXDEBUG\_\_ is defined) and expands to
+The right functions for debug output. They only do something in debug
+mode (when the preprocessor symbol \_\_WXDEBUG\_\_ is defined) and expand to
 nothing in release mode (otherwise).
 
 \membersection{::wxLogTrace}\label{wxlogtrace}
 
 \func{void}{wxLogTrace}{\param{const char*}{ formatString}, \param{...}{}}
+\func{void}{wxLogTrace}{\param{const char*}{ formatString}, \param{va_list}{argPtr}}
 
 \func{void}{wxLogTrace}{\param{const char *}{mask}, \param{const char *}{formatString}, \param{...}{}}
+\func{void}{wxLogTrace}{\param{const char *}{mask}, \param{const char *}{formatString}, \param{va_list}{argPtr}}
 
 \func{void}{wxLogTrace}{\param{wxTraceMask}{ mask}, \param{const char *}{formatString}, \param{...}{}}
+\func{void}{wxLogTrace}{\param{wxTraceMask}{ mask}, \param{const char *}{formatString}, \param{va_list}{argPtr}}
 
 As {\bf wxLogDebug}, trace functions only do something in debug build and
 expand to nothing in the release one. The reason for making
index 8799686e8f4e24268d8defda3343e3e283f9b999..69e642f69a8cefed652ba70a13a4a66122fb0e24 100644 (file)
@@ -20,8 +20,9 @@ functions to use with them.
 
 First of all, no knowledge of {\it wxLog} classes is needed to use them. For
 this, you should only know about {\it wxLogXXX()} functions. All of them have
-the same syntax as {\it printf()}, i.e. they take the format string as the
-first argument and a variable number of arguments. Here are all of them:
+the same syntax as {\it printf()} or {\it vprintf()} , i.e. they take the
+format string as the first argument and respectively a variable number of
+arguments or a variable argument list pointer. Here are all of them:
 
 \begin{itemize}\itemsep=0pt
 \item{\bf wxLogFatalError} which is like {\it wxLogError}, but also
@@ -46,9 +47,9 @@ bar of the active or specified (as the first argument) \helpref{wxFrame}{wxframe
 \item{\bf wxLogSysError} is mostly used by wxWindows itself, but might be
 handy for logging errors after system call (API function) failure. It logs the
 specified message text as well as the last system error
-code ({\it errno} or {\it ::GetLastError()} depending on the platform) and the corresponding error
-message. The second form of this function takes the error code explicitly as the
-first argument.
+code ({\it errno} or {\it ::GetLastError()} depending on the platform) and
+the corresponding error message. The second form of this function takes the
+error code explicitly as the first argument.
 \item{\bf wxLogDebug} is {\bf the} right function for debug output. It only
 does anything at all in the debug mode (when the preprocessor symbol
 \_\_WXDEBUG\_\_ is defined) and expands to nothing in release mode (otherwise).
@@ -70,8 +71,9 @@ generic mechanisms, but are not really adapted for wxWindows, while the log
 classes are. Some of advantages in using wxWindows log functions are:
 
 \begin{itemize}\itemsep=0pt
-\item{\bf Portability} It is a common practice to use {\it printf()} statements or
-cout/cerr C++ streams for writing out some (debug or otherwise) information.
+\item{\bf Portability} It is a common practice to use {\it printf()}
+statements or cout/cerr C++ streams for writing out some (debug or otherwise)
+information.
 Although it works just fine under Unix, these messages go strictly nowhere
 under Windows where the stdout of GUI programs is not assigned to anything.
 Thus, you might view {\it wxLogMessage()} as a simple substitute for {\it
index d7d62303dc41435aa305727052415608224e249e..006e8a467262b9d8bc3b896eb524c9d7a715e1c0 100644 (file)
@@ -475,16 +475,24 @@ WXDLLEXPORT const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0);
 // -------------------
 
 #define DECLARE_LOG_FUNCTION(level)                                 \
+extern void WXDLLEXPORT wxLog##level(const wxChar *szFormat,        \
+                                      va_list argptr);              \
 extern void WXDLLEXPORT wxLog##level(const wxChar *szFormat, ...)
 #define DECLARE_LOG_FUNCTION2(level, arg1)                          \
+extern void WXDLLEXPORT wxLog##level(arg1, const wxChar *szFormat,  \
+                                      va_list argptr);              \
 extern void WXDLLEXPORT wxLog##level(arg1, const wxChar *szFormat, ...)
 
 #else // !wxUSE_LOG
 
 // log functions do nothing at all
 #define DECLARE_LOG_FUNCTION(level)                                 \
+inline void WXDLLEXPORT wxLog##level(const wxChar *szFormat,        \
+                                     va_list argptr) {}             \
 inline void WXDLLEXPORT wxLog##level(const wxChar *szFormat, ...) {}
 #define DECLARE_LOG_FUNCTION2(level, arg1)                          \
+inline void WXDLLEXPORT wxLog##level(arg1, const wxChar *szFormat,  \
+                                     va_list argptr) {}             \
 inline void WXDLLEXPORT wxLog##level(arg1, const wxChar *szFormat, ...) {}
 
 #endif // wxUSE_LOG/!wxUSE_LOG
@@ -520,7 +528,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
@@ -533,9 +541,13 @@ DECLARE_LOG_FUNCTION2(SysError, long lErrCode);
     DECLARE_LOG_FUNCTION2(Trace, wxTraceMask mask);
 #else   //!debug
     // these functions do nothing in release builds
+    inline void wxLogDebug(const wxChar *, va_list) { }
     inline void wxLogDebug(const wxChar *, ...) { }
+    inline void wxLogTrace(const wxChar *, va_list) { }
     inline void wxLogTrace(const wxChar *, ...) { }
+    inline void wxLogTrace(wxTraceMask, const wxChar *, va_list) { }
     inline void wxLogTrace(wxTraceMask, const wxChar *, ...) { }
+    inline void wxLogTrace(const wxChar *, const wxChar *, va_list) { }
     inline void wxLogTrace(const wxChar *, const wxChar *, ...) { }
 #endif // debug/!debug
 
index 3dfb000b32b58a3ba58af98edea09a7056733798..0f91c7ba1bcd4870003d32a33744082b12b0c6df 100644 (file)
@@ -111,33 +111,42 @@ static inline bool IsLoggingEnabled()
 // ----------------------------------------------------------------------------
 
 // generic log function
-void wxLogGeneric(wxLogLevel level, const wxChar *szFormat, ...)
+void wxLogGeneric(wxLogLevel level, const wxChar *szFormat, va_list argptr)
 {
     if ( IsLoggingEnabled() ) {
         wxCRIT_SECT_LOCKER(locker, gs_csLogBuf);
 
-        va_list argptr;
-        va_start(argptr, szFormat);
         wxVsnprintf(s_szBuf, WXSIZEOF(s_szBuf), szFormat, argptr);
-        va_end(argptr);
 
         wxLog::OnLog(level, s_szBuf, time(NULL));
     }
 }
 
+void wxLogGeneric(wxLogLevel level, const wxChar *szFormat, ...)
+{
+    va_list argptr;
+    va_start(argptr, szFormat);
+    wxLogGeneric(level, szFormat, argptr);
+    va_end(argptr);
+}
+
 #define IMPLEMENT_LOG_FUNCTION(level)                               \
-  void wxLog##level(const wxChar *szFormat, ...)                    \
+  void wxLog##level(const wxChar *szFormat, va_list argptr)         \
   {                                                                 \
     if ( IsLoggingEnabled() ) {                                     \
       wxCRIT_SECT_LOCKER(locker, gs_csLogBuf);                      \
                                                                     \
-      va_list argptr;                                               \
-      va_start(argptr, szFormat);                                   \
       wxVsnprintf(s_szBuf, WXSIZEOF(s_szBuf), szFormat, argptr);    \
-      va_end(argptr);                                               \
                                                                     \
       wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL));             \
     }                                                               \
+  }                                                                 \
+  void wxLog##level(const wxChar *szFormat, ...)                    \
+  {                                                                 \
+    va_list argptr;                                                 \
+    va_start(argptr, szFormat);                                     \
+    wxLog##level(szFormat, argptr);                                 \
+    va_end(argptr);                                                 \
   }
 
 IMPLEMENT_LOG_FUNCTION(FatalError)
@@ -148,41 +157,50 @@ IMPLEMENT_LOG_FUNCTION(Info)
 IMPLEMENT_LOG_FUNCTION(Status)
 
 // same as info, but only if 'verbose' mode is on
-void wxLogVerbose(const wxChar *szFormat, ...)
+void wxLogVerbose(const wxChar *szFormat, va_list argptr)
 {
     if ( IsLoggingEnabled() ) {
         wxLog *pLog = wxLog::GetActiveTarget();
         if ( pLog != NULL && pLog->GetVerbose() ) {
             wxCRIT_SECT_LOCKER(locker, gs_csLogBuf);
 
-            va_list argptr;
-            va_start(argptr, szFormat);
             wxVsnprintf(s_szBuf, WXSIZEOF(s_szBuf), szFormat, argptr);
-            va_end(argptr);
 
             wxLog::OnLog(wxLOG_Info, s_szBuf, time(NULL));
         }
     }
 }
 
+void wxLogVerbose(const wxChar *szFormat, ...)
+{
+    va_list argptr;
+    va_start(argptr, szFormat);
+    wxLogVerbose(szFormat, argptr);
+    va_end(argptr);
+}
+
 // debug functions
 #ifdef __WXDEBUG__
 #define IMPLEMENT_LOG_DEBUG_FUNCTION(level)                         \
-  void wxLog##level(const wxChar *szFormat, ...)                    \
+  void wxLog##level(const wxChar *szFormat, va_list argptr)         \
   {                                                                 \
     if ( IsLoggingEnabled() ) {                                     \
       wxCRIT_SECT_LOCKER(locker, gs_csLogBuf);                      \
                                                                     \
-      va_list argptr;                                               \
-      va_start(argptr, szFormat);                                   \
       wxVsnprintf(s_szBuf, WXSIZEOF(s_szBuf), szFormat, argptr);    \
-      va_end(argptr);                                               \
                                                                     \
       wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL));             \
     }                                                               \
+  }                                                                 \
+  void wxLog##level(const wxChar *szFormat, ...)                    \
+  {                                                                 \
+    va_list argptr;                                                 \
+    va_start(argptr, szFormat);                                     \
+    wxLog##level(szFormat, argptr);                                 \
+    va_end(argptr);                                                 \
   }
 
-  void wxLogTrace(const wxChar *mask, const wxChar *szFormat, ...)
+  void wxLogTrace(const wxChar *mask, const wxChar *szFormat, va_list argptr)
   {
     if ( IsLoggingEnabled() && wxLog::IsAllowedTraceMask(mask) ) {
       wxCRIT_SECT_LOCKER(locker, gs_csLogBuf);
@@ -201,16 +219,21 @@ void wxLogVerbose(const wxChar *szFormat, ...)
       len -= 2;
       p += 2;
 
-      va_list argptr;
-      va_start(argptr, szFormat);
       wxVsnprintf(p, len, szFormat, argptr);
-      va_end(argptr);
-
+      
       wxLog::OnLog(wxLOG_Trace, s_szBuf, time(NULL));
     }
   }
 
-  void wxLogTrace(wxTraceMask mask, const wxChar *szFormat, ...)
+  void wxLogTrace(const wxChar *mask, const wxChar *szFormat, ...)
+  {
+    va_list argptr;
+    va_start(argptr, szFormat);
+    wxLogTrace(mask, szFormat, argptr);
+    va_end(argptr);
+  }
+
+  void wxLogTrace(wxTraceMask mask, const wxChar *szFormat, va_list argptr)
   {
     // we check that all of mask bits are set in the current mask, so
     // that wxLogTrace(wxTraceRefCount | wxTraceOle) will only do something
@@ -218,15 +241,20 @@ void wxLogVerbose(const wxChar *szFormat, ...)
     if ( IsLoggingEnabled() && ((wxLog::GetTraceMask() & mask) == mask) ) {
       wxCRIT_SECT_LOCKER(locker, gs_csLogBuf);
 
-      va_list argptr;
-      va_start(argptr, szFormat);
       wxVsnprintf(s_szBuf, WXSIZEOF(s_szBuf), szFormat, argptr);
-      va_end(argptr);
 
       wxLog::OnLog(wxLOG_Trace, s_szBuf, time(NULL));
     }
   }
 
+  void wxLogTrace(wxTraceMask mask, const wxChar *szFormat, ...)
+  {
+    va_list argptr;
+    va_start(argptr, szFormat);
+    wxLogTrace(mask, szFormat, argptr);
+    va_end(argptr);
+  }
+
 #else // release
   #define IMPLEMENT_LOG_DEBUG_FUNCTION(level)
 #endif
@@ -248,34 +276,44 @@ void wxLogSysErrorHelper(long lErrCode)
     wxLog::OnLog(wxLOG_Error, s_szBuf, time(NULL));
 }
 
-void WXDLLEXPORT wxLogSysError(const wxChar *szFormat, ...)
+void WXDLLEXPORT wxLogSysError(const wxChar *szFormat, va_list argptr)
 {
     if ( IsLoggingEnabled() ) {
         wxCRIT_SECT_LOCKER(locker, gs_csLogBuf);
 
-        va_list argptr;
-        va_start(argptr, szFormat);
         wxVsnprintf(s_szBuf, WXSIZEOF(s_szBuf), szFormat, argptr);
-        va_end(argptr);
 
         wxLogSysErrorHelper(wxSysErrorCode());
     }
 }
 
-void WXDLLEXPORT wxLogSysError(long lErrCode, const wxChar *szFormat, ...)
+void WXDLLEXPORT wxLogSysError(const wxChar *szFormat, ...)
+{
+    va_list argptr;
+    va_start(argptr, szFormat);
+    wxLogSysError(szFormat, argptr);
+    va_end(argptr);
+}
+
+void WXDLLEXPORT wxLogSysError(long lErrCode, const wxChar *szFormat, va_list argptr)
 {
     if ( IsLoggingEnabled() ) {
         wxCRIT_SECT_LOCKER(locker, gs_csLogBuf);
 
-        va_list argptr;
-        va_start(argptr, szFormat);
         wxVsnprintf(s_szBuf, WXSIZEOF(s_szBuf), szFormat, argptr);
-        va_end(argptr);
 
         wxLogSysErrorHelper(lErrCode);
     }
 }
 
+void WXDLLEXPORT wxLogSysError(long lErrCode, const wxChar *szFormat, ...)
+{
+    va_list argptr;
+    va_start(argptr, szFormat);
+    wxLogSysError(lErrCode, szFormat, argptr);
+    va_end(argptr);
+}
+
 // ----------------------------------------------------------------------------
 // wxLog class implementation
 // ----------------------------------------------------------------------------