Add wxLogFormatter to allow easier wxLog output customization.

Delegate the log string creation to wxLogFormatter. This allows defining a
custom object of a class derived from it to customize the log output instead
of having to override DoLogRecord() in wxLog itself.

Closes #13792.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70086 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-12-22 13:35:01 +00:00
parent 2cc6b51b90
commit 4ffdb64018
5 changed files with 283 additions and 74 deletions

View File

@@ -11,7 +11,7 @@
@page overview_log wxLog Classes Overview
Classes: wxLog, wxLogStderr, wxLogStream, wxLogTextCtrl, wxLogWindow, wxLogGui, wxLogNull, wxLogBuffer,
wxLogChain, wxLogInterposer, wxLogInterposerTemp, wxStreamToTextRedirector
wxLogChain, wxLogInterposer, wxLogInterposerTemp, wxStreamToTextRedirector, wxLogFormatter
Table of contents:
@li @ref overview_log_introduction
@@ -20,7 +20,6 @@ Table of contents:
@li @ref overview_log_mt
@li @ref overview_log_customize
@li @ref overview_log_tracemasks
@li @ref overview_log_timestamps
<hr>
@@ -275,8 +274,15 @@ want to redirect the log output elsewhere, without taking into account the
level of the message. If you do want to handle messages of different levels
differently, then you should override wxLog::DoLogTextAtLevel().
Finally, if more control over the output format is needed, then the first
function must be overridden as it allows to construct custom messages
Additionally, you can customize the way full log messages are constructed from
the components (such as time stamp, source file information, logging thread ID
and so on). This task is performed by wxLogFormatter class so you need to
derive a custom class from it and override its Format() method to build the log
messages in desired way. Notice that if you just need to modify (or suppress)
the time stamp display, overriding FormatTime() is enough.
Finally, if even more control over the output format is needed, then
DoLogRecord() can be overridden as it allows to construct custom messages
depending on the log level or even do completely different things depending
on the message severity (for example, throw away all messages except
warnings and errors, show warnings on the screen and forward the error
@@ -321,25 +327,5 @@ wxLog::AddTraceMask( wxTRACE_OleCalls );
The standard trace masks are given in wxLogTrace() documentation.
@section overview_log_timestamps Timestamps
The wxLog::LogRecord() function automatically prepends a time stamp
to all the messages. The format of the time stamp may be changed: it can be
any string with % specifications fully described in the documentation of the
standard @e strftime() function. For example, the default format is
@c "[%d/%b/%y %H:%M:%S] " which gives something like @c "[17/Sep/98 22:10:16] "
(without quotes) for the current date.
Setting an empty string as the time format or calling the shortcut wxLog::DisableTimestamp(),
disables timestamping of the messages completely.
@note
Timestamping 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, please
use SetTimestamp() explicitly.
*/