Version: 3.2.5
wxLogFormatter Class Reference

#include <wx/log.h>

Detailed Description

wxLogFormatter class is used to format the log messages.

It implements the default formatting and can be derived from to create custom formatters.

The default implementation formats the message into a string containing the time stamp, level-dependent prefix and the message itself.

To change it, you can derive from it and override its Format() method. For example, to include the thread id in the log messages you can use

class LogFormatterWithThread : public wxLogFormatter
{
virtual wxString Format(wxLogLevel level,
const wxString& msg,
const wxLogRecordInfo& info) const
{
return wxString::Format("[%d] %s(%d) : %s",
info.threadId, info.filename, info.line, msg);
}
};
wxLogFormatter class is used to format the log messages.
Definition: log.h:126
virtual wxString Format(wxLogLevel level, const wxString &msg, const wxLogRecordInfo &info) const
This function creates the full log message string.
Information about a log record (unit of the log output).
Definition: log.h:41
int line
The line number at which this log message was generated.
Definition: log.h:47
const char * filename
The name of the file where this log message was generated.
Definition: log.h:44
wxThreadIdType threadId
Id of the thread in which the message was generated.
Definition: log.h:79
String class for passing textual data to or receiving it from wxWidgets.
Definition: string.h:315
static wxString Format(const wxString &format,...)
This static function returns the string containing the result of calling Printf() with the passed par...
unsigned long wxLogLevel
The type used to specify a log level.
Definition: log.h:35

And then associate it with wxLog instance using its SetFormatter(). Then, if you call:

wxLogMessage(_("*** Application started ***"));
void wxLogMessage(const char *formatString,...)
For all normal, informational messages.
const wxString & _(const wxString &string)
Macro to be used around all literal strings that should be translated.

the log output could be something like:

    [7872] d:\testApp\src\testApp.cpp(85) : *** Application started ***

Library:  wxBase
Category:  Logging
See also
Logging Overview
Since
2.9.4

Public Member Functions

 wxLogFormatter ()
 The default ctor does nothing. More...
 
virtual wxString Format (wxLogLevel level, const wxString &msg, const wxLogRecordInfo &info) const
 This function creates the full log message string. More...
 

Protected Member Functions

virtual wxString FormatTimeMS (wxLongLong_t msec) const
 This function formats the time stamp part of the log message including milliseconds. More...
 
virtual wxString FormatTime (time_t time) const
 This function formats the time stamp part of the log message. More...
 

Constructor & Destructor Documentation

◆ wxLogFormatter()

wxLogFormatter::wxLogFormatter ( )

The default ctor does nothing.

Member Function Documentation

◆ Format()

virtual wxString wxLogFormatter::Format ( wxLogLevel  level,
const wxString msg,
const wxLogRecordInfo info 
) const
virtual

This function creates the full log message string.

Override it to customize the output string format.

Parameters
levelThe level of this log record, e.g. wxLOG_Error.
msgThe log message itself.
infoAll the other information (such as time, component, location...) associated with this log record.
Returns
The formatted message.
Note
Time stamping is disabled for Visual C++ users in debug builds by default because otherwise it would be impossible to directly go to the line from which the log message was generated by simply clicking in the debugger window on the corresponding error message. If you wish to enable it, override FormatTime().

◆ FormatTime()

virtual wxString wxLogFormatter::FormatTime ( time_t  time) const
protectedvirtual

This function formats the time stamp part of the log message.

Deprecated:
This function only exists for compatibility, please override FormatTimeMS() in the new code.

Override this function if you need to customize just the time stamp.

Parameters
timeTime to format.
Returns
The formatted time string, may be empty.

◆ FormatTimeMS()

virtual wxString wxLogFormatter::FormatTimeMS ( wxLongLong_t  msec) const
protectedvirtual

This function formats the time stamp part of the log message including milliseconds.

Override this function if you need to customize just the time stamp formatting in the log messages.

Parameters
msecTime to format as the number of milliseconds since 1970-01-01T00:00:00.
Returns
The formatted time string, may be empty.
Since
3.1.5