]>
Commit | Line | Data |
---|---|---|
9ee2d31c VZ |
1 | \section{\class{wxLog}}\label{wxlog} |
2 | ||
3 | wxLog class defines the interface for the {\it log targets} used by wxWindows | |
4 | logging functions as explained in the \helpref{wxLog overview}{wxlogoverview}. | |
5 | The only situations when you need to directly use this class is when you want | |
6 | to derive your own log target because the existing ones don't satisfy your | |
7 | needs. Another case is if you wish to customize the behaviour of the standard | |
8 | logging classes (all of which respect the wxLog settings): for example, set | |
9 | which trace messages are logged and which are not or change (or even remove | |
10 | completely) the timestamp on the messages. | |
11 | ||
12 | Otherwise, it is completely hidden behind the {\it wxLogXXX()} functions and | |
13 | you may not even know about its existence. | |
14 | ||
15 | See \helpref{log overview}{wxlogoverview} for the descriptions of wxWindows | |
16 | logging facilities. | |
17 | ||
18 | \wxheading{Derived from} | |
19 | ||
20 | No 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 | ||
30 | The functions in this section work with and manipulate the active log target. | |
99f09bc1 | 31 | The {\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 |
33 | install/query the current active target and, finally, |
34 | \helpref{DontCreateOnDemand()}{wxlogdontcreateondemand} | |
35 | disables the automatic creation of a standard log target | |
9ee2d31c VZ |
36 | if none actually exists. It is only useful when the application is terminating |
37 | and shouldn't be used in other situations because it may easily lead to a loss | |
38 | of 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 | ||
49 | Some of wxLog implementations, most notably the standard | |
6fb26ea3 | 50 | wxLogGui class, buffer the messages (for example, to avoid |
9ee2d31c VZ |
51 | showing the user a zillion of modal message boxes one after another - which |
52 | would be really annoying). {\it Flush()} shows them all and clears the buffer | |
53 | contents. Although this function doesn't do anything if the buffer is already | |
54 | empty, {\it HasPendingMessages()} is also provided which allows to explicitly | |
55 | verify 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 | |
63 | The functions below allow some limited customization of wxLog behaviour | |
64 | without writing a new log target class (which, aside of being a matter of | |
65 | several minutes, allows you to do anything you want). | |
66 | ||
67 | The verbose messages are the trace messages which are not disabled in the | |
fe482327 SB |
68 | release mode and are generated by \helpref{wxLogVerbose}{wxlogverbose}. They |
69 | are not normally shown to the user because they present little interest, but | |
70 | may be activated, for example, in order to help the user find some program | |
71 | problem. | |
9ee2d31c | 72 | |
ac7f0167 VZ |
73 | As for the (real) trace messages, their handling depends on the settings of |
74 | the (application global) {\it trace mask}. There are two ways to specify it: | |
fe482327 | 75 | either 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 | ||
80 | The difference between bit-wise and string trace masks is that a message using | |
81 | integer trace mask will only be logged if all bits of the mask are set in the | |
82 | current mask while a message using string mask will be logged simply if the | |
83 | mask had been added before to the list of allowed ones. | |
84 | ||
85 | For example, | |
fa482912 | 86 | |
ac7f0167 VZ |
87 | \begin{verbatim} |
88 | // wxTraceOleCalls is one of standard bit masks | |
89 | wxLogTrace(wxTraceRefCount | wxTraceOleCalls, "Active object ref count: %d", nRef); | |
90 | \end{verbatim} | |
91 | will 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 | 96 | wxLogTrace(wxTRACE_OleCalls, "IFoo::Bar() called"); |
ac7f0167 | 97 | \end{verbatim} |
fa482912 | 98 | |
ac7f0167 | 99 | will log the message if it was preceded by |
fa482912 | 100 | |
9ee2d31c | 101 | \begin{verbatim} |
ac7f0167 | 102 | wxLog::AddTraceMask(wxTRACE_OleCalls); |
9ee2d31c | 103 | \end{verbatim} |
ac7f0167 VZ |
104 | |
105 | Using string masks is simpler and allows to easily add custom ones, so this is | |
106 | the preferred way of working with trace messages. The integer trace mask is | |
107 | kept for compatibility and for additional (but very rarely needed) flexibility | |
108 | only. | |
109 | ||
110 | The standard trace masks are given in \helpref{wxLogTrace}{wxlogtrace} | |
111 | documentation. | |
9ee2d31c VZ |
112 | |
113 | Finally, the {\it wxLog::DoLog()} function automatically prepends a time stamp | |
114 | to all the messages. The format of the time stamp may be changed: it can be | |
115 | any string with \% specificators fully described in the documentation of the | |
116 | standard {\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 | |
119 | format disables timestamping of the messages completely. | |
120 | ||
ac7f0167 VZ |
121 | {\bf NB:} Timestamping is disabled for Visual C++ users in debug builds by |
122 | default because otherwise it would be impossible to directly go to the line | |
123 | from which the log message was generated by simply clicking in the debugger | |
124 | window 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 | ||
149 | Add the {\it mask} to the list of allowed masks for | |
150 | \helpref{wxLogTrace}{wxlogtrace}. | |
151 | ||
152 | See also: \helpref{RemoveTraceMask}{wxlogremovetracemask} | |
153 | ||
36bd6902 VZ |
154 | \membersection{wxLog::ClearTraceMasks}\label{wxlogcleartracemasks} |
155 | ||
156 | \func{static void}{ClearTraceMasks}{\void} | |
157 | ||
158 | Removes all trace masks previously set with | |
159 | \helpref{AddTraceMask}{wxlogaddtracemask}. | |
160 | ||
161 | See 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 | ||
167 | Forwards the message at specified level to the {\it DoLog()} function of the | |
168 | active log target if there is any, does nothing otherwise. | |
169 | ||
170 | \membersection{wxLog::GetActiveTarget}\label{wxloggetactivetarget} | |
171 | ||
172 | \func{static wxLog *}{GetActiveTarget}{\void} | |
173 | ||
174 | Returns 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 | ||
180 | Sets the specified log target as the active one. Returns the pointer to the | |
181 | previous active log target (may be NULL). | |
182 | ||
b6b1d47f VZ |
183 | \membersection{wxLog::Suspend}\label{wxlogsuspend} |
184 | ||
185 | \func{static void}{Suspend}{\void} | |
186 | ||
187 | Suspends the logging until \helpref{Resume}{wxlogresume} is called. Note that | |
188 | the latter must be called the same number of times as the former to undo it, | |
189 | i.e. if you call Suspend() twice you must call Resume() twice as well. | |
190 | ||
191 | Note that suspending the logging means that the log sink won't be be flushed | |
192 | periodically, it doesn't have any effect if the current log target does the | |
193 | logging immediately without waiting for \helpref{Flush}{wxlogflush} to be | |
194 | called (the standard GUI log target only shows the log dialog when it is | |
195 | flushed, 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 | ||
206 | Resumes logging previously suspended by a call to | |
207 | \helpref{Suspend|wxlogsuspend}. All messages logged in the meanwhile will be | |
208 | flushed soon. | |
209 | ||
9ee2d31c VZ |
210 | \membersection{wxLog::DontCreateOnDemand}\label{wxlogdontcreateondemand} |
211 | ||
212 | \func{static void}{DontCreateOnDemand}{\void} | |
213 | ||
214 | Instructs wxLog to not create new log targets on the fly if there is none | |
36bd6902 VZ |
215 | currently. (Almost) for internal use only: it is supposed to be called by the |
216 | application shutdown code. | |
217 | ||
218 | Note 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 | ||
225 | Shows all the messages currently in buffer and clears it. If the buffer | |
226 | is already empty, nothing happens. | |
227 | ||
e1ea357c VZ |
228 | \membersection{wxLog::FlushActive}\label{wxlogflushactive} |
229 | ||
230 | \func{static void}{FlushActive}{\void} | |
231 | ||
232 | Flushes the current log target if any, does nothing if there is none. | |
233 | ||
234 | See also: | |
235 | ||
236 | \helpref{Flush}{wxlogflush} | |
237 | ||
42ff6409 | 238 | \membersection{wxLog::HasPendingMessages}\label{haspendingmessages} |
9ee2d31c VZ |
239 | |
240 | \constfunc{bool}{HasPendingMessages}{\void} | |
241 | ||
242 | Returns true if there are any messages in the buffer (not yet shown to the | |
243 | user). (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 | ||
249 | Activates or desactivates verbose mode in which the verbose messages are | |
250 | logged 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 | ||
256 | Returns 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 | |
262 | Sets the timestamp format prepended by the default log targets to all | |
263 | messages. The string may contain any normal characters as well as \% | |
264 | prefixed format specificators, see {\it strftime()} manual for details. | |
da4b7ffc | 265 | Passing 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 | |
271 | Returns 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 | ||
277 | Sets the trace mask, see \helpref{Customization}{wxlogcustomization} | |
278 | section for details. | |
279 | ||
42ff6409 | 280 | \membersection{wxLog::GetTraceMask}\label{wxloggettracemask} |
9ee2d31c | 281 | |
42ff6409 JS |
282 | Returns the current trace mask, see \helpref{Customization}{wxlogcustomization} section |
283 | for details. | |
62448488 | 284 | |
ac7f0167 VZ |
285 | \membersection{wxLog::IsAllowedTraceMask}\label{wxlogisallowedtracemask} |
286 | ||
287 | \func{static bool}{IsAllowedTraceMask}{\param{const wxChar *}{mask}} | |
288 | ||
289 | Returns TRUE if the {\it mask} is one of allowed masks for | |
290 | \helpref{wxLogTrace}{wxlogtrace}. | |
291 | ||
292 | See 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 | ||
299 | Remove the {\it mask} from the list of allowed masks for | |
300 | \helpref{wxLogTrace}{wxlogtrace}. | |
301 | ||
302 | See also: \helpref{AddTraceMask}{wxlogaddtracemask} | |
303 |