File: overview_log.html

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (162 lines) | stat: -rw-r--r-- 33,168 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>wxWidgets: Logging Overview</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page_container">
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0" style="width: 100%;">
 <tbody>
 <tr>
  <td id="projectlogo">
    <a href="http://www.wxwidgets.org/" target="_new">
      <img alt="wxWidgets" src="logo.png"/>
    </a>
  </td>
  <td style="padding-left: 0.5em; text-align: right;">
   <span id="projectnumber">Version: 3.0.2</span>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- Generated by Doxygen 1.8.2 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Categories</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="index.html">Documentation</a></li><li class="navelem"><a class="el" href="page_topics.html">Programming Guides</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Logging Overview </div>  </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#overview_log_enable">Log Messages Selection</a></li>
<li class="level1"><a href="#overview_log_targets">Log Targets</a></li>
<li class="level1"><a href="#overview_log_mt">Logging in Multi-Threaded Applications</a></li>
<li class="level1"><a href="#overview_log_customize">Logging Customization</a></li>
<li class="level1"><a href="#overview_log_tracemasks">Using Trace Masks</a></li>
</ul>
</div>
<div class="textblock"><p>This is a general overview of logging classes provided by wxWidgets.</p>
<p>The word logging here has a broad sense, including all of the program output, not only non-interactive messages. The logging facilities included in wxWidgets provide the base <a class="el" href="classwx_log.html" title="wxLog class defines the interface for the log targets used by wxWidgets logging functions as explaine...">wxLog</a> class which defines the standard interface for a <em>log</em> target as well as several standard implementations of it and a family of functions to use with them.</p>
<p>First of all, no knowledge of <a class="el" href="classwx_log.html" title="wxLog class defines the interface for the log targets used by wxWidgets logging functions as explaine...">wxLog</a> classes is needed to use them. For this, you should only know about <a class="el" href="group__group__funcmacro__log.html">wxLogXXX() functions</a>. All of them have the same syntax as <em>printf()</em> or <em>vprintf()</em> , 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:</p>
<ul>
<li><a class="el" href="group__group__funcmacro__log.html#ga4ae39c06cbeaa5461cd1b5c293a31403" title="Like wxLogError(), but also terminates the program with the exit code 3.">wxLogFatalError()</a> which is like <a class="el" href="group__group__funcmacro__log.html#ga0dd3c633f990f794e76065c9a7af4c87" title="The functions to use for error messages, i.e.">wxLogError()</a>, but also terminates the program with the exit code 3 (using <em>abort()</em> standard function). Unlike for all the other logging functions, this function can't be overridden by a log target. </li>
<li><a class="el" href="group__group__funcmacro__log.html#ga0dd3c633f990f794e76065c9a7af4c87" title="The functions to use for error messages, i.e.">wxLogError()</a> is the function 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. </li>
<li><a class="el" href="group__group__funcmacro__log.html#ga0c2b19580ef6721508e6d69534b10e90" title="For warnings - they are also normally shown to the user, but don&#39;t interrupt the program work...">wxLogWarning()</a> for warnings. They are also normally shown to the user, but don't interrupt the program work. </li>
<li><a class="el" href="group__group__funcmacro__log.html#ga249358701f3c2d410088ddf7a61d8564" title="For all normal, informational messages.">wxLogMessage()</a> is for all normal, informational messages. They also appear in a message box by default (but it can be changed, see below). </li>
<li><a class="el" href="group__group__funcmacro__log.html#gaf57b7e28ab76bacf10b3be044e8bd634" title="For verbose output.">wxLogVerbose()</a> is 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). </li>
<li><a class="el" href="group__group__funcmacro__log.html#gac241ed1e5d13c7a552f58307c7f16691" title="Messages logged by this function will appear in the statusbar of the frame or of the top level applic...">wxLogStatus()</a> is for status messages. They will go into the status bar of the active or specified (as the first argument) <a class="el" href="classwx_frame.html" title="A frame is a window whose size and position can (usually) be changed by the user.">wxFrame</a> if it has one. </li>
<li><a class="el" href="group__group__funcmacro__log.html#ga28f01715af5aaf37caffdc5bc00fde3f" title="Mostly used by wxWidgets itself, but might be handy for logging errors after system call (API functio...">wxLogSysError()</a> is 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 (<em>errno</em> or Windows' <em>GetLastError()</em> depending on the platform) and the corresponding error message. The second form of this function takes the error code explicitly as the first argument. </li>
<li><a class="el" href="group__group__funcmacro__log.html#ga9c530ae20eb423744f90874d2c97d02b" title="The right functions for debug output.">wxLogDebug()</a> is <b>the</b> right function for debug output. It only does anything at all in the debug mode (when the preprocessor symbol <code><b>WXDEBUG</b></code> is defined) and expands to nothing in release mode (otherwise). Note that under Windows, you must either run the program under debugger or use a 3rd party program such as DebugView (<a href="http://www.microsoft.com/technet/sysinternals/Miscellaneous/DebugView.mspx">http://www.microsoft.com/technet/sysinternals/Miscellaneous/DebugView.mspx</a>) to actually see the debug output. </li>
<li><a class="el" href="group__group__funcmacro__log.html#ga947e317db477914c12b13c4534867ec9" title="Log a message at wxLOG_Trace log level (see wxLogLevelValues enum).">wxLogTrace()</a> as <a class="el" href="group__group__funcmacro__log.html#ga9c530ae20eb423744f90874d2c97d02b" title="The right functions for debug output.">wxLogDebug()</a> only does something in debug build. 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 which would be flooded in them. Moreover, the second version of this function takes a trace mask as the first argument which allows to further restrict the amount of messages generated.</li>
</ul>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="group__group__funcmacro__log.html">Logging Functions and Macros</a></dd></dl>
<p>The usage of these functions should be fairly straightforward, however it may be asked why not use the other logging facilities, such as C standard stdio functions or C++ streams. The short answer is that they're all very good generic mechanisms, but are not really adapted for wxWidgets, while the log classes are. Some of advantages in using wxWidgets log functions are:</p>
<ul>
<li><b>Portability:</b> It is a common practice to use <em>printf()</em> 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 <a class="el" href="group__group__funcmacro__log.html#ga249358701f3c2d410088ddf7a61d8564" title="For all normal, informational messages.">wxLogMessage()</a> as a simple substitute for <em>printf()</em>. You can also redirect the <em>wxLogXXX</em> calls to <em>cout</em> by just writing: <div class="fragment"><div class="line"><a class="code" href="classwx_log.html" title="wxLog class defines the interface for the log targets used by wxWidgets logging functions as explaine...">wxLog</a>* logger = <span class="keyword">new</span> <a class="code" href="classwx_log_stream.html" title="This class can be used to redirect the log messages to a C++ stream.">wxLogStream</a>(&amp;cout);</div>
<div class="line"><a class="code" href="classwx_log.html#ac7ea85f71c8d3ecd4247f412be410505" title="Sets the specified log target as the active one.">wxLog::SetActiveTarget</a>(logger);</div>
</div><!-- fragment --> Finally, there is also a possibility to redirect the output sent to <em>cout</em> to a <a class="el" href="classwx_text_ctrl.html" title="A text control allows text to be displayed and edited.">wxTextCtrl</a> by using the <a class="el" href="classwx_stream_to_text_redirector.html" title="This class can be used to (temporarily) redirect all output sent to a C++ ostream object to a wxTextC...">wxStreamToTextRedirector</a> class. </li>
<li><b>Flexibility:</b> The output of <a class="el" href="classwx_log.html" title="wxLog class defines the interface for the log targets used by wxWidgets logging functions as explaine...">wxLog</a> functions can be redirected or suppressed entirely based on their importance, which is either impossible or difficult to do with traditional methods. For example, only error messages, or only error messages and warnings might be logged, filtering out all informational messages. </li>
<li><b>Completeness:</b> Usually, an error message should be presented to the user when some operation fails. Let's take a quite simple but common case of a file error: suppose that you're writing your data file on disk and there is not enough space. The actual error might have been detected inside wxWidgets code (say, in <a class="el" href="classwx_file.html#a0974a92a5c8793629fd9ee0f1735657c" title="Write data to the file (descriptor).">wxFile::Write</a>), so the calling function doesn't really know the exact reason of the failure, it only knows that the data file couldn't be written to the disk. However, as wxWidgets uses <a class="el" href="group__group__funcmacro__log.html#ga0dd3c633f990f794e76065c9a7af4c87" title="The functions to use for error messages, i.e.">wxLogError()</a> in this situation, the exact error code (and the corresponding error message) will be given to the user together with "high level" message about data file writing error.</li>
</ul>
<h1><a class="anchor" id="overview_log_enable"></a>
Log Messages Selection</h1>
<p>By default, most log messages are enabled. In particular, this means that errors logged by wxWidgets code itself (e.g. when it fails to perform some operation, for instance <a class="el" href="classwx_file.html#a70f2abe0e310dcf77ea6aeaac60df25b" title="Opens the file, returning true if successful.">wxFile::Open()</a> logs an error when it fails to open a file) will be processed and shown to the user. To disable the logging entirely you can use <a class="el" href="classwx_log.html#a58bbfc0831eb47f0d88c9350d1f6e02d" title="Globally enable or disable logging.">wxLog::EnableLogging()</a> method or, more usually, <a class="el" href="classwx_log_null.html" title="This class allows you to temporarily suspend logging.">wxLogNull</a> class which temporarily disables logging and restores it back to the original setting when it is destroyed.</p>
<p>To limit logging to important messages only, you may use <a class="el" href="classwx_log.html#a4ea68379469ca27f645d5f91c2d42b3b" title="Specifies that log messages with level greater (numerically) than logLevel should be ignored and not ...">wxLog::SetLogLevel()</a> with e.g. wxLOG_Warning value &ndash; this will completely disable all logging messages with the severity less than warnings, so <a class="el" href="group__group__funcmacro__log.html#ga249358701f3c2d410088ddf7a61d8564" title="For all normal, informational messages.">wxLogMessage()</a> output won't be shown to the user any more.</p>
<p>Moreover, the log level can be set separately for different log components. Before showing how this can be useful, let us explain what log components are: they are simply arbitrary strings identifying the component, or module, which generated the message. They are hierarchical in the sense that "foo/bar/baz" component is supposed to be a child of "foo". And all components are children of the unnamed root component.</p>
<p>By default, all messages logged by wxWidgets originate from "wx" component or one of its subcomponents such as "wx/net/ftp", while the messages logged by your own code are assigned empty log component. To change this, you need to define <code>wxLOG_COMPONENT</code> to a string uniquely identifying each component, e.g. you could give it the value "MyProgram" by default and re-define it as "MyProgram/DB" in the module working with the database and "MyProgram/DB/Trans" in its part managing the transactions. Then you could use <a class="el" href="classwx_log.html#a7ae244e71dff20efd3a37b3718841a39" title="Sets the log level for the given component.">wxLog::SetComponentLevel()</a> in the following ways:</p>
<div class="fragment"><div class="line"><span class="comment">// disable all database error messages, everybody knows databases never</span></div>
<div class="line"><span class="comment">// fail anyhow</span></div>
<div class="line"><a class="code" href="classwx_log.html#a7ae244e71dff20efd3a37b3718841a39" title="Sets the log level for the given component.">wxLog::SetComponentLevel</a>(<span class="stringliteral">&quot;MyProgram/DB&quot;</span>, <a class="code" href="interface_2wx_2log_8h.html#aacf1e0ade132ca66e9414ee658c94887a84fba9c5b2a134eef33710303503bc5b" title="program can&#39;t continue, abort immediately">wxLOG_FatalError</a>);</div>
<div class="line"></div>
<div class="line"><span class="comment">// but enable tracing for the transactions as somehow our changes don&#39;t</span></div>
<div class="line"><span class="comment">// get committed sometimes</span></div>
<div class="line"><a class="code" href="classwx_log.html#a7ae244e71dff20efd3a37b3718841a39" title="Sets the log level for the given component.">wxLog::SetComponentLevel</a>(<span class="stringliteral">&quot;MyProgram/DB/Trans&quot;</span>, <a class="code" href="interface_2wx_2log_8h.html#aacf1e0ade132ca66e9414ee658c94887a897a7912d3d8eb59e913b1b45af94455" title="trace messages are also only enabled in debug mode">wxLOG_Trace</a>);</div>
<div class="line"></div>
<div class="line"><span class="comment">// also enable tracing messages from wxWidgets dynamic module loading</span></div>
<div class="line"><span class="comment">// mechanism</span></div>
<div class="line"><a class="code" href="classwx_log.html#a7ae244e71dff20efd3a37b3718841a39" title="Sets the log level for the given component.">wxLog::SetComponentLevel</a>(<span class="stringliteral">&quot;wx/base/module&quot;</span>, <a class="code" href="interface_2wx_2log_8h.html#aacf1e0ade132ca66e9414ee658c94887a897a7912d3d8eb59e913b1b45af94455" title="trace messages are also only enabled in debug mode">wxLOG_Trace</a>);</div>
</div><!-- fragment --><p>Notice that the log level set explicitly for the transactions code overrides the log level of the parent component but that all other database code subcomponents inherit its setting by default and so won't generate any log messages at all.</p>
<h1><a class="anchor" id="overview_log_targets"></a>
Log Targets</h1>
<p>After having enumerated all the functions which are normally used to log the messages, and why would you want to use them, we now describe how all this works.</p>
<p>wxWidgets has the notion of a <em>log target</em>: it is just a class deriving from <a class="el" href="classwx_log.html" title="wxLog class defines the interface for the log targets used by wxWidgets logging functions as explaine...">wxLog</a>. As such, it implements the virtual functions of the base class which are called when a message is logged. Only one log target is <em>active</em> at any moment, this is the one used by <a class="el" href="group__group__funcmacro__log.html">wxLogXXX() functions</a>. The normal usage of a log object (i.e. object of a class derived from <a class="el" href="classwx_log.html" title="wxLog class defines the interface for the log targets used by wxWidgets logging functions as explaine...">wxLog</a>) is to install it as the active target with a call to <em>SetActiveTarget()</em> and it will be used automatically by all subsequent calls to <a class="el" href="group__group__funcmacro__log.html">wxLogXXX() functions</a>.</p>
<p>To create a new log target class you only need to derive it from <a class="el" href="classwx_log.html" title="wxLog class defines the interface for the log targets used by wxWidgets logging functions as explaine...">wxLog</a> and override one or several of <a class="el" href="classwx_log.html#aede0ff7812690d487de845b7f3095dfd" title="Called to log a new record.">wxLog::DoLogRecord()</a>, <a class="el" href="classwx_log.html#a3fafbd3b87ff2d08dfdd1378d35013bb" title="Called to log the specified string at given level.">wxLog::DoLogTextAtLevel()</a> and <a class="el" href="classwx_log.html#a18c877e0038afe284757512b866b0aac" title="Called to log the specified string.">wxLog::DoLogText()</a> in it. The first one is the most flexible and allows you to change the formatting of the messages, dynamically filter and redirect them and so on &ndash; all log messages, except for those generated by <a class="el" href="group__group__funcmacro__log.html#ga4ae39c06cbeaa5461cd1b5c293a31403" title="Like wxLogError(), but also terminates the program with the exit code 3.">wxLogFatalError()</a>, pass by this function. <a class="el" href="classwx_log.html#a3fafbd3b87ff2d08dfdd1378d35013bb" title="Called to log the specified string at given level.">wxLog::DoLogTextAtLevel()</a> should be overridden if you simply want to redirect the log messages somewhere else, without changing their formatting. Finally, it is enough to override <a class="el" href="classwx_log.html#a18c877e0038afe284757512b866b0aac" title="Called to log the specified string.">wxLog::DoLogText()</a> if you only want to redirect the log messages and the destination doesn't depend on the message log level.</p>
<p>There are some predefined classes deriving from <a class="el" href="classwx_log.html" title="wxLog class defines the interface for the log targets used by wxWidgets logging functions as explaine...">wxLog</a> and which might be helpful to see how you can create a new log target class and, of course, may also be used without any change. There are:</p>
<ul>
<li><a class="el" href="classwx_log_stderr.html" title="This class can be used to redirect the log messages to a C file stream (not to be confused with C++ s...">wxLogStderr</a>: This class logs messages to a <code>FILE *</code>, using stderr by default as its name suggests. </li>
<li><a class="el" href="classwx_log_stream.html" title="This class can be used to redirect the log messages to a C++ stream.">wxLogStream</a>: This class has the same functionality as <a class="el" href="classwx_log_stderr.html" title="This class can be used to redirect the log messages to a C file stream (not to be confused with C++ s...">wxLogStderr</a>, but uses <em>ostream</em> and cerr instead of <code>FILE *</code> and stderr. </li>
<li><a class="el" href="classwx_log_gui.html" title="This is the default log target for the GUI wxWidgets applications.">wxLogGui</a>: This is the standard log target for wxWidgets applications (it is used by default if you don't do anything) and provides the most reasonable handling of all types of messages for given platform. </li>
<li><a class="el" href="classwx_log_window.html" title="This class represents a background log window: to be precise, it collects all log messages in the log...">wxLogWindow</a>: This log target provides a "log console" which collects all messages generated by the application and also passes them to the previous active log target. The log window frame has a menu allowing user to clear the log, close it completely or save all messages to file. </li>
<li><a class="el" href="classwx_log_buffer.html" title="wxLogBuffer is a very simple implementation of log sink which simply collects all the logged messages...">wxLogBuffer</a>: This target collects all the logged messages in an internal buffer allowing to show them later to the user all at once. </li>
<li><a class="el" href="classwx_log_null.html" title="This class allows you to temporarily suspend logging.">wxLogNull</a>: The last log class is quite particular: it doesn't do anything. The objects of this class may be instantiated to (temporarily) suppress output of <em>wxLogXXX()</em> functions. As an example, trying to open a non-existing file will usually provoke an error message, but if for some reasons it is unwanted, just use this construction: <div class="fragment"><div class="line"><a class="code" href="classwx_file.html" title="A wxFile performs raw file I/O.">wxFile</a> file;</div>
<div class="line"></div>
<div class="line"><span class="comment">// wxFile.Open() normally complains if file can&#39;t be opened, we don&#39;t want it</span></div>
<div class="line">{</div>
<div class="line">    <a class="code" href="classwx_log_null.html" title="This class allows you to temporarily suspend logging.">wxLogNull</a> logNo;</div>
<div class="line">    <span class="keywordflow">if</span> ( !file.<a class="code" href="classwx_file.html#a70f2abe0e310dcf77ea6aeaac60df25b" title="Opens the file, returning true if successful.">Open</a>(<span class="stringliteral">&quot;bar&quot;</span>) )</div>
<div class="line">    {</div>
<div class="line">        <span class="comment">// ... process error ourselves ...</span></div>
<div class="line">    }</div>
<div class="line">} <span class="comment">// ~wxLogNull called, old log sink restored</span></div>
<div class="line"></div>
<div class="line"><a class="code" href="group__group__funcmacro__log.html#ga249358701f3c2d410088ddf7a61d8564" title="For all normal, informational messages.">wxLogMessage</a>(<span class="stringliteral">&quot;...&quot;</span>); <span class="comment">// ok</span></div>
</div><!-- fragment --></li>
</ul>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="group__group__class__logging.html">Logging Classes</a></dd></dl>
<p>The log targets can also be combined: for example you may wish to redirect the messages somewhere else (for example, to a log file) but also process them as normally. For this the <a class="el" href="classwx_log_chain.html" title="This simple class allows you to chain log sinks, that is to install a new sink but keep passing log m...">wxLogChain</a>, <a class="el" href="classwx_log_interposer.html" title="A special version of wxLogChain which uses itself as the new log target.">wxLogInterposer</a>, and <a class="el" href="classwx_log_interposer_temp.html" title="A special version of wxLogChain which uses itself as the new log target.">wxLogInterposerTemp</a> can be used.</p>
<h1><a class="anchor" id="overview_log_mt"></a>
Logging in Multi-Threaded Applications</h1>
<p>Starting with wxWidgets 2.9.1, logging functions can be safely called from any thread. Messages logged from threads other than the main one will be buffered until <a class="el" href="classwx_log.html#a21f8a2a7d83bd17a0e89bbe7dd7e6feb" title="Some of wxLog implementations, most notably the standard wxLogGui class, buffer the messages (for exa...">wxLog::Flush()</a> is called in the main thread (which usually happens during idle time, i.e. after processing all pending events) and will be really output only then. Notice that the default GUI logger already only output the messages when it is flushed, so by default messages from the other threads will be shown more or less at the same moment as usual. However if you define a custom log target, messages may be logged out of order, e.g. messages from the main thread with later timestamp may appear before messages with earlier timestamp logged from other threads. <a class="el" href="classwx_log.html" title="wxLog class defines the interface for the log targets used by wxWidgets logging functions as explaine...">wxLog</a> does however guarantee that messages logged by each thread will appear in order in which they were logged.</p>
<p>Also notice that <a class="el" href="classwx_log.html#a58bbfc0831eb47f0d88c9350d1f6e02d" title="Globally enable or disable logging.">wxLog::EnableLogging()</a> and <a class="el" href="classwx_log_null.html" title="This class allows you to temporarily suspend logging.">wxLogNull</a> class which uses it only affect the current thread, i.e. logging messages may still be generated by the other threads after a call to <code>EnableLogging(false)</code>.</p>
<h1><a class="anchor" id="overview_log_customize"></a>
Logging Customization</h1>
<p>To completely change the logging behaviour you may define a custom log target. For example, you could define a class inheriting from <a class="el" href="classwx_log.html" title="wxLog class defines the interface for the log targets used by wxWidgets logging functions as explaine...">wxLog</a> which shows all the log messages in some part of your main application window reserved for the message output without interrupting the user work flow with modal message boxes.</p>
<p>To use your custom log target you may either call <a class="el" href="classwx_log.html#ac7ea85f71c8d3ecd4247f412be410505" title="Sets the specified log target as the active one.">wxLog::SetActiveTarget()</a> with your custom log object or create a wxAppTraits-derived class and override <a class="el" href="classwx_app_traits.html#aae9e62a6b5364fb9a230888a637eb378" title="Creates a wxLog class for the application to use for logging errors.">wxAppTraits::CreateLogTarget()</a> virtual method in it and also override <a class="el" href="classwx_app_console.html#ab2811644bfee7a93d0564a09397c4408" title="Creates the wxAppTraits object when GetTraits() needs it for the first time.">wxApp::CreateTraits()</a> to return an instance of your custom traits object. Notice that in the latter case you should be prepared for logging messages early during the program startup and also during program shutdown so you shouldn't rely on existence of the main application window, for example. You can however safely assume that GUI is (already/still) available when your log target as used as wxWidgets automatically switches to using <a class="el" href="classwx_log_stderr.html" title="This class can be used to redirect the log messages to a C file stream (not to be confused with C++ s...">wxLogStderr</a> if it isn't.</p>
<p>There are several methods which may be overridden in the derived class to customize log messages handling: <a class="el" href="classwx_log.html#aede0ff7812690d487de845b7f3095dfd" title="Called to log a new record.">wxLog::DoLogRecord()</a>, <a class="el" href="classwx_log.html#a3fafbd3b87ff2d08dfdd1378d35013bb" title="Called to log the specified string at given level.">wxLog::DoLogTextAtLevel()</a> and <a class="el" href="classwx_log.html#a18c877e0038afe284757512b866b0aac" title="Called to log the specified string.">wxLog::DoLogText()</a>.</p>
<p>The last method is the simplest one: you should override it if you simply 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 <a class="el" href="classwx_log.html#a3fafbd3b87ff2d08dfdd1378d35013bb" title="Called to log the specified string at given level.">wxLog::DoLogTextAtLevel()</a>.</p>
<p>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 <a class="el" href="classwx_log_formatter.html" title="wxLogFormatter class is used to format the log messages.">wxLogFormatter</a> 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.</p>
<p>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 messages to the user's (or programmer's) cell phone &ndash; maybe depending on whether the timestamp tells us if it is day or night in the current time zone).</p>
<p>The <em>dialog</em> sample illustrates this approach by defining a custom log target customizing the dialog used by <a class="el" href="classwx_log_gui.html" title="This is the default log target for the GUI wxWidgets applications.">wxLogGui</a> for the single messages.</p>
<h1><a class="anchor" id="overview_log_tracemasks"></a>
Using Trace Masks</h1>
<p>Notice that the use of log trace masks is hardly necessary any longer in current wxWidgets version as the same effect can be achieved by using different log components for different log statements of any level. Please see <a class="el" href="overview_log.html#overview_log_enable">Log Messages Selection</a> for more information about the log components.</p>
<p>The functions below allow some limited customization of <a class="el" href="classwx_log.html" title="wxLog class defines the interface for the log targets used by wxWidgets logging functions as explaine...">wxLog</a> behaviour without writing a new log target class (which, aside from being a matter of several minutes, allows you to do anything you want). The verbose messages are the trace messages which are not disabled in the release mode and are generated by <a class="el" href="group__group__funcmacro__log.html#gaf57b7e28ab76bacf10b3be044e8bd634" title="For verbose output.">wxLogVerbose()</a>. They are not normally shown to the user because they present little interest, but may be activated, for example, in order to help the user find some program problem.</p>
<p>As for the (real) trace messages, their handling depends on the currently enabled trace masks: if <a class="el" href="classwx_log.html#a4c11ee23ce5264b6c5921a17610cda13" title="Add the mask to the list of allowed masks for wxLogTrace().">wxLog::AddTraceMask()</a> was called for the mask of the given message, it will be logged, otherwise nothing happens.</p>
<p>For example, </p>
<div class="fragment"><div class="line"><a class="code" href="group__group__funcmacro__log.html#ga947e317db477914c12b13c4534867ec9" title="Log a message at wxLOG_Trace log level (see wxLogLevelValues enum).">wxLogTrace</a>( wxTRACE_OleCalls, <span class="stringliteral">&quot;IFoo::Bar() called&quot;</span> );</div>
</div><!-- fragment --><p>will log the message if it was preceded by:</p>
<div class="fragment"><div class="line"><a class="code" href="classwx_log.html#a4c11ee23ce5264b6c5921a17610cda13" title="Add the mask to the list of allowed masks for wxLogTrace().">wxLog::AddTraceMask</a>( wxTRACE_OleCalls );</div>
</div><!-- fragment --><p>The standard trace masks are given in <a class="el" href="group__group__funcmacro__log.html#ga947e317db477914c12b13c4534867ec9" title="Log a message at wxLOG_Trace log level (see wxLogLevelValues enum).">wxLogTrace()</a> documentation. </p>
</div></div><!-- contents -->

<address class="footer">
	<small>
		Generated on Thu Nov 27 2014 13:46:42 for wxWidgets by <a href="http://www.doxygen.org/index.html" target="_new">Doxygen</a> 1.8.2
	</small>
</address>
<script src="wxwidgets.js" type="text/javascript"></script>
</div><!-- #page_container -->
</body>
</html>