Contents Up Previous Next

Log functions

These functions provide a variety of logging functions: see Log classes overview for further information. The functions use (implicitly) the currently active log target, so their descriptions here may not apply if the log target is not the standard one (installed by wxWidgets in the beginning of the program).

Include files

<wx/log.h>

::wxDebugMsg
::wxError
::wxFatalError
::wxLogError
::wxLogFatalError
::wxLogWarning
::wxLogMessage
::wxLogVerbose
::wxLogStatus
::wxLogSysError
::wxLogDebug
::wxLogTrace
::wxSafeShowMessage
::wxSysErrorCode
::wxSysErrorMsg
WXTRACE
WXTRACELEVEL
::wxTrace
::wxTraceLevel


::wxDebugMsg

void wxDebugMsg(const wxString& fmt, ...)

NB: This function is now obsolete, replaced by Log functions and wxLogDebug in particular.

Display a debugging message; under Windows, this will appear on the debugger command window, and under Unix, it will be written to standard error.

The syntax is identical to printf: pass a format string and a variable list of arguments.

Tip: under Windows, if your application crashes before the message appears in the debugging window, put a wxYield call after each wxDebugMsg call. wxDebugMsg seems to be broken under WIN32s (at least for Watcom C++): preformat your messages and use OutputDebugString instead.

Include files

<wx/utils.h>


::wxError

void wxError(const wxString& msg, const wxString& title = "wxWidgets Internal Error")

NB: This function is now obsolete, please use wxLogError instead.

Displays msg and continues. This writes to standard error under Unix, and pops up a message box under Windows. Used for internal wxWidgets errors. See also wxFatalError.

Include files

<wx/utils.h>


::wxFatalError

void wxFatalError(const wxString& msg, const wxString& title = "wxWidgets Fatal Error")

NB: This function is now obsolete, please use wxLogFatalError instead.

Displays msg and exits. This writes to standard error under Unix, and pops up a message box under Windows. Used for fatal internal wxWidgets errors. See also wxError.

Include files

<wx/utils.h>


::wxLogError

void wxLogError(const char *formatString, ...)

void wxVLogError(const char *formatString, va_list argPtr)

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.


::wxLogFatalError

void wxLogFatalError(const char *formatString, ...)

void wxVLogFatalError(const char *formatString, va_list argPtr)

Like wxLogError, but also terminates the program with the exit code 3. Using abort() standard function also terminates the program with this exit code.


::wxLogWarning

void wxLogWarning(const char *formatString, ...)

void wxVLogWarning(const char *formatString, va_list argPtr)

For warnings - they are also normally shown to the user, but don't interrupt the program work.


::wxLogMessage

void wxLogMessage(const char *formatString, ...)

void wxVLogMessage(const char *formatString, va_list argPtr)

For all normal, informational messages. They also appear in a message box by default (but it can be changed).


::wxLogVerbose

void wxLogVerbose(const char *formatString, ...)

void wxVLogVerbose(const char *formatString, 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 progress (another, but possibly confusing name for the same function is wxLogInfo).


::wxLogStatus

void wxLogStatus(wxFrame *frame, const char *formatString, ...)

void wxVLogStatus(wxFrame *frame, const char *formatString, va_list argPtr)

void wxLogStatus(const char *formatString, ...)

void wxVLogStatus(const char *formatString, va_list argPtr)

Messages logged by these functions will appear in the statusbar of the frame or of the top level application window by default (i.e. when using the second version of the functions).

If the target frame doesn't have a statusbar, the message will be lost.


::wxLogSysError

void wxLogSysError(const char *formatString, ...)

void wxVLogSysError(const char *formatString, va_list argPtr)

Mostly used by wxWidgets 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 (errno or ::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.

See also

wxSysErrorCode, wxSysErrorMsg


::wxLogDebug

void wxLogDebug(const char *formatString, ...)

void wxVLogDebug(const char *formatString, va_list argPtr)

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).


::wxLogTrace

void wxLogTrace(const char *formatString, ...)

void wxVLogTrace(const char *formatString, va_list argPtr)

void wxLogTrace(const char *mask, const char *formatString, ...)

void wxVLogTrace(const char *mask, const char *formatString, va_list argPtr)

void wxLogTrace(wxTraceMask mask, const char *formatString, ...)

void wxVLogTrace(wxTraceMask mask, const char *formatString, va_list argPtr)

As wxLogDebug, trace functions only do something in debug build and expand to nothing in the release one. The reason for making it a separate function from it is that usually there are a lot of trace messages, so it might make sense to separate them from other debug messages.

The trace messages also usually can be separated into different categories and the second and third versions of this function only log the message if the mask which it has is currently enabled in wxLog. This allows to selectively trace only some operations and not others by changing the value of the trace mask (possible during the run-time).

For the second function (taking a string mask), the message is logged only if the mask has been previously enabled by the call to AddTraceMask or by setting WXTRACE environment variable. The predefined string trace masks used by wxWidgets are:

Caveats: since both the mask and the format string are strings, this might lead to function signature confusion in some cases: if you intend to call the format string only version of wxLogTrace, then add a %s format string parameter and then supply a second string parameter for that %s, the string mask version of wxLogTrace will erroneously get called instead, since you are supplying two string parameters to the function. In this case you'll unfortunately have to avoid having two leading string parameters, e.g. by adding a bogus integer (with its %d format string).

The third version of the function only logs the message if all the bits corresponding to the mask are set in the wxLog trace mask which can be set by SetTraceMask. This version is less flexible than the previous one because it doesn't allow defining the user trace masks easily - this is why it is deprecated in favour of using string trace masks.


::wxSafeShowMessage

void wxSafeShowMessage(const wxString& title, const wxString& text)

This function shows a message to the user in a safe way and should be safe to call even before the application has been initialized or if it is currently in some other strange state (for example, about to crash). Under Windows this function shows a message box using a native dialog instead of wxMessageBox (which might be unsafe to call), elsewhere it simply prints the message to the standard output using the title as prefix.

Parameters

title

text

See also

wxLogFatalError

Include files

<wx/log.h>


::wxSysErrorCode

unsigned long wxSysErrorCode()

Returns the error code from the last system call. This function uses errno on Unix platforms and GetLastError under Win32.

See also

wxSysErrorMsg, wxLogSysError


::wxSysErrorMsg

const wxChar * wxSysErrorMsg(unsigned long errCode = 0)

Returns the error message corresponding to the given system error code. If errCode is 0 (default), the last error code (as returned by wxSysErrorCode) is used.

See also

wxSysErrorCode, wxLogSysError


WXTRACE

Include files

<wx/object.h>

WXTRACE(formatString, ...)

NB: This macro is now obsolete, replaced by Log functions.

Calls wxTrace with printf-style variable argument syntax. Output is directed to the current output stream (see wxDebugContext).

Include files

<wx/memory.h>


WXTRACELEVEL

WXTRACELEVEL(level, formatString, ...)

NB: This function is now obsolete, replaced by Log functions.

Calls wxTraceLevel with printf-style variable argument syntax. Output is directed to the current output stream (see wxDebugContext). The first argument should be the level at which this information is appropriate. It will only be output if the level returned by wxDebugContext::GetLevel is equal to or greater than this value.

Include files

<wx/memory.h>


::wxTrace

void wxTrace(const wxString& fmt, ...)

NB: This function is now obsolete, replaced by Log functions.

Takes printf-style variable argument syntax. Output is directed to the current output stream (see wxDebugContext).

Include files

<wx/memory.h>


::wxTraceLevel

void wxTraceLevel(int level, const wxString& fmt, ...)

NB: This function is now obsolete, replaced by Log functions.

Takes printf-style variable argument syntax. Output is directed to the current output stream (see wxDebugContext). The first argument should be the level at which this information is appropriate. It will only be output if the level returned by wxDebugContext::GetLevel is equal to or greater than this value.

Include files

<wx/memory.h>