]> git.saurik.com Git - wxWidgets.git/blame_incremental - 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
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
22\wxheading{Include files}
23
24<wx/log.h>
25
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.
31The {\it OnLog()} is called by the {\it wxLogXXX()} functions and invokes the
32{\it DoLog()} of the active log target if any. Get/Set methods are used to
33install/query the current active target and, finally,
34\helpref{DontCreateOnDemand()}{wxlogdontcreateondemand}
35disables the automatic creation of a standard log target
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}\\
42\helpref{SetActiveTarget}{wxlogsetactivetarget}\\
43\helpref{DontCreateOnDemand}{wxlogdontcreateondemand}\\
44\helpref{Suspend}{wxlogsuspend}\\
45\helpref{Resume}{wxlogresume}
46
47\membersection{Message buffering}
48
49Some of wxLog implementations, most notably the standard
50wxLogGui class, buffer the messages (for example, to avoid
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}\\
58\helpref{FlushActive}{wxlogflushactive}\\
59\helpref{HasPendingMessages}{haspendingmessages}
60
61\membersection{Customization}\label{wxlogcustomization}
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
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.
72
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:
75either by using \helpref{SetTraceMask}{wxlogsettracemask} and
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,
86
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
93
94\begin{verbatim}
95// wxTRACE_OleCalls is one of standard string masks
96wxLogTrace(wxTRACE_OleCalls, "IFoo::Bar() called");
97\end{verbatim}
98
99will log the message if it was preceded by
100
101\begin{verbatim}
102wxLog::AddTraceMask(wxTRACE_OleCalls);
103\end{verbatim}
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.
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
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}\\
129\helpref{ClearTraceMasks}{wxlogcleartracemasks}\\
130\helpref{IsAllowedTraceMask}{wxlogisallowedtracemask}\\
131\helpref{SetVerbose}{wxlogsetverbose}\\
132\helpref{GetVerbose}{wxloggetverbose}\\
133\helpref{SetTimestamp}{wxlogsettimestamp}\\
134\helpref{GetTimestamp}{wxloggettimestamp}\\
135\helpref{SetTraceMask}{wxlogsettracemask}\\
136\helpref{GetTraceMask}{wxloggettracemask}
137
138%%%%% MEMBERS HERE %%%%%
139\helponly{\insertatlevel{2}{
140
141\wxheading{Members}
142
143}}
144
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
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
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
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
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
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}.
220
221\membersection{wxLog::Flush}\label{wxlogflush}
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
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
238\membersection{wxLog::HasPendingMessages}\label{haspendingmessages}
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
245\membersection{wxLog::SetVerbose}\label{wxlogsetverbose}
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
252\membersection{wxLog::GetVerbose}\label{wxloggetverbose}
253
254\constfunc{bool}{GetVerbose}{\void}
255
256Returns whether the verbose mode is currently active.
257
258\membersection{wxLog::SetTimestamp}\label{wxlogsettimestamp}
259
260\func{void}{SetTimestamp}{\param{const char * }{ format}}
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.
265Passing a NULL value (not empty string) to this function disables message timestamping.
266
267\membersection{wxLog::GetTimestamp}\label{wxloggettimestamp}
268
269\constfunc{const char *}{GetTimestamp}{\void}
270
271Returns the current timestamp format string.
272
273\membersection{wxLog::SetTraceMask}\label{wxlogsettracemask}
274
275\func{static void}{SetTraceMask}{\param{wxTraceMask }{ mask}}
276
277Sets the trace mask, see \helpref{Customization}{wxlogcustomization}
278section for details.
279
280\membersection{wxLog::GetTraceMask}\label{wxloggettracemask}
281
282Returns the current trace mask, see \helpref{Customization}{wxlogcustomization} section
283for details.
284
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