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