]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/log.tex
Fixed compilation if wxUSE_NEW_GRID and wxUSE_GRID are both set to 0
[wxWidgets.git] / docs / latex / wx / log.tex
CommitLineData
9ee2d31c
VZ
1\section{\class{wxLog}}\label{wxlog}
2
3wxLog class defines the interface for the {\it log targets} used by wxWindows
4logging functions as explained in the \helpref{wxLog overview}{wxlogoverview}.
5The only situations when you need to directly use this class is when you want
6to derive your own log target because the existing ones don't satisfy your
7needs. Another case is if you wish to customize the behaviour of the standard
8logging classes (all of which respect the wxLog settings): for example, set
9which trace messages are logged and which are not or change (or even remove
10completely) the timestamp on the messages.
11
12Otherwise, it is completely hidden behind the {\it wxLogXXX()} functions and
13you may not even know about its existence.
14
15See \helpref{log overview}{wxlogoverview} for the descriptions of wxWindows
16logging facilities.
17
18\wxheading{Derived from}
19
20No base class
21
954b8ae6
JS
22\wxheading{Include files}
23
24<wx/log.h>
25
9ee2d31c
VZ
26\latexignore{\rtfignore{\wxheading{Function groups}}}
27
28\membersection{Static functions}
29
30The functions in this section work with and manipulate the active log target.
99f09bc1 31The {\it OnLog()} is called by the {\it wxLogXXX()} functions and invokes the
9ee2d31c 32{\it DoLog()} of the active log target if any. Get/Set methods are used to
36bd6902
VZ
33install/query the current active target and, finally,
34\helpref{DontCreateOnDemand()}{wxlogdontcreateondemand}
35disables the automatic creation of a standard log target
9ee2d31c
VZ
36if none actually exists. It is only useful when the application is terminating
37and shouldn't be used in other situations because it may easily lead to a loss
38of messages.
39
40\helpref{OnLog}{wxlogonlog}\\
41\helpref{GetActiveTarget}{wxloggetactivetarget}\\
42ff6409 42\helpref{SetActiveTarget}{wxlogsetactivetarget}\\
b6b1d47f
VZ
43\helpref{DontCreateOnDemand}{wxlogdontcreateondemand}\\
44\helpref{Suspend}{wxlogsuspend}\\
45\helpref{Resume}{wxlogresume}
9ee2d31c
VZ
46
47\membersection{Message buffering}
48
49Some of wxLog implementations, most notably the standard
6fb26ea3 50wxLogGui class, buffer the messages (for example, to avoid
9ee2d31c
VZ
51showing the user a zillion of modal message boxes one after another - which
52would be really annoying). {\it Flush()} shows them all and clears the buffer
53contents. Although this function doesn't do anything if the buffer is already
54empty, {\it HasPendingMessages()} is also provided which allows to explicitly
55verify it.
56
57\helpref{Flush}{wxlogflush}\\
e1ea357c 58\helpref{FlushActive}{wxlogflushactive}\\
9ee2d31c
VZ
59\helpref{HasPendingMessages}{haspendingmessages}
60
42ff6409 61\membersection{Customization}\label{wxlogcustomization}
9ee2d31c
VZ
62
63The functions below allow some limited customization of wxLog behaviour
64without writing a new log target class (which, aside of being a matter of
65several minutes, allows you to do anything you want).
66
67The verbose messages are the trace messages which are not disabled in the
fe482327
SB
68release mode and are generated by \helpref{wxLogVerbose}{wxlogverbose}. They
69are not normally shown to the user because they present little interest, but
70may be activated, for example, in order to help the user find some program
71problem.
9ee2d31c 72
ac7f0167
VZ
73As for the (real) trace messages, their handling depends on the settings of
74the (application global) {\it trace mask}. There are two ways to specify it:
fe482327 75either by using \helpref{SetTraceMask}{wxlogsettracemask} and
ac7f0167
VZ
76\helpref{GetTraceMask}{wxloggettracemask} and using
77\helpref{wxLogTrace}{wxlogtrace} which takes an integer mask or by using
78\helpref{AddTraceMask}{wxlogaddtracemask} for string trace masks.
79
80The difference between bit-wise and string trace masks is that a message using
81integer trace mask will only be logged if all bits of the mask are set in the
82current mask while a message using string mask will be logged simply if the
83mask had been added before to the list of allowed ones.
84
85For example,
fa482912 86
ac7f0167
VZ
87\begin{verbatim}
88// wxTraceOleCalls is one of standard bit masks
89wxLogTrace(wxTraceRefCount | wxTraceOleCalls, "Active object ref count: %d", nRef);
90\end{verbatim}
91will do something only if the current trace mask contains both
92{\tt wxTraceRefCount} and {\tt wxTraceOle}, but
fa482912 93
ac7f0167
VZ
94\begin{verbatim}
95// wxTRACE_OleCalls is one of standard string masks
fe482327 96wxLogTrace(wxTRACE_OleCalls, "IFoo::Bar() called");
ac7f0167 97\end{verbatim}
fa482912 98
ac7f0167 99will log the message if it was preceded by
fa482912 100
9ee2d31c 101\begin{verbatim}
ac7f0167 102wxLog::AddTraceMask(wxTRACE_OleCalls);
9ee2d31c 103\end{verbatim}
ac7f0167
VZ
104
105Using string masks is simpler and allows to easily add custom ones, so this is
106the preferred way of working with trace messages. The integer trace mask is
107kept for compatibility and for additional (but very rarely needed) flexibility
108only.
109
110The standard trace masks are given in \helpref{wxLogTrace}{wxlogtrace}
111documentation.
9ee2d31c
VZ
112
113Finally, the {\it wxLog::DoLog()} function automatically prepends a time stamp
114to all the messages. The format of the time stamp may be changed: it can be
115any string with \% specificators fully described in the documentation of the
116standard {\it strftime()} function. For example, the default format is
117"[\%d/\%b/\%y \%H:\%M:\%S] " which gives something like "[17/Sep/98 22:10:16] "
118(without quotes) for the current date. Setting an empty string as the time
119format disables timestamping of the messages completely.
120
ac7f0167
VZ
121{\bf NB:} Timestamping is disabled for Visual C++ users in debug builds by
122default because otherwise it would be impossible to directly go to the line
123from which the log message was generated by simply clicking in the debugger
124window on the corresponding error message. If you wish to enable it, please use
125\helpref{SetTimestamp}{wxlogsettimestamp} explicitly.
126
127\helpref{AddTraceMask}{wxlogaddtracemask}\\
128\helpref{RemoveTraceMask}{wxlogremovetracemask}\\
36bd6902 129\helpref{ClearTraceMasks}{wxlogcleartracemasks}\\
ac7f0167 130\helpref{IsAllowedTraceMask}{wxlogisallowedtracemask}\\
9ee2d31c
VZ
131\helpref{SetVerbose}{wxlogsetverbose}\\
132\helpref{GetVerbose}{wxloggetverbose}\\
22d6efa8
JS
133\helpref{SetTimestamp}{wxlogsettimestamp}\\
134\helpref{GetTimestamp}{wxloggettimestamp}\\
9ee2d31c
VZ
135\helpref{SetTraceMask}{wxlogsettracemask}\\
136\helpref{GetTraceMask}{wxloggettracemask}
137
138%%%%% MEMBERS HERE %%%%%
139\helponly{\insertatlevel{2}{
140
141\wxheading{Members}
142
143}}
144
ac7f0167
VZ
145\membersection{wxLog::AddTraceMask}\label{wxlogaddtracemask}
146
147\func{static void}{AddTraceMask}{\param{const wxString\& }{mask}}
148
149Add the {\it mask} to the list of allowed masks for
150\helpref{wxLogTrace}{wxlogtrace}.
151
152See also: \helpref{RemoveTraceMask}{wxlogremovetracemask}
153
36bd6902
VZ
154\membersection{wxLog::ClearTraceMasks}\label{wxlogcleartracemasks}
155
156\func{static void}{ClearTraceMasks}{\void}
157
158Removes all trace masks previously set with
159\helpref{AddTraceMask}{wxlogaddtracemask}.
160
161See also: \helpref{RemoveTraceMask}{wxlogremovetracemask}
162
9ee2d31c
VZ
163\membersection{wxLog::OnLog}\label{wxlogonlog}
164
165\func{static void}{OnLog}{\param{wxLogLevel }{ level}, \param{const char * }{ message}}
166
167Forwards the message at specified level to the {\it DoLog()} function of the
168active log target if there is any, does nothing otherwise.
169
170\membersection{wxLog::GetActiveTarget}\label{wxloggetactivetarget}
171
172\func{static wxLog *}{GetActiveTarget}{\void}
173
174Returns the pointer to the active log target (may be NULL).
175
176\membersection{wxLog::SetActiveTarget}\label{wxlogsetactivetarget}
177
178\func{static wxLog *}{SetActiveTarget}{\param{wxLog * }{ logtarget}}
179
180Sets the specified log target as the active one. Returns the pointer to the
181previous active log target (may be NULL).
182
b6b1d47f
VZ
183\membersection{wxLog::Suspend}\label{wxlogsuspend}
184
185\func{static void}{Suspend}{\void}
186
187Suspends the logging until \helpref{Resume}{wxlogresume} is called. Note that
188the latter must be called the same number of times as the former to undo it,
189i.e. if you call Suspend() twice you must call Resume() twice as well.
190
191Note that suspending the logging means that the log sink won't be be flushed
192periodically, it doesn't have any effect if the current log target does the
193logging immediately without waiting for \helpref{Flush}{wxlogflush} to be
194called (the standard GUI log target only shows the log dialog when it is
195flushed, so Suspend() works as expected with it).
196
197\wxheading{See also:}
198
199\helpref{Resume}{wxlogresume},\\
200\helpref{wxLogNull}{wxlogoverview}
201
202\membersection{wxLog::Resume}\label{wxlogresume}
203
204\func{static void}{Resume}{\void}
205
206Resumes logging previously suspended by a call to
207\helpref{Suspend|wxlogsuspend}. All messages logged in the meanwhile will be
208flushed soon.
209
9ee2d31c
VZ
210\membersection{wxLog::DontCreateOnDemand}\label{wxlogdontcreateondemand}
211
212\func{static void}{DontCreateOnDemand}{\void}
213
214Instructs wxLog to not create new log targets on the fly if there is none
36bd6902
VZ
215currently. (Almost) for internal use only: it is supposed to be called by the
216application shutdown code.
217
218Note that this function also calls
219\helpref{ClearTraceMasks}{wxlogcleartracemasks}.
9ee2d31c 220
42ff6409 221\membersection{wxLog::Flush}\label{wxlogflush}
9ee2d31c
VZ
222
223\func{virtual void}{Flush}{\void}
224
225Shows all the messages currently in buffer and clears it. If the buffer
226is already empty, nothing happens.
227
e1ea357c
VZ
228\membersection{wxLog::FlushActive}\label{wxlogflushactive}
229
230\func{static void}{FlushActive}{\void}
231
232Flushes the current log target if any, does nothing if there is none.
233
234See also:
235
236\helpref{Flush}{wxlogflush}
237
42ff6409 238\membersection{wxLog::HasPendingMessages}\label{haspendingmessages}
9ee2d31c
VZ
239
240\constfunc{bool}{HasPendingMessages}{\void}
241
242Returns true if there are any messages in the buffer (not yet shown to the
243user). (Almost) for internal use only.
244
42ff6409 245\membersection{wxLog::SetVerbose}\label{wxlogsetverbose}
9ee2d31c
VZ
246
247\func{void}{SetVerbose}{\param{bool }{ verbose = TRUE}}
248
249Activates or desactivates verbose mode in which the verbose messages are
250logged as the normal ones instead of being silently dropped.
251
42ff6409 252\membersection{wxLog::GetVerbose}\label{wxloggetverbose}
9ee2d31c
VZ
253
254\constfunc{bool}{GetVerbose}{\void}
255
256Returns whether the verbose mode is currently active.
257
22d6efa8 258\membersection{wxLog::SetTimestamp}\label{wxlogsettimestamp}
9ee2d31c 259
22d6efa8 260\func{void}{SetTimestamp}{\param{const char * }{ format}}
9ee2d31c
VZ
261
262Sets the timestamp format prepended by the default log targets to all
263messages. The string may contain any normal characters as well as \%
264prefixed format specificators, see {\it strftime()} manual for details.
da4b7ffc 265Passing a NULL value (not empty string) to this function disables message timestamping.
9ee2d31c 266
22d6efa8 267\membersection{wxLog::GetTimestamp}\label{wxloggettimestamp}
9ee2d31c 268
22d6efa8 269\constfunc{const char *}{GetTimestamp}{\void}
9ee2d31c
VZ
270
271Returns the current timestamp format string.
272
42ff6409 273\membersection{wxLog::SetTraceMask}\label{wxlogsettracemask}
9ee2d31c
VZ
274
275\func{static void}{SetTraceMask}{\param{wxTraceMask }{ mask}}
276
277Sets the trace mask, see \helpref{Customization}{wxlogcustomization}
278section for details.
279
42ff6409 280\membersection{wxLog::GetTraceMask}\label{wxloggettracemask}
9ee2d31c 281
42ff6409
JS
282Returns the current trace mask, see \helpref{Customization}{wxlogcustomization} section
283for details.
62448488 284
ac7f0167
VZ
285\membersection{wxLog::IsAllowedTraceMask}\label{wxlogisallowedtracemask}
286
287\func{static bool}{IsAllowedTraceMask}{\param{const wxChar *}{mask}}
288
289Returns TRUE if the {\it mask} is one of allowed masks for
290\helpref{wxLogTrace}{wxlogtrace}.
291
292See also: \helpref{AddTraceMask}{wxlogaddtracemask},
293\helpref{RemoveTraceMask}{wxlogremovetracemask}
294
295\membersection{wxLog::RemoveTraceMask}\label{wxlogremovetracemask}
296
297\func{static void}{RemoveTraceMask}{\param{const wxString\& }{mask}}
298
299Remove the {\it mask} from the list of allowed masks for
300\helpref{wxLogTrace}{wxlogtrace}.
301
302See also: \helpref{AddTraceMask}{wxlogaddtracemask}
303