]>
Commit | Line | Data |
---|---|---|
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 | ||
22 | \wxheading{Include files} | |
23 | ||
24 | <wx/log.h> | |
25 | ||
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. | |
31 | The {\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 | |
33 | install/query the current active target and, finally, | |
34 | \helpref{DontCreateOnDemand()}{wxlogdontcreateondemand} | |
35 | disables the automatic creation of a standard log target | |
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}\\ | |
42 | \helpref{SetActiveTarget}{wxlogsetactivetarget}\\ | |
43 | \helpref{DontCreateOnDemand}{wxlogdontcreateondemand}\\ | |
44 | \helpref{Suspend}{wxlogsuspend}\\ | |
45 | \helpref{Resume}{wxlogresume} | |
46 | ||
47 | \membersection{Message buffering} | |
48 | ||
49 | Some of wxLog implementations, most notably the standard | |
50 | wxLogGui class, buffer the messages (for example, to avoid | |
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}\\ | |
58 | \helpref{FlushActive}{wxlogflushactive}\\ | |
59 | \helpref{HasPendingMessages}{haspendingmessages} | |
60 | ||
61 | \membersection{Customization}\label{wxlogcustomization} | |
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 | |
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. | |
72 | ||
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: | |
75 | either 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 | ||
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, | |
86 | ||
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 | |
93 | ||
94 | \begin{verbatim} | |
95 | // wxTRACE_OleCalls is one of standard string masks | |
96 | wxLogTrace(wxTRACE_OleCalls, "IFoo::Bar() called"); | |
97 | \end{verbatim} | |
98 | ||
99 | will log the message if it was preceded by | |
100 | ||
101 | \begin{verbatim} | |
102 | wxLog::AddTraceMask(wxTRACE_OleCalls); | |
103 | \end{verbatim} | |
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. | |
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 | ||
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}\\ | |
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 | ||
149 | Add the {\it mask} to the list of allowed masks for | |
150 | \helpref{wxLogTrace}{wxlogtrace}. | |
151 | ||
152 | See also: \helpref{RemoveTraceMask}{wxlogremovetracemask} | |
153 | ||
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 | ||
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 | ||
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 | ||
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 | |
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}. | |
220 | ||
221 | \membersection{wxLog::Flush}\label{wxlogflush} | |
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 | ||
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 | ||
238 | \membersection{wxLog::HasPendingMessages}\label{haspendingmessages} | |
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 | ||
245 | \membersection{wxLog::SetVerbose}\label{wxlogsetverbose} | |
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 | ||
252 | \membersection{wxLog::GetVerbose}\label{wxloggetverbose} | |
253 | ||
254 | \constfunc{bool}{GetVerbose}{\void} | |
255 | ||
256 | Returns whether the verbose mode is currently active. | |
257 | ||
258 | \membersection{wxLog::SetTimestamp}\label{wxlogsettimestamp} | |
259 | ||
260 | \func{void}{SetTimestamp}{\param{const char * }{ format}} | |
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. | |
265 | Passing 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 | ||
271 | Returns the current timestamp format string. | |
272 | ||
273 | \membersection{wxLog::SetTraceMask}\label{wxlogsettracemask} | |
274 | ||
275 | \func{static void}{SetTraceMask}{\param{wxTraceMask }{ mask}} | |
276 | ||
277 | Sets the trace mask, see \helpref{Customization}{wxlogcustomization} | |
278 | section for details. | |
279 | ||
280 | \membersection{wxLog::GetTraceMask}\label{wxloggettracemask} | |
281 | ||
282 | Returns the current trace mask, see \helpref{Customization}{wxlogcustomization} section | |
283 | for details. | |
284 | ||
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 |