]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/log.tex
Project file corrections, doc corrections
[wxWidgets.git] / docs / latex / wx / log.tex
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %% Name: log.tex
3 %% Purpose: wxLog and related classes documentation
4 %% Author: Vadim Zeitlin
5 %% Modified by:
6 %% Created: some time ago
7 %% RCS-ID: $Id$
8 %% Copyright: (c) 1997-2001 Vadim Zeitlin
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
12 \section{\class{wxLog}}\label{wxlog}
13
14 wxLog class defines the interface for the {\it log targets} used by wxWindows
15 logging functions as explained in the \helpref{wxLog overview}{wxlogoverview}.
16 The only situations when you need to directly use this class is when you want
17 to derive your own log target because the existing ones don't satisfy your
18 needs. Another case is if you wish to customize the behaviour of the standard
19 logging classes (all of which respect the wxLog settings): for example, set
20 which trace messages are logged and which are not or change (or even remove
21 completely) the timestamp on the messages.
22
23 Otherwise, it is completely hidden behind the {\it wxLogXXX()} functions and
24 you may not even know about its existence.
25
26 See \helpref{log overview}{wxlogoverview} for the descriptions of wxWindows
27 logging facilities.
28
29 \wxheading{Derived from}
30
31 No base class
32
33 \wxheading{Include files}
34
35 <wx/log.h>
36
37 \latexignore{\rtfignore{\wxheading{Function groups}}}
38
39 \membersection{Static functions}
40
41 The functions in this section work with and manipulate the active log target.
42 The \helpref{OnLog()}{wxlogonlog} is called by the {\it wxLogXXX()} functions
43 and invokes the \helpref{DoLog()}{wxlogdolog} of the active log target if any.
44 Get/Set methods are used to install/query the current active target and,
45 finally, \helpref{DontCreateOnDemand()}{wxlogdontcreateondemand} disables the
46 automatic creation of a standard log target if none actually exists. It is
47 only useful when the application is terminating and shouldn't be used in other
48 situations because it may easily lead to a loss of messages.
49
50 \helpref{OnLog}{wxlogonlog}\\
51 \helpref{GetActiveTarget}{wxloggetactivetarget}\\
52 \helpref{SetActiveTarget}{wxlogsetactivetarget}\\
53 \helpref{DontCreateOnDemand}{wxlogdontcreateondemand}\\
54 \helpref{Suspend}{wxlogsuspend}\\
55 \helpref{Resume}{wxlogresume}
56
57 \membersection{Logging functions}
58
59 There are two functions which must be implemented by any derived class to
60 actually process the log messages: \helpref{DoLog}{wxlogdolog} and
61 \helpref{DoLogString}{wxlogdologstring}. The second function receives a string
62 which just has to be output in some way and the easiest way to write a new log
63 target is to override just this function in the derived class. If more control
64 over the output format is needed, then the first function must be overridden
65 which allows to construct custom messages depending on the log level or even
66 do completely different things depending on the message severity (for example,
67 throw away all messages except warnings and errors, show warnings on the
68 screen and forward the error messages to the user's (or programmer's) cell
69 phone - maybe depending on whether the timestamp tells us if it is day or
70 night in the current time zone).
71
72 There also functions to support message buffering. Why are they needed?
73 Some of wxLog implementations, most notably the standard wxLogGui class,
74 buffer the messages (for example, to avoid showing the user a zillion of modal
75 message boxes one after another - which would be really annoying).
76 \helpref{Flush()}{wxlogflush} shows them all and clears the buffer contents.
77 Although this function doesn't do anything if the buffer is already empty,
78 \helpref{HasPendingMessages()}{wxloghaspendingmessages} is also provided which
79 allows to explicitly verify it.
80
81 \helpref{Flush}{wxlogflush}\\
82 \helpref{FlushActive}{wxlogflushactive}\\
83 \helpref{HasPendingMessages}{wxloghaspendingmessages}
84
85 \membersection{Customization}\label{wxlogcustomization}
86
87 The functions below allow some limited customization of wxLog behaviour
88 without writing a new log target class (which, aside of being a matter of
89 several minutes, allows you to do anything you want).
90
91 The verbose messages are the trace messages which are not disabled in the
92 release mode and are generated by \helpref{wxLogVerbose}{wxlogverbose}. They
93 are not normally shown to the user because they present little interest, but
94 may be activated, for example, in order to help the user find some program
95 problem.
96
97 As for the (real) trace messages, their handling depends on the settings of
98 the (application global) {\it trace mask}. There are two ways to specify it:
99 either by using \helpref{SetTraceMask}{wxlogsettracemask} and
100 \helpref{GetTraceMask}{wxloggettracemask} and using
101 \helpref{wxLogTrace}{wxlogtrace} which takes an integer mask or by using
102 \helpref{AddTraceMask}{wxlogaddtracemask} for string trace masks.
103
104 The difference between bit-wise and string trace masks is that a message using
105 integer trace mask will only be logged if all bits of the mask are set in the
106 current mask while a message using string mask will be logged simply if the
107 mask had been added before to the list of allowed ones.
108
109 For example,
110
111 \begin{verbatim}
112 // wxTraceOleCalls is one of standard bit masks
113 wxLogTrace(wxTraceRefCount | wxTraceOleCalls, "Active object ref count: %d", nRef);
114 \end{verbatim}
115 will do something only if the current trace mask contains both
116 {\tt wxTraceRefCount} and {\tt wxTraceOle}, but
117
118 \begin{verbatim}
119 // wxTRACE_OleCalls is one of standard string masks
120 wxLogTrace(wxTRACE_OleCalls, "IFoo::Bar() called");
121 \end{verbatim}
122
123 will log the message if it was preceded by
124
125 \begin{verbatim}
126 wxLog::AddTraceMask(wxTRACE_OleCalls);
127 \end{verbatim}
128
129 Using string masks is simpler and allows to easily add custom ones, so this is
130 the preferred way of working with trace messages. The integer trace mask is
131 kept for compatibility and for additional (but very rarely needed) flexibility
132 only.
133
134 The standard trace masks are given in \helpref{wxLogTrace}{wxlogtrace}
135 documentation.
136
137 Finally, the {\it wxLog::DoLog()} function automatically prepends a time stamp
138 to all the messages. The format of the time stamp may be changed: it can be
139 any string with \% specificators fully described in the documentation of the
140 standard {\it strftime()} function. For example, the default format is
141 "[\%d/\%b/\%y \%H:\%M:\%S] " which gives something like "[17/Sep/98 22:10:16] "
142 (without quotes) for the current date. Setting an empty string as the time
143 format disables timestamping of the messages completely.
144
145 {\bf NB:} Timestamping is disabled for Visual C++ users in debug builds by
146 default because otherwise it would be impossible to directly go to the line
147 from which the log message was generated by simply clicking in the debugger
148 window on the corresponding error message. If you wish to enable it, please use
149 \helpref{SetTimestamp}{wxlogsettimestamp} explicitly.
150
151 \helpref{AddTraceMask}{wxlogaddtracemask}\\
152 \helpref{RemoveTraceMask}{wxlogremovetracemask}\\
153 \helpref{ClearTraceMasks}{wxlogcleartracemasks}\\
154 \helpref{IsAllowedTraceMask}{wxlogisallowedtracemask}\\
155 \helpref{SetVerbose}{wxlogsetverbose}\\
156 \helpref{GetVerbose}{wxloggetverbose}\\
157 \helpref{SetTimestamp}{wxlogsettimestamp}\\
158 \helpref{GetTimestamp}{wxloggettimestamp}\\
159 \helpref{SetTraceMask}{wxlogsettracemask}\\
160 \helpref{GetTraceMask}{wxloggettracemask}
161
162 %%%%% MEMBERS HERE %%%%%
163 \helponly{\insertatlevel{2}{
164
165 \wxheading{Members}
166
167 }}
168
169 \membersection{wxLog::AddTraceMask}\label{wxlogaddtracemask}
170
171 \func{static void}{AddTraceMask}{\param{const wxString\& }{mask}}
172
173 Add the {\it mask} to the list of allowed masks for
174 \helpref{wxLogTrace}{wxlogtrace}.
175
176 See also: \helpref{RemoveTraceMask}{wxlogremovetracemask}
177
178 \membersection{wxLog::ClearTraceMasks}\label{wxlogcleartracemasks}
179
180 \func{static void}{ClearTraceMasks}{\void}
181
182 Removes all trace masks previously set with
183 \helpref{AddTraceMask}{wxlogaddtracemask}.
184
185 See also: \helpref{RemoveTraceMask}{wxlogremovetracemask}
186
187 \membersection{wxLog::OnLog}\label{wxlogonlog}
188
189 \func{static void}{OnLog}{\param{wxLogLevel }{ level}, \param{const char * }{ message}}
190
191 Forwards the message at specified level to the {\it DoLog()} function of the
192 active log target if there is any, does nothing otherwise.
193
194 \membersection{wxLog::GetActiveTarget}\label{wxloggetactivetarget}
195
196 \func{static wxLog *}{GetActiveTarget}{\void}
197
198 Returns the pointer to the active log target (may be NULL).
199
200 \membersection{wxLog::SetActiveTarget}\label{wxlogsetactivetarget}
201
202 \func{static wxLog *}{SetActiveTarget}{\param{wxLog * }{ logtarget}}
203
204 Sets the specified log target as the active one. Returns the pointer to the
205 previous active log target (may be NULL).
206
207 \membersection{wxLog::Suspend}\label{wxlogsuspend}
208
209 \func{static void}{Suspend}{\void}
210
211 Suspends the logging until \helpref{Resume}{wxlogresume} is called. Note that
212 the latter must be called the same number of times as the former to undo it,
213 i.e. if you call Suspend() twice you must call Resume() twice as well.
214
215 Note that suspending the logging means that the log sink won't be be flushed
216 periodically, it doesn't have any effect if the current log target does the
217 logging immediately without waiting for \helpref{Flush}{wxlogflush} to be
218 called (the standard GUI log target only shows the log dialog when it is
219 flushed, so Suspend() works as expected with it).
220
221 \wxheading{See also:}
222
223 \helpref{Resume}{wxlogresume},\\
224 \helpref{wxLogNull}{wxlogoverview}
225
226 \membersection{wxLog::Resume}\label{wxlogresume}
227
228 \func{static void}{Resume}{\void}
229
230 Resumes logging previously suspended by a call to
231 \helpref{Suspend}{wxlogsuspend}. All messages logged in the meanwhile will be
232 flushed soon.
233
234 \membersection{wxLog::DoLog}\label{wxlogdolog}
235
236 \func{virtual void}{DoLog}{\param{wxLogLevel }{level}, \param{const wxChar }{*msg}, \param{time\_t }{timestamp}}
237
238 Called to process the message of the specified severity. {\it msg} is the text
239 of the message as specified in the call of {\it wxLogXXX()} function which
240 generated it and {\it timestamp} is the moment when the message was generated.
241
242 The base class version prepends the timestamp to the message, adds a prefix
243 corresponding to the log level and then calls
244 \helpref{DoLogString}{wxlogdologstring} with the resulting string.
245
246 \membersection{wxLog::DoLogString}\label{wxlogdologstring}
247
248 \func{virtual void}{DoLogString}{\param{const wxChar }{*msg}, \param{time\_t }{timestamp}}
249
250 Called to log the specified string. The timestamp is already included into the
251 string but still passed to this function.
252
253 A simple implementation may just send the string to {\tt stdout} or, better,
254 {\tt stderr}.
255
256 \membersection{wxLog::DontCreateOnDemand}\label{wxlogdontcreateondemand}
257
258 \func{static void}{DontCreateOnDemand}{\void}
259
260 Instructs wxLog to not create new log targets on the fly if there is none
261 currently. (Almost) for internal use only: it is supposed to be called by the
262 application shutdown code.
263
264 Note that this function also calls
265 \helpref{ClearTraceMasks}{wxlogcleartracemasks}.
266
267 \membersection{wxLog::Flush}\label{wxlogflush}
268
269 \func{virtual void}{Flush}{\void}
270
271 Shows all the messages currently in buffer and clears it. If the buffer
272 is already empty, nothing happens.
273
274 \membersection{wxLog::FlushActive}\label{wxlogflushactive}
275
276 \func{static void}{FlushActive}{\void}
277
278 Flushes the current log target if any, does nothing if there is none.
279
280 See also:
281
282 \helpref{Flush}{wxlogflush}
283
284 \membersection{wxLog::HasPendingMessages}\label{wxloghaspendingmessages}
285
286 \constfunc{bool}{HasPendingMessages}{\void}
287
288 Returns true if there are any messages in the buffer (not yet shown to the
289 user). (Almost) for internal use only.
290
291 \membersection{wxLog::SetVerbose}\label{wxlogsetverbose}
292
293 \func{static void}{SetVerbose}{\param{bool }{ verbose = TRUE}}
294
295 Activates or desactivates verbose mode in which the verbose messages are
296 logged as the normal ones instead of being silently dropped.
297
298 \membersection{wxLog::GetVerbose}\label{wxloggetverbose}
299
300 \func{static bool}{GetVerbose}{\void}
301
302 Returns whether the verbose mode is currently active.
303
304 \membersection{wxLog::SetTimestamp}\label{wxlogsettimestamp}
305
306 \func{void}{SetTimestamp}{\param{const char * }{ format}}
307
308 Sets the timestamp format prepended by the default log targets to all
309 messages. The string may contain any normal characters as well as \%
310 prefixed format specificators, see {\it strftime()} manual for details.
311 Passing a NULL value (not empty string) to this function disables message timestamping.
312
313 \membersection{wxLog::GetTimestamp}\label{wxloggettimestamp}
314
315 \constfunc{const char *}{GetTimestamp}{\void}
316
317 Returns the current timestamp format string.
318
319 \membersection{wxLog::SetTraceMask}\label{wxlogsettracemask}
320
321 \func{static void}{SetTraceMask}{\param{wxTraceMask }{ mask}}
322
323 Sets the trace mask, see \helpref{Customization}{wxlogcustomization}
324 section for details.
325
326 \membersection{wxLog::GetTraceMask}\label{wxloggettracemask}
327
328 Returns the current trace mask, see \helpref{Customization}{wxlogcustomization} section
329 for details.
330
331 \membersection{wxLog::IsAllowedTraceMask}\label{wxlogisallowedtracemask}
332
333 \func{static bool}{IsAllowedTraceMask}{\param{const wxChar *}{mask}}
334
335 Returns TRUE if the {\it mask} is one of allowed masks for
336 \helpref{wxLogTrace}{wxlogtrace}.
337
338 See also: \helpref{AddTraceMask}{wxlogaddtracemask},
339 \helpref{RemoveTraceMask}{wxlogremovetracemask}
340
341 \membersection{wxLog::RemoveTraceMask}\label{wxlogremovetracemask}
342
343 \func{static void}{RemoveTraceMask}{\param{const wxString\& }{mask}}
344
345 Remove the {\it mask} from the list of allowed masks for
346 \helpref{wxLogTrace}{wxlogtrace}.
347
348 See also: \helpref{AddTraceMask}{wxlogaddtracemask}
349
350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wxLogChain %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
351
352 \section{\class{wxLogChain}}\label{wxlogchain}
353
354 This simple class allows to chain log sinks, that is to install a new sink but
355 keep passing log messages to the old one instead of replacing it completely as
356 \helpref{SetActiveTarget}{wxlogsetactivetarget} does.
357
358 It is especially useful when you want to divert the logs somewhere (for
359 example to a file or a log window) but also keep showing the error messages
360 using the standard dialogs as \helpref{wxLogGui}{wxlogoverview} does by default.
361
362 Example of usage:
363
364 \begin{verbatim}
365 wxLogChain *logChain = new wxLogChain(new wxLogStderr);
366
367 // all the log messages are sent to stderr and also processed as usually
368 ...
369
370 delete logChain;
371
372 \end{verbatim}
373
374 \wxheading{Derived from}
375
376 \helpref{wxLog}{wxlog}
377
378 \wxheading{Include files}
379
380 <wx/log.h>
381
382 \latexignore{\rtfignore{\wxheading{Members}}}
383
384 \membersection{wxLogChain::wxLogChain}\label{wxlogchainwxlogchain}
385
386 \func{}{wxLogChain}{\param{wxLog *}{logger}}
387
388 Sets the specified {\tt logger} (which may be {\tt NULL}) as the default log
389 target but the log messages are also passed to the previous log target if any.
390
391 \membersection{wxLogChain::\destruct{wxLogChain}}
392
393 \func{}{\destruct{wxLogChain}}{\void}
394
395 Destroys the previous log target.
396
397 \membersection{wxLogChain::GetOldLog}\label{wxlogchaingetoldlog}
398
399 \constfunc{wxLog *}{GetOldLog}{\void}
400
401 Returns the pointer to the previously active log target (which may be {\tt
402 NULL}).
403
404 \membersection{wxLogChain::IsPassingMessages}\label{wxlogchainispassingmessages}
405
406 \constfunc{bool}{IsPassingMessages}{\void}
407
408 Returns {\tt TRUE} if the messages are passed to the previously active log
409 target (default) or {\tt FALSE} if \helpref{PassMessages}{wxlogchainpassmessages}
410 had been called.
411
412 \membersection{wxLogChain::PassMessages}\label{wxlogchainpassmessages}
413
414 \func{void}{PassMessages}{\param{bool }{passMessages}}
415
416 By default, the log messages are passed to the previously active log target.
417 Calling this function with {\tt FALSE} parameter disables this behaviour
418 (presumably temporarily, as you shouldn't use wxLogChain at all otherwise) and
419 it can be reenabled by calling it again with {\it passMessages} set to {\tt
420 TRUE}.
421
422 \membersection{wxLogChain::SetLog}\label{wxlogchainsetlog}
423
424 \func{void}{SetLog}{\param{wxLog *}{logger}}
425
426 Sets another log target to use (may be {\tt NULL}). The log target specified
427 in the \helpref{constructor}{wxlogchainwxlogchain} or in a previous call to
428 this function is deleted.
429
430 This doesn't change the old log target value (the one the messages are
431 forwarded to) which still remains the same as was active when wxLogChain
432 object was created.
433
434 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wxLogChain %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
435
436 \section{\class{wxLogPassThrough}}\label{wxlogpassthrough}
437
438 A special version of \helpref{wxLogChain}{wxlogchain} which uses itself as the
439 new log target. Maybe more clearly, it means that this is a log target which
440 forwards the log messages to the previously installed one in addition to
441 processing them itself.
442
443 Unlike \helpref{wxLogChain}{wxlogchain} which is usually used directly as is,
444 this class must be derived from to implement \helpref{DoLog}{wxlogdolog}
445 and/or \helpref{DoLogString}{wxlogdologstring} methods.
446
447 \wxheading{Derived from}
448
449 \helpref{wxLogChain}{wxlogchain}
450
451 \wxheading{Include files}
452
453 <wx/log.h>
454
455 \latexignore{\rtfignore{\wxheading{Members}}}
456
457 \membersection{wxLogPassThrough::wxLogPassThrough}\label{wxlogpassthroughctor}
458
459 Default ctor installs this object as the current active log target.
460