]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: log.h | |
e54c96f1 | 3 | // Purpose: interface of wxLogWindow |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxLogWindow | |
11 | @wxheader{log.h} | |
7c913512 | 12 | |
23324ae1 FM |
13 | This class represents a background log window: to be precise, it collects all |
14 | log messages in the log frame which it manages but also passes them on to the | |
3e6f95dc | 15 | log target which was active at the moment of its creation. This allows you, for |
23324ae1 FM |
16 | example, to show all the log messages in a frame but still continue to process |
17 | them normally by showing the standard log dialog. | |
7c913512 | 18 | |
23324ae1 FM |
19 | @library{wxbase} |
20 | @category{logging} | |
7c913512 | 21 | |
e54c96f1 | 22 | @see wxLogTextCtrl |
23324ae1 FM |
23 | */ |
24 | class wxLogWindow : public wxLogInterposer | |
25 | { | |
26 | public: | |
27 | /** | |
28 | Creates the log frame window and starts collecting the messages in it. | |
3c4f71cc | 29 | |
7c913512 | 30 | @param parent |
4cc4bfaf | 31 | The parent window for the log frame, may be @NULL |
7c913512 | 32 | @param title |
4cc4bfaf | 33 | The title for the log frame |
7c913512 | 34 | @param show |
4cc4bfaf FM |
35 | @true to show the frame initially (default), otherwise |
36 | Show() must be called later. | |
7c913512 | 37 | @param passToOld |
4cc4bfaf FM |
38 | @true to process the log messages normally in addition to |
39 | logging them in the log frame (default), @false to only log them in the | |
40 | log frame. | |
23324ae1 | 41 | */ |
4cc4bfaf FM |
42 | wxLogWindow(wxFrame parent, const wxChar title, bool show = true, |
43 | bool passToOld = true); | |
23324ae1 FM |
44 | |
45 | /** | |
46 | Returns the associated log frame window. This may be used to position or resize | |
47 | it but use Show() to show or hide it. | |
48 | */ | |
328f5751 | 49 | wxFrame* GetFrame() const; |
23324ae1 FM |
50 | |
51 | /** | |
52 | Called if the user closes the window interactively, will not be | |
53 | called if it is destroyed for another reason (such as when program | |
54 | exits). | |
23324ae1 FM |
55 | Return @true from here to allow the frame to close, @false to |
56 | prevent this from happening. | |
3c4f71cc | 57 | |
4cc4bfaf | 58 | @see OnFrameDelete() |
23324ae1 FM |
59 | */ |
60 | virtual bool OnFrameClose(wxFrame frame); | |
61 | ||
62 | /** | |
63 | Called immediately after the log frame creation allowing for | |
64 | any extra initializations. | |
65 | */ | |
66 | virtual void OnFrameCreate(wxFrame frame); | |
67 | ||
68 | /** | |
69 | Called right before the log frame is going to be deleted: will | |
70 | always be called unlike OnFrameClose(). | |
71 | */ | |
72 | virtual void OnFrameDelete(wxFrame frame); | |
73 | ||
74 | /** | |
75 | Shows or hides the frame. | |
76 | */ | |
4cc4bfaf | 77 | void Show(bool show = true); |
23324ae1 FM |
78 | }; |
79 | ||
80 | ||
e54c96f1 | 81 | |
23324ae1 FM |
82 | /** |
83 | @class wxLogInterposerTemp | |
84 | @wxheader{log.h} | |
7c913512 | 85 | |
23324ae1 FM |
86 | A special version of wxLogChain which uses itself as the |
87 | new log target. It forwards log messages to the previously installed one in | |
88 | addition to | |
89 | processing them itself. Unlike wxLogInterposer, it doesn't | |
90 | delete the old target which means it can be used to temporarily redirect log | |
91 | output. | |
7c913512 | 92 | |
23324ae1 FM |
93 | As per wxLogInterposer, this class must be derived from to implement |
94 | wxLog::DoLog | |
95 | and/or wxLog::DoLogString methods. | |
7c913512 | 96 | |
23324ae1 FM |
97 | @library{wxbase} |
98 | @category{logging} | |
99 | */ | |
100 | class wxLogInterposerTemp : public wxLogChain | |
101 | { | |
102 | public: | |
103 | /** | |
104 | The default constructor installs this object as the current active log target. | |
105 | */ | |
106 | }; | |
107 | ||
108 | ||
e54c96f1 | 109 | |
23324ae1 FM |
110 | /** |
111 | @class wxLogChain | |
112 | @wxheader{log.h} | |
7c913512 | 113 | |
3e6f95dc | 114 | This simple class allows you to chain log sinks, that is to install a new sink but |
23324ae1 FM |
115 | keep passing log messages to the old one instead of replacing it completely as |
116 | wxLog::SetActiveTarget does. | |
7c913512 | 117 | |
23324ae1 FM |
118 | It is especially useful when you want to divert the logs somewhere (for |
119 | example to a file or a log window) but also keep showing the error messages | |
120 | using the standard dialogs as wxLogGui does by default. | |
7c913512 | 121 | |
23324ae1 | 122 | Example of usage: |
7c913512 | 123 | |
23324ae1 FM |
124 | @code |
125 | wxLogChain *logChain = new wxLogChain(new wxLogStderr); | |
7c913512 | 126 | |
23324ae1 FM |
127 | // all the log messages are sent to stderr and also processed as usually |
128 | ... | |
7c913512 | 129 | |
23324ae1 FM |
130 | // don't delete logChain directly as this would leave a dangling |
131 | // pointer as active log target, use SetActiveTarget() instead | |
132 | delete wxLog::SetActiveTarget(...something else or @NULL...); | |
133 | @endcode | |
7c913512 | 134 | |
23324ae1 FM |
135 | @library{wxbase} |
136 | @category{logging} | |
137 | */ | |
138 | class wxLogChain : public wxLog | |
139 | { | |
140 | public: | |
141 | /** | |
142 | Sets the specified @c logger (which may be @NULL) as the default log | |
143 | target but the log messages are also passed to the previous log target if any. | |
144 | */ | |
4cc4bfaf | 145 | wxLogChain(wxLog* logger); |
23324ae1 FM |
146 | |
147 | /** | |
148 | Destroys the previous log target. | |
149 | */ | |
150 | ~wxLogChain(); | |
151 | ||
152 | /** | |
153 | Detaches the old log target so it won't be destroyed when the wxLogChain object | |
154 | is destroyed. | |
155 | */ | |
156 | void DetachOldLog(); | |
157 | ||
158 | /** | |
159 | Returns the pointer to the previously active log target (which may be @NULL). | |
160 | */ | |
328f5751 | 161 | wxLog* GetOldLog() const; |
23324ae1 FM |
162 | |
163 | /** | |
164 | Returns @true if the messages are passed to the previously active log | |
165 | target (default) or @false if PassMessages() | |
166 | had been called. | |
167 | */ | |
328f5751 | 168 | bool IsPassingMessages() const; |
23324ae1 FM |
169 | |
170 | /** | |
171 | By default, the log messages are passed to the previously active log target. | |
172 | Calling this function with @false parameter disables this behaviour | |
173 | (presumably temporarily, as you shouldn't use wxLogChain at all otherwise) and | |
4cc4bfaf | 174 | it can be reenabled by calling it again with @a passMessages set to @true. |
23324ae1 FM |
175 | */ |
176 | void PassMessages(bool passMessages); | |
177 | ||
178 | /** | |
179 | Sets another log target to use (may be @NULL). The log target specified | |
3e6f95dc | 180 | in the wxLogChain(wxLog*) constructor or in a previous call to |
23324ae1 | 181 | this function is deleted. |
23324ae1 FM |
182 | This doesn't change the old log target value (the one the messages are |
183 | forwarded to) which still remains the same as was active when wxLogChain | |
184 | object was created. | |
185 | */ | |
4cc4bfaf | 186 | void SetLog(wxLog* logger); |
23324ae1 FM |
187 | }; |
188 | ||
189 | ||
e54c96f1 | 190 | |
23324ae1 FM |
191 | /** |
192 | @class wxLogGui | |
193 | @wxheader{log.h} | |
7c913512 | 194 | |
23324ae1 FM |
195 | This is the default log target for the GUI wxWidgets applications. It is passed |
196 | to wxLog::SetActiveTarget at the program | |
197 | startup and is deleted by wxWidgets during the program shut down. | |
7c913512 | 198 | |
23324ae1 FM |
199 | @library{wxbase} |
200 | @category{logging} | |
201 | */ | |
202 | class wxLogGui : public wxLog | |
203 | { | |
204 | public: | |
205 | /** | |
206 | Default constructor. | |
207 | */ | |
208 | wxLogGui(); | |
209 | }; | |
210 | ||
211 | ||
e54c96f1 | 212 | |
23324ae1 FM |
213 | /** |
214 | @class wxLogStream | |
215 | @wxheader{log.h} | |
7c913512 | 216 | |
23324ae1 | 217 | This class can be used to redirect the log messages to a C++ stream. |
7c913512 | 218 | |
23324ae1 FM |
219 | Please note that this class is only available if wxWidgets was compiled with |
220 | the standard iostream library support (@c wxUSE_STD_IOSTREAM must be on). | |
7c913512 | 221 | |
23324ae1 FM |
222 | @library{wxbase} |
223 | @category{logging} | |
7c913512 | 224 | |
e54c96f1 | 225 | @see wxLogStderr, wxStreamToTextRedirector |
23324ae1 FM |
226 | */ |
227 | class wxLogStream : public wxLog | |
228 | { | |
229 | public: | |
230 | /** | |
231 | Constructs a log target which sends all the log messages to the given | |
232 | output stream. If it is @NULL, the messages are sent to @c cerr. | |
233 | */ | |
4cc4bfaf | 234 | wxLogStream(std::ostream ostr = NULL); |
23324ae1 FM |
235 | }; |
236 | ||
237 | ||
e54c96f1 | 238 | |
23324ae1 FM |
239 | /** |
240 | @class wxLogStderr | |
241 | @wxheader{log.h} | |
7c913512 | 242 | |
23324ae1 FM |
243 | This class can be used to redirect the log messages to a C file stream (not to |
244 | be confused with C++ streams). It is the default log target for the non-GUI | |
245 | wxWidgets applications which send all the output to @c stderr. | |
7c913512 | 246 | |
23324ae1 FM |
247 | @library{wxbase} |
248 | @category{logging} | |
7c913512 | 249 | |
e54c96f1 | 250 | @see wxLogStream |
23324ae1 FM |
251 | */ |
252 | class wxLogStderr : public wxLog | |
253 | { | |
254 | public: | |
255 | /** | |
256 | Constructs a log target which sends all the log messages to the given | |
257 | @c FILE. If it is @NULL, the messages are sent to @c stderr. | |
258 | */ | |
4cc4bfaf | 259 | wxLogStderr(FILE fp = NULL); |
23324ae1 FM |
260 | }; |
261 | ||
262 | ||
e54c96f1 | 263 | |
23324ae1 FM |
264 | /** |
265 | @class wxLogBuffer | |
266 | @wxheader{log.h} | |
7c913512 | 267 | |
23324ae1 FM |
268 | wxLogBuffer is a very simple implementation of log sink which simply collects |
269 | all the logged messages in a string (except the debug messages which are output | |
270 | in the usual way immediately as we're presumably not interested in collecting | |
271 | them for later). The messages from different log function calls are separated | |
272 | by the new lines. | |
7c913512 | 273 | |
23324ae1 | 274 | All the messages collected so far can be shown to the user (and the current |
7c913512 | 275 | buffer cleared) by calling the overloaded wxLogBuffer::Flush |
23324ae1 | 276 | method. |
7c913512 | 277 | |
23324ae1 | 278 | @library{wxbase} |
3e6f95dc | 279 | @category{logging} |
23324ae1 FM |
280 | */ |
281 | class wxLogBuffer : public wxLog | |
282 | { | |
283 | public: | |
284 | /** | |
285 | Shows all the messages collected so far to the user (using a message box in the | |
286 | GUI applications or by printing them out to the console in text mode) and | |
287 | clears the internal buffer. | |
288 | */ | |
289 | virtual void Flush(); | |
290 | ||
291 | /** | |
292 | Returns the current buffer contains. Messages from different log function calls | |
293 | are separated with the new lines in the buffer. | |
23324ae1 FM |
294 | The buffer can be cleared by Flush() which will |
295 | also show the current contents to the user. | |
296 | */ | |
297 | const wxString GetBuffer(); | |
298 | }; | |
299 | ||
300 | ||
e54c96f1 | 301 | |
23324ae1 FM |
302 | /** |
303 | @class wxLogInterposer | |
304 | @wxheader{log.h} | |
7c913512 | 305 | |
23324ae1 FM |
306 | A special version of wxLogChain which uses itself as the |
307 | new log target. It forwards log messages to the previously installed one in | |
308 | addition to | |
309 | processing them itself. | |
7c913512 | 310 | |
23324ae1 FM |
311 | Unlike wxLogChain which is usually used directly as is, |
312 | this class must be derived from to implement wxLog::DoLog | |
313 | and/or wxLog::DoLogString methods. | |
7c913512 | 314 | |
23324ae1 FM |
315 | wxLogInterposer destroys the previous log target in its destructor. If you |
316 | don't want this to happen, use wxLogInterposerTemp instead. | |
7c913512 | 317 | |
23324ae1 FM |
318 | @library{wxbase} |
319 | @category{logging} | |
320 | */ | |
321 | class wxLogInterposer : public wxLogChain | |
322 | { | |
323 | public: | |
324 | /** | |
325 | The default constructor installs this object as the current active log target. | |
326 | */ | |
327 | }; | |
328 | ||
329 | ||
e54c96f1 | 330 | |
23324ae1 FM |
331 | /** |
332 | @class wxLogTextCtrl | |
333 | @wxheader{log.h} | |
7c913512 | 334 | |
23324ae1 FM |
335 | Using these target all the log messages can be redirected to a text control. |
336 | The text control must have been created with @c wxTE_MULTILINE style by the | |
337 | caller previously. | |
7c913512 | 338 | |
23324ae1 FM |
339 | @library{wxbase} |
340 | @category{logging} | |
7c913512 | 341 | |
e54c96f1 | 342 | @see wxTextCtrl, wxStreamToTextRedirector |
23324ae1 FM |
343 | */ |
344 | class wxLogTextCtrl : public wxLog | |
345 | { | |
346 | public: | |
347 | /** | |
348 | Constructs a log target which sends all the log messages to the given text | |
4cc4bfaf | 349 | control. The @a textctrl parameter cannot be @NULL. |
23324ae1 FM |
350 | */ |
351 | wxLogTextCtrl(wxTextCtrl textctrl); | |
352 | }; | |
353 | ||
354 | ||
e54c96f1 | 355 | |
23324ae1 FM |
356 | /** |
357 | @class wxLog | |
358 | @wxheader{log.h} | |
7c913512 | 359 | |
23324ae1 | 360 | wxLog class defines the interface for the @e log targets used by wxWidgets |
3e6f95dc | 361 | logging functions as explained in the @ref overview_log. |
23324ae1 FM |
362 | The only situations when you need to directly use this class is when you want |
363 | to derive your own log target because the existing ones don't satisfy your | |
364 | needs. Another case is if you wish to customize the behaviour of the standard | |
365 | logging classes (all of which respect the wxLog settings): for example, set | |
366 | which trace messages are logged and which are not or change (or even remove | |
367 | completely) the timestamp on the messages. | |
7c913512 | 368 | |
23324ae1 FM |
369 | Otherwise, it is completely hidden behind the @e wxLogXXX() functions and |
370 | you may not even know about its existence. | |
7c913512 | 371 | |
8becd062 | 372 | @section overview_wxLog_deriving Deriving your own log target |
5bc128d6 RR |
373 | |
374 | There are two functions which must be implemented by any derived class to | |
375 | actually process the log messages: DoLog() and | |
376 | DoLogString(). The second function receives a string | |
377 | which just has to be output in some way and the easiest way to write a new log | |
378 | target is to override just this function in the derived class. If more control | |
379 | over the output format is needed, then the first function must be overridden | |
380 | which allows to construct custom messages depending on the log level or even | |
381 | do completely different things depending on the message severity (for example, | |
382 | throw away all messages except warnings and errors, show warnings on the | |
383 | screen and forward the error messages to the user's (or programmer's) cell | |
384 | phone - maybe depending on whether the timestamp tells us if it is day or | |
385 | night in the current time zone). | |
386 | There also functions to support message buffering. Why are they needed? | |
387 | Some of wxLog implementations, most notably the standard wxLogGui class, | |
388 | buffer the messages (for example, to avoid showing the user a zillion of modal | |
389 | message boxes one after another -- which would be really annoying). | |
390 | Flush() shows them all and clears the buffer contents. | |
391 | This function doesn't do anything if the buffer is already empty. | |
392 | See also: | |
393 | @li Flush() | |
394 | @li FlushActive() | |
395 | ||
396 | @section overview_wxLog_Trace_Masks Using trace masks | |
23324ae1 | 397 | |
23324ae1 | 398 | The functions below allow some limited customization of wxLog behaviour |
3e6f95dc | 399 | without writing a new log target class (which, aside from being a matter of |
23324ae1 | 400 | several minutes, allows you to do anything you want). |
23324ae1 | 401 | The verbose messages are the trace messages which are not disabled in the |
e54c96f1 | 402 | release mode and are generated by wxLogVerbose(). They |
23324ae1 FM |
403 | are not normally shown to the user because they present little interest, but |
404 | may be activated, for example, in order to help the user find some program | |
405 | problem. | |
23324ae1 | 406 | As for the (real) trace messages, their handling depends on the settings of |
5bc128d6 RR |
407 | the (application global) @e trace mask which can either be specified using |
408 | SetTraceMask(), GetTraceMask() and wxLogTrace() which takes an integer mask | |
409 | or using AddTraceMask() for string trace masks. | |
23324ae1 FM |
410 | The difference between bit-wise and string trace masks is that a message using |
411 | integer trace mask will only be logged if all bits of the mask are set in the | |
412 | current mask while a message using string mask will be logged simply if the | |
413 | mask had been added before to the list of allowed ones. | |
23324ae1 | 414 | For example, |
5bc128d6 | 415 | |
8becd062 | 416 | @code |
5bc128d6 RR |
417 | wxLogTrace( wxTraceRefCount|wxTraceOleCalls, "Active object ref count: %d", nRef ); |
418 | @endcode | |
3c4f71cc | 419 | |
23324ae1 FM |
420 | will do something only if the current trace mask contains both |
421 | @c wxTraceRefCount and @c wxTraceOle, but | |
3c4f71cc | 422 | |
8becd062 | 423 | @code |
5bc128d6 RR |
424 | wxLogTrace( wxTRACE_OleCalls, "IFoo::Bar() called" ); |
425 | @endcode | |
426 | ||
23324ae1 | 427 | will log the message if it was preceded by |
5bc128d6 | 428 | |
8becd062 | 429 | @code |
5bc128d6 RR |
430 | wxLog::AddTraceMask( wxTRACE_OleCalls); |
431 | @endcode | |
3c4f71cc | 432 | |
3e6f95dc | 433 | Using string masks is simpler and allows you to easily add custom ones, so this is |
23324ae1 FM |
434 | the preferred way of working with trace messages. The integer trace mask is |
435 | kept for compatibility and for additional (but very rarely needed) flexibility | |
436 | only. | |
5bc128d6 | 437 | The standard trace masks are given in wxLogTrace() documentation. |
23324ae1 FM |
438 | Finally, the @e wxLog::DoLog() function automatically prepends a time stamp |
439 | to all the messages. The format of the time stamp may be changed: it can be | |
440 | any string with % specifications fully described in the documentation of the | |
441 | standard @e strftime() function. For example, the default format is | |
442 | "[%d/%b/%y %H:%M:%S] " which gives something like "[17/Sep/98 22:10:16] " | |
443 | (without quotes) for the current date. Setting an empty string as the time | |
444 | format disables timestamping of the messages completely. | |
8becd062 | 445 | See also |
5bc128d6 RR |
446 | @li AddTraceMask() |
447 | @li RemoveTraceMask() | |
448 | @li ClearTraceMasks() | |
449 | @li GetTraceMasks() | |
450 | @li IsAllowedTraceMask() | |
451 | @li SetVerbose() | |
452 | @li GetVerbose() | |
453 | @li SetTimestamp() | |
454 | @li GetTimestamp() | |
455 | @li SetTraceMask() | |
456 | @li GetTraceMask() | |
457 | @li SetRepetitionCounting() | |
458 | @li GetRepetitionCounting() | |
459 | ||
8becd062 RR |
460 | @note Timestamping is disabled for Visual C++ users in debug builds by |
461 | default because otherwise it would be impossible to directly go to the line | |
462 | from which the log message was generated by simply clicking in the debugger | |
463 | window on the corresponding error message. If you wish to enable it, please | |
464 | use SetTimestamp() explicitly. | |
465 | ||
5bc128d6 RR |
466 | @section overview_wxLog_Target Manipulating the log target |
467 | ||
468 | The functions in this section work with and manipulate the active log | |
469 | target. The OnLog() is called by the @e wxLogXXX() functions | |
470 | and invokes the DoLog() of the active log target if any. | |
471 | Get/Set methods are used to install/query the current active target and, | |
472 | finally, DontCreateOnDemand() disables the automatic creation of a standard | |
473 | log target if none actually exists. It is only useful when the application | |
474 | is terminating and shouldn't be used in other situations because it may | |
475 | easily lead to a loss of messages. See also | |
476 | @li OnLog() | |
477 | @li GetActiveTarget() | |
478 | @li SetActiveTarget() | |
479 | @li DontCreateOnDemand() | |
480 | @li Suspend() | |
481 | @li Resume() | |
3c4f71cc | 482 | |
5bc128d6 RR |
483 | @library{wxcore} |
484 | @category{logging} | |
3c4f71cc | 485 | |
3e6f95dc | 486 | @see @ref overview_log |
5bc128d6 RR |
487 | */ |
488 | class wxLog | |
489 | { | |
490 | public: | |
491 | /** | |
492 | Add the @a mask to the list of allowed masks for | |
493 | wxLogTrace(). | |
3c4f71cc | 494 | |
5bc128d6 RR |
495 | @see RemoveTraceMask(), GetTraceMasks() |
496 | */ | |
497 | static void AddTraceMask(const wxString& mask); | |
3c4f71cc | 498 | |
5bc128d6 RR |
499 | /** |
500 | Removes all trace masks previously set with | |
501 | AddTraceMask(). | |
3c4f71cc | 502 | |
5bc128d6 RR |
503 | @see RemoveTraceMask() |
504 | */ | |
505 | static void ClearTraceMasks(); | |
3c4f71cc | 506 | |
23324ae1 FM |
507 | */ |
508 | ||
509 | ||
510 | /** | |
511 | Disables time stamping of the log messages. | |
23324ae1 FM |
512 | This function is new since wxWidgets version 2.9 |
513 | */ | |
514 | void SetTimestamp(const wxString& format); | |
515 | ||
516 | /** | |
4cc4bfaf | 517 | Called to process the message of the specified severity. @a msg is the text |
23324ae1 | 518 | of the message as specified in the call of @e wxLogXXX() function which |
4cc4bfaf | 519 | generated it and @a timestamp is the moment when the message was generated. |
23324ae1 FM |
520 | The base class version prepends the timestamp to the message, adds a prefix |
521 | corresponding to the log level and then calls | |
522 | DoLogString() with the resulting string. | |
523 | */ | |
524 | virtual void DoLog(wxLogLevel level, const wxString& msg, | |
525 | time_t timestamp); | |
526 | ||
527 | /** | |
528 | Called to log the specified string. The timestamp is already included in the | |
529 | string but still passed to this function. | |
23324ae1 FM |
530 | A simple implementation may just send the string to @c stdout or, better, |
531 | @c stderr. | |
532 | */ | |
533 | virtual void DoLogString(const wxString& msg, time_t timestamp); | |
534 | ||
535 | /** | |
536 | Instructs wxLog to not create new log targets on the fly if there is none | |
537 | currently. (Almost) for internal use only: it is supposed to be called by the | |
538 | application shutdown code. | |
23324ae1 FM |
539 | Note that this function also calls |
540 | ClearTraceMasks(). | |
541 | */ | |
542 | static void DontCreateOnDemand(); | |
543 | ||
544 | /** | |
545 | Shows all the messages currently in buffer and clears it. If the buffer | |
546 | is already empty, nothing happens. | |
547 | */ | |
548 | virtual void Flush(); | |
549 | ||
550 | /** | |
551 | Flushes the current log target if any, does nothing if there is none. | |
3c4f71cc | 552 | |
4cc4bfaf | 553 | @see Flush() |
23324ae1 FM |
554 | */ |
555 | static void FlushActive(); | |
556 | ||
557 | /** | |
558 | Returns the pointer to the active log target (may be @NULL). | |
559 | */ | |
4cc4bfaf | 560 | static wxLog* GetActiveTarget(); |
23324ae1 FM |
561 | |
562 | /** | |
563 | Returns the current log level limit. | |
564 | */ | |
565 | static wxLogLevel GetLogLevel(); | |
566 | ||
567 | /** | |
568 | Returns whether the repetition counting mode is enabled. | |
569 | */ | |
570 | static bool GetRepetitionCounting(); | |
571 | ||
572 | /** | |
573 | Returns the current timestamp format string. | |
574 | */ | |
575 | static const wxString GetTimestamp(); | |
576 | ||
577 | /** | |
578 | Returns the current trace mask, see Customization() section | |
579 | for details. | |
580 | */ | |
581 | static wxTraceMask GetTraceMask(); | |
582 | ||
583 | /** | |
584 | Returns the currently allowed list of string trace masks. | |
3c4f71cc | 585 | |
4cc4bfaf | 586 | @see AddTraceMask(). |
23324ae1 FM |
587 | */ |
588 | static const wxArrayString GetTraceMasks(); | |
589 | ||
590 | /** | |
591 | Returns whether the verbose mode is currently active. | |
592 | */ | |
593 | static bool GetVerbose(); | |
594 | ||
23324ae1 | 595 | /** |
4cc4bfaf | 596 | Returns @true if the @a mask is one of allowed masks for |
e54c96f1 | 597 | wxLogTrace(). |
5bc128d6 RR |
598 | |
599 | See also: AddTraceMask(), RemoveTraceMask() | |
23324ae1 FM |
600 | */ |
601 | static bool IsAllowedTraceMask(const wxString& mask); | |
602 | ||
603 | /** | |
604 | There are two functions which must be implemented by any derived class to | |
605 | actually process the log messages: DoLog() and | |
606 | DoLogString(). The second function receives a string | |
607 | which just has to be output in some way and the easiest way to write a new log | |
608 | target is to override just this function in the derived class. If more control | |
609 | over the output format is needed, then the first function must be overridden | |
3e6f95dc | 610 | which allows you to construct custom messages depending on the log level or even |
23324ae1 FM |
611 | do completely different things depending on the message severity (for example, |
612 | throw away all messages except warnings and errors, show warnings on the | |
613 | screen and forward the error messages to the user's (or programmer's) cell | |
614 | phone - maybe depending on whether the timestamp tells us if it is day or | |
615 | night in the current time zone). | |
23324ae1 FM |
616 | There also functions to support message buffering. Why are they needed? |
617 | Some of wxLog implementations, most notably the standard wxLogGui class, | |
618 | buffer the messages (for example, to avoid showing the user a zillion of modal | |
619 | message boxes one after another -- which would be really annoying). | |
620 | Flush() shows them all and clears the buffer contents. | |
621 | This function doesn't do anything if the buffer is already empty. | |
23324ae1 | 622 | Flush() |
3c4f71cc | 623 | |
23324ae1 FM |
624 | FlushActive() |
625 | */ | |
626 | ||
627 | ||
628 | /** | |
629 | Forwards the message at specified level to the @e DoLog() function of the | |
630 | active log target if there is any, does nothing otherwise. | |
631 | */ | |
632 | static void OnLog(wxLogLevel level, const wxString& message); | |
633 | ||
634 | /** | |
4cc4bfaf | 635 | Remove the @a mask from the list of allowed masks for |
e54c96f1 | 636 | wxLogTrace(). |
23324ae1 FM |
637 | See also: AddTraceMask() |
638 | */ | |
639 | static void RemoveTraceMask(const wxString& mask); | |
640 | ||
641 | /** | |
642 | Resumes logging previously suspended by a call to | |
643 | Suspend(). All messages logged in the meanwhile will be | |
644 | flushed soon. | |
645 | */ | |
646 | static void Resume(); | |
647 | ||
648 | /** | |
649 | Sets the specified log target as the active one. Returns the pointer to the | |
650 | previous active log target (may be @NULL). To suppress logging use a new | |
651 | instance of wxLogNull not @NULL. If the active log target is set to @NULL a | |
652 | new default log target will be created when logging occurs. | |
653 | */ | |
4cc4bfaf | 654 | static wxLog* SetActiveTarget(wxLog* logtarget); |
23324ae1 FM |
655 | |
656 | /** | |
657 | Specifies that log messages with level logLevel should be ignored | |
658 | and not sent to the active log target. | |
659 | */ | |
660 | static void SetLogLevel(wxLogLevel logLevel); | |
661 | ||
662 | /** | |
663 | Enables logging mode in which a log message is logged once, and in case exactly | |
7c913512 | 664 | the same message successively repeats one or more times, only the number of |
23324ae1 FM |
665 | repetitions is logged. |
666 | */ | |
4cc4bfaf | 667 | static void SetRepetitionCounting(bool repetCounting = true); |
23324ae1 FM |
668 | |
669 | /** | |
670 | Sets the timestamp format prepended by the default log targets to all | |
671 | messages. The string may contain any normal characters as well as % | |
672 | prefixed format specificators, see @e strftime() manual for details. | |
673 | Passing an empty string to this function disables message time stamping. | |
674 | */ | |
675 | static void SetTimestamp(const wxString& format); | |
676 | ||
677 | /** | |
678 | Sets the trace mask, see Customization() | |
679 | section for details. | |
680 | */ | |
681 | static void SetTraceMask(wxTraceMask mask); | |
682 | ||
683 | /** | |
684 | Activates or deactivates verbose mode in which the verbose messages are | |
685 | logged as the normal ones instead of being silently dropped. | |
686 | */ | |
4cc4bfaf | 687 | static void SetVerbose(bool verbose = true); |
23324ae1 FM |
688 | |
689 | /** | |
690 | Suspends the logging until Resume() is called. Note that | |
691 | the latter must be called the same number of times as the former to undo it, | |
692 | i.e. if you call Suspend() twice you must call Resume() twice as well. | |
23324ae1 FM |
693 | Note that suspending the logging means that the log sink won't be be flushed |
694 | periodically, it doesn't have any effect if the current log target does the | |
695 | logging immediately without waiting for Flush() to be | |
696 | called (the standard GUI log target only shows the log dialog when it is | |
697 | flushed, so Suspend() works as expected with it). | |
3c4f71cc | 698 | |
4cc4bfaf | 699 | @see Resume(), wxLogNull |
23324ae1 FM |
700 | */ |
701 | static void Suspend(); | |
702 | }; | |
703 | ||
704 | ||
e54c96f1 | 705 | |
23324ae1 FM |
706 | /** |
707 | @class wxLogNull | |
708 | @wxheader{log.h} | |
7c913512 | 709 | |
3e6f95dc | 710 | This class allows you to temporarily suspend logging. All calls to the log |
23324ae1 | 711 | functions during the life time of an object of this class are just ignored. |
7c913512 | 712 | |
23324ae1 FM |
713 | In particular, it can be used to suppress the log messages given by wxWidgets |
714 | itself but it should be noted that it is rarely the best way to cope with this | |
715 | problem as @b all log messages are suppressed, even if they indicate a | |
716 | completely different error than the one the programmer wanted to suppress. | |
7c913512 | 717 | |
23324ae1 | 718 | For instance, the example of the overview: |
7c913512 | 719 | |
23324ae1 FM |
720 | @code |
721 | wxFile file; | |
7c913512 | 722 | |
23324ae1 FM |
723 | // wxFile.Open() normally complains if file can't be opened, we don't want it |
724 | { | |
725 | wxLogNull logNo; | |
726 | if ( !file.Open("bar") ) | |
727 | ... process error ourselves ... | |
728 | } // ~wxLogNull called, old log sink restored | |
7c913512 | 729 | |
23324ae1 FM |
730 | wxLogMessage("..."); // ok |
731 | @endcode | |
7c913512 | 732 | |
23324ae1 | 733 | would be better written as: |
7c913512 | 734 | |
23324ae1 FM |
735 | @code |
736 | wxFile file; | |
7c913512 | 737 | |
23324ae1 FM |
738 | // don't try to open file if it doesn't exist, we are prepared to deal with |
739 | // this ourselves - but all other errors are not expected | |
740 | if ( wxFile::Exists("bar") ) | |
741 | { | |
742 | // gives an error message if the file couldn't be opened | |
743 | file.Open("bar"); | |
744 | } | |
745 | else | |
746 | { | |
747 | ... | |
748 | } | |
749 | @endcode | |
7c913512 FM |
750 | |
751 | ||
23324ae1 FM |
752 | @library{wxbase} |
753 | @category{logging} | |
754 | */ | |
755 | class wxLogNull : public wxLog | |
756 | { | |
757 | public: | |
758 | /** | |
759 | Suspends logging. | |
760 | */ | |
761 | wxLogNull(); | |
762 | ||
763 | /** | |
764 | Resumes logging. | |
765 | */ | |
766 | }; | |
767 | ||
768 | ||
e54c96f1 | 769 | |
23324ae1 FM |
770 | // ============================================================================ |
771 | // Global functions/macros | |
772 | // ============================================================================ | |
773 | ||
ef477678 BP |
774 | /** @ingroup group_funcmacro_log */ |
775 | //@{ | |
776 | ||
23324ae1 | 777 | /** |
ef477678 BP |
778 | This function shows a message to the user in a safe way and should be safe |
779 | to call even before the application has been initialized or if it is | |
780 | currently in some other strange state (for example, about to crash). Under | |
781 | Windows this function shows a message box using a native dialog instead of | |
782 | wxMessageBox() (which might be unsafe to call), elsewhere it simply prints | |
783 | the message to the standard output using the title as prefix. | |
7c913512 FM |
784 | |
785 | @param title | |
ef477678 BP |
786 | The title of the message box shown to the user or the prefix of the |
787 | message string. | |
7c913512 | 788 | @param text |
ef477678 | 789 | The text to show to the user. |
7c913512 | 790 | |
e54c96f1 | 791 | @see wxLogFatalError() |
ef477678 BP |
792 | |
793 | @header{wx/log.h} | |
23324ae1 | 794 | */ |
ef477678 BP |
795 | void wxSafeShowMessage(const wxString& title, const wxString& text); |
796 | ||
797 | /** | |
798 | Returns the error code from the last system call. This function uses | |
799 | @c errno on Unix platforms and @c GetLastError under Win32. | |
23324ae1 | 800 | |
ef477678 | 801 | @see wxSysErrorMsg(), wxLogSysError() |
96d7cc9b | 802 | |
ef477678 BP |
803 | @header{wx/log.h} |
804 | */ | |
805 | unsigned long wxSysErrorCode(); | |
96d7cc9b | 806 | |
ef477678 BP |
807 | /** |
808 | Returns the error message corresponding to the given system error code. If | |
809 | @a errCode is 0 (default), the last error code (as returned by | |
810 | wxSysErrorCode()) is used. | |
811 | ||
812 | @see wxSysErrorCode(), wxLogSysError() | |
813 | ||
814 | @header{wx/log.h} | |
815 | */ | |
816 | const wxChar* wxSysErrorMsg(unsigned long errCode = 0); | |
817 | ||
818 | //@} | |
819 | ||
820 | /** @ingroup group_funcmacro_log */ | |
96d7cc9b FM |
821 | //@{ |
822 | /** | |
ef477678 BP |
823 | For all normal, informational messages. They also appear in a message box |
824 | by default (but it can be changed). | |
825 | ||
826 | @header{wx/log.h} | |
96d7cc9b FM |
827 | */ |
828 | void wxLogMessage(const char* formatString, ... ); | |
829 | void wxVLogMessage(const char* formatString, va_list argPtr); | |
830 | //@} | |
831 | ||
ef477678 | 832 | /** @ingroup group_funcmacro_log */ |
96d7cc9b FM |
833 | //@{ |
834 | /** | |
ef477678 BP |
835 | For verbose output. Normally, it is suppressed, but might be activated if |
836 | the user wishes to know more details about the program progress (another, | |
837 | but possibly confusing name for the same function could be @c wxLogInfo). | |
838 | ||
839 | @header{wx/log.h} | |
96d7cc9b FM |
840 | */ |
841 | void wxLogVerbose(const char* formatString, ... ); | |
842 | void wxVLogVerbose(const char* formatString, va_list argPtr); | |
843 | //@} | |
844 | ||
ef477678 | 845 | /** @ingroup group_funcmacro_log */ |
96d7cc9b FM |
846 | //@{ |
847 | /** | |
ef477678 BP |
848 | For warnings - they are also normally shown to the user, but don't |
849 | interrupt the program work. | |
850 | ||
851 | @header{wx/log.h} | |
96d7cc9b FM |
852 | */ |
853 | void wxLogWarning(const char* formatString, ... ); | |
854 | void wxVLogWarning(const char* formatString, va_list argPtr); | |
855 | //@} | |
856 | ||
ef477678 | 857 | /** @ingroup group_funcmacro_log */ |
96d7cc9b FM |
858 | //@{ |
859 | /** | |
ef477678 BP |
860 | Like wxLogError(), but also terminates the program with the exit code 3. |
861 | Using @e abort() standard function also terminates the program with this | |
862 | exit code. | |
863 | ||
864 | @header{wx/log.h} | |
96d7cc9b FM |
865 | */ |
866 | void wxLogFatalError(const char* formatString, ... ); | |
ef477678 | 867 | void wxVLogFatalError(const char* formatString, va_list argPtr); |
96d7cc9b FM |
868 | //@} |
869 | ||
ef477678 | 870 | /** @ingroup group_funcmacro_log */ |
96d7cc9b FM |
871 | //@{ |
872 | /** | |
ef477678 BP |
873 | The functions to use for error messages, i.e. the messages that must be |
874 | shown to the user. The default processing is to pop up a message box to | |
875 | inform the user about it. | |
876 | ||
877 | @header{wx/log.h} | |
96d7cc9b FM |
878 | */ |
879 | void wxLogError(const char* formatString, ... ); | |
880 | void wxVLogError(const char* formatString, va_list argPtr); | |
881 | //@} | |
882 | ||
ef477678 | 883 | /** @ingroup group_funcmacro_log */ |
96d7cc9b FM |
884 | //@{ |
885 | /** | |
ef477678 BP |
886 | Like wxLogDebug(), trace functions only do something in debug builds and |
887 | expand to nothing in the release one. The reason for making it a separate | |
888 | function is that usually there are a lot of trace messages, so it might | |
889 | make sense to separate them from other debug messages. | |
890 | ||
891 | wxLogDebug(const char*,const char*,...) and | |
892 | wxLogDebug(wxTraceMask,const char*,...) can be used instead if you would | |
893 | like to be able to separate trace messages into different categories which | |
894 | can be enabled or disabled with the static functions provided in wxLog. | |
895 | ||
896 | @header{wx/log.h} | |
96d7cc9b FM |
897 | */ |
898 | void wxLogTrace(const char* formatString, ... ); | |
899 | void wxVLogTrace(const char* formatString, va_list argPtr); | |
ef477678 BP |
900 | //@} |
901 | ||
902 | /** @ingroup group_funcmacro_log */ | |
903 | //@{ | |
904 | /** | |
905 | Like wxLogDebug(), trace functions only do something in debug builds and | |
906 | expand to nothing in the release one. The reason for making it a separate | |
907 | function is that usually there are a lot of trace messages, so it might | |
908 | make sense to separate them from other debug messages. | |
909 | ||
910 | In this version of wxLogTrace(), trace messages can be separated into | |
911 | different categories and calls using this function only log the message if | |
912 | the given @a mask is currently enabled in wxLog. This lets you selectively | |
913 | trace only some operations and not others by enabling the desired trace | |
914 | masks with wxLog::AddTraceMask() or by setting the | |
915 | @ref overview_envvars "@c WXTRACE environment variable". | |
916 | ||
917 | The predefined string trace masks used by wxWidgets are: | |
918 | ||
919 | @beginDefList | |
920 | @itemdef{ wxTRACE_MemAlloc, Trace memory allocation (new/delete) } | |
921 | @itemdef{ wxTRACE_Messages, Trace window messages/X callbacks } | |
922 | @itemdef{ wxTRACE_ResAlloc, Trace GDI resource allocation } | |
923 | @itemdef{ wxTRACE_RefCount, Trace various ref counting operations } | |
924 | @itemdef{ wxTRACE_OleCalls, Trace OLE method calls (Win32 only) } | |
925 | @endDefList | |
926 | ||
927 | @note Since both the mask and the format string are strings, this might | |
928 | lead to function signature confusion in some cases: if you intend to | |
929 | call the format string only version of wxLogTrace(), add a "%s" | |
930 | format string parameter and then supply a second string parameter for | |
931 | that "%s", the string mask version of wxLogTrace() will erroneously | |
932 | get called instead, since you are supplying two string parameters to | |
933 | the function. In this case you'll unfortunately have to avoid having | |
934 | two leading string parameters, e.g. by adding a bogus integer (with | |
935 | its "%d" format string). | |
936 | ||
937 | @header{wx/log.h} | |
938 | */ | |
939 | void wxLogTrace(const char* mask, const char* formatString, ... ); | |
96d7cc9b | 940 | void wxVLogTrace(const char* mask, |
ef477678 BP |
941 | const char* formatString, |
942 | va_list argPtr); | |
96d7cc9b FM |
943 | //@} |
944 | ||
ef477678 BP |
945 | /** @ingroup group_funcmacro_log */ |
946 | //@{ | |
947 | /** | |
948 | Like wxLogDebug(), trace functions only do something in debug builds and | |
949 | expand to nothing in the release one. The reason for making it a separate | |
950 | function is that usually there are a lot of trace messages, so it might | |
951 | make sense to separate them from other debug messages. | |
952 | ||
953 | This version of wxLogTrace() only logs the message if all the bits | |
954 | corresponding to the @a mask are set in the wxLog trace mask which can be | |
955 | set by calling wxLog::SetTraceMask(). This version is less flexible than | |
956 | wxLogDebug(const char*,const char*,...) because it doesn't allow defining | |
957 | the user trace masks easily. This is why it is deprecated in favour of | |
958 | using string trace masks. | |
959 | ||
960 | The following bitmasks are defined for wxTraceMask: | |
961 | ||
962 | @beginDefList | |
963 | @itemdef{ wxTraceMemAlloc, Trace memory allocation (new/delete) } | |
964 | @itemdef{ wxTraceMessages, Trace window messages/X callbacks } | |
965 | @itemdef{ wxTraceResAlloc, Trace GDI resource allocation } | |
966 | @itemdef{ wxTraceRefCount, Trace various ref counting operations } | |
967 | @itemdef{ wxTraceOleCalls, Trace OLE method calls (Win32 only) } | |
968 | @endDefList | |
969 | ||
970 | @header{wx/log.h} | |
971 | */ | |
972 | void wxLogTrace(wxTraceMask mask, const char* formatString, ... ); | |
973 | void wxVLogTrace(wxTraceMask mask, const char* formatString, va_list argPtr); | |
974 | //@} | |
96d7cc9b | 975 | |
ef477678 | 976 | /** @ingroup group_funcmacro_log */ |
96d7cc9b FM |
977 | //@{ |
978 | /** | |
ef477678 BP |
979 | The right functions for debug output. They only do something in debug mode |
980 | (when the preprocessor symbol @c __WXDEBUG__ is defined) and expand to | |
96d7cc9b | 981 | nothing in release mode (otherwise). |
ef477678 BP |
982 | |
983 | @header{wx/log.h} | |
96d7cc9b FM |
984 | */ |
985 | void wxLogDebug(const char* formatString, ... ); | |
986 | void wxVLogDebug(const char* formatString, va_list argPtr); | |
987 | //@} | |
988 | ||
ef477678 | 989 | /** @ingroup group_funcmacro_log */ |
96d7cc9b FM |
990 | //@{ |
991 | /** | |
ef477678 BP |
992 | Messages logged by this function will appear in the statusbar of the |
993 | @a frame or of the top level application window by default (i.e. when using | |
96d7cc9b | 994 | the second version of the functions). |
ef477678 | 995 | |
96d7cc9b | 996 | If the target frame doesn't have a statusbar, the message will be lost. |
ef477678 BP |
997 | |
998 | @header{wx/log.h} | |
96d7cc9b | 999 | */ |
ef477678 BP |
1000 | void wxLogStatus(wxFrame* frame, const char* formatString, ... ); |
1001 | void wxVLogStatus(wxFrame* frame, const char* formatString, va_list argPtr); | |
96d7cc9b FM |
1002 | void wxLogStatus(const char* formatString, ... ); |
1003 | void wxVLogStatus(const char* formatString, va_list argPtr); | |
1004 | //@} | |
1005 | ||
ef477678 | 1006 | /** @ingroup group_funcmacro_log */ |
96d7cc9b FM |
1007 | //@{ |
1008 | /** | |
ef477678 BP |
1009 | Mostly used by wxWidgets itself, but might be handy for logging errors |
1010 | after system call (API function) failure. It logs the specified message | |
1011 | text as well as the last system error code (@e errno or @e ::GetLastError() | |
1012 | depending on the platform) and the corresponding error message. The second | |
1013 | form of this function takes the error code explicitly as the first | |
1014 | argument. | |
96d7cc9b FM |
1015 | |
1016 | @see wxSysErrorCode(), wxSysErrorMsg() | |
ef477678 BP |
1017 | |
1018 | @header{wx/log.h} | |
96d7cc9b FM |
1019 | */ |
1020 | void wxLogSysError(const char* formatString, ... ); | |
ef477678 | 1021 | void wxVLogSysError(const char* formatString, va_list argPtr); |
39fb8056 FM |
1022 | //@} |
1023 |