]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/log.h
When registering editor, try wxRTTI class name in additon to result of wxPGEditor...
[wxWidgets.git] / interface / wx / log.h
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 virtual ~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.
192
193 Please see @ref overview_log_customize for explanation of how to change the
194 default log target.
195
196 An object of this class is used by default to show the log messages created
197 by using wxLogMessage(), wxLogError() and other logging functions. It
198 doesn't display the messages logged by them immediately however but
199 accumulates all messages logged during an event handler execution and then
200 shows them all at once when its Flush() method is called during the idle
201 time processing. This has the important advantage of showing only a single
202 dialog to the user even if several messages were logged because of a single
203 error as it often happens (e.g. a low level function could log a message
204 because it failed to open a file resulting in its caller logging another
205 message due to the failure of higher level operation requiring the use of
206 this file). If you need to force the display of all previously logged
207 messages immediately you can use wxLog::FlushActive() to force the dialog
208 display.
209
210 Also notice that if an error message is logged when several informative
211 messages had been already logged before, the informative messages are
212 discarded on the assumption that they are not useful -- and may be
213 confusing and hence harmful -- any more after the error. The warning
214 and error messages are never discarded however and any informational
215 messages logged after the first error one are also kept (as they may
216 contain information about the error recovery). You may override DoLog()
217 method to change this behaviour.
218
219 At any rate, it is possible that that several messages were accumulated
220 before this class Flush() method is called. If this is the case, Flush()
221 uses a custom dialog which shows the last message directly and allows the
222 user to view the previously logged ones by expanding the "Details"
223 wxCollapsiblePane inside it. This custom dialog also provides the buttons
224 for copying the log messages to the clipboard and saving them to a file.
225
226 However if only a single message is present when Flush() is called, just a
227 wxMessageBox() is used to show it. This has the advantage of being closer
228 to the native behaviour but it doesn't give the user any possibility to
229 copy or save the message (except for the recent Windows versions where @c
230 Ctrl-C may be pressed in the message box to copy its contents to the
231 clipboard) so you may want to override DoShowSingleMessage() to customize
232 wxLogGui -- the dialogs sample shows how to do this.
233
234 @library{wxcore}
235 @category{logging}
236 */
237 class wxLogGui : public wxLog
238 {
239 public:
240 /**
241 Default constructor.
242 */
243 wxLogGui();
244
245 /**
246 Presents the accumulated log messages, if any, to the user.
247
248 This method is called during the idle time and should show any messages
249 accumulated in wxLogGui#m_aMessages field to the user.
250 */
251 virtual void Flush();
252
253 protected:
254 /**
255 Returns the appropriate title for the dialog.
256
257 The title is constructed from wxApp::GetAppDisplayName() and the
258 severity string (e.g. "error" or "warning") appropriate for the current
259 wxLogGui#m_bErrors and wxLogGui#m_bWarnings values.
260 */
261 wxString GetTitle() const;
262
263 /**
264 Returns wxICON_ERROR, wxICON_WARNING or wxICON_INFORMATION depending on
265 the current maximal severity.
266
267 This value is suitable to be used in the style parameter of
268 wxMessageBox() function.
269 */
270 int GetSeverityIcon() const;
271
272 /**
273 Forgets all the currently stored messages.
274
275 If you override Flush() (and don't call the base class version), you
276 must call this method to avoid messages being logged over and over
277 again.
278 */
279 void Clear();
280
281
282 /**
283 Method called by Flush() to show a single log message.
284
285 This function can be overridden to show the message in a different way.
286 By default a simple wxMessageBox() call is used.
287
288 @param message
289 The message to show (it can contain multiple lines).
290 @param title
291 The suggested title for the dialog showing the message, see
292 GetTitle().
293 @param style
294 One of @c wxICON_XXX constants, see GetSeverityIcon().
295 */
296 virtual void DoShowSingleLogMessage(const wxString& message,
297 const wxString& title,
298 int style);
299
300 /**
301 Method called by Flush() to show multiple log messages.
302
303 This function can be overridden to show the messages in a different way.
304 By default a special log dialog showing the most recent message and
305 allowing the user to expand it to view the previously logged ones is
306 used.
307
308 @param messages
309 Array of messages to show; it contains more than one element.
310 @param severities
311 Array of message severities containing @c wxLOG_XXX values.
312 @param times
313 Array of time_t values indicating when each message was logged.
314 @param title
315 The suggested title for the dialog showing the message, see
316 GetTitle().
317 @param style
318 One of @c wxICON_XXX constants, see GetSeverityIcon().
319 */
320 virtual void DoShowMultipleLogMessages(const wxArrayString& messages,
321 const wxArrayInt& severities,
322 const wxArrayLong& times,
323 const wxString& title,
324 int style);
325
326
327 /**
328 All currently accumulated messages.
329
330 This array may be empty if no messages were logged.
331
332 @see m_aSeverity, m_aTimes
333 */
334 wxArrayString m_aMessages;
335
336 /**
337 The severities of each logged message.
338
339 This array is synchronized with wxLogGui#m_aMessages, i.e. the n-th
340 element of this array corresponds to the severity of the n-th message.
341 The possible severity values are @c wxLOG_XXX constants, e.g.
342 wxLOG_Error, wxLOG_Warning, wxLOG_Message etc.
343 */
344 wxArrayInt m_aSeverity;
345
346 /**
347 The time stamps of each logged message.
348
349 The elements of this array are time_t values corresponding to the time
350 when the message was logged.
351 */
352 wxArrayLong m_aTimes;
353
354 /**
355 True if there any error messages.
356 */
357 bool m_bErrors;
358
359 /**
360 True if there any warning messages.
361
362 If both wxLogGui#m_bErrors and this member are false, there are only
363 informational messages to be shown.
364 */
365 bool m_bWarnings;
366
367 /**
368 True if there any messages to be shown to the user.
369
370 This variable is used instead of simply checking whether
371 wxLogGui#m_aMessages array is empty to allow blocking further calls to
372 Flush() while a log dialog is already being shown, even if the messages
373 array hasn't been emptied yet.
374 */
375 bool m_bHasMessages;
376 };
377
378
379
380 /**
381 @class wxLogStream
382
383 This class can be used to redirect the log messages to a C++ stream.
384
385 Please note that this class is only available if wxWidgets was compiled with
386 the standard iostream library support (@c wxUSE_STD_IOSTREAM must be on).
387
388 @library{wxbase}
389 @category{logging}
390
391 @see wxLogStderr, wxStreamToTextRedirector
392 */
393 class wxLogStream : public wxLog
394 {
395 public:
396 /**
397 Constructs a log target which sends all the log messages to the given
398 output stream. If it is @NULL, the messages are sent to @c cerr.
399 */
400 wxLogStream(std::ostream ostr = NULL);
401 };
402
403
404
405 /**
406 @class wxLogStderr
407
408 This class can be used to redirect the log messages to a C file stream (not to
409 be confused with C++ streams). It is the default log target for the non-GUI
410 wxWidgets applications which send all the output to @c stderr.
411
412 @library{wxbase}
413 @category{logging}
414
415 @see wxLogStream
416 */
417 class wxLogStderr : public wxLog
418 {
419 public:
420 /**
421 Constructs a log target which sends all the log messages to the given
422 @c FILE. If it is @NULL, the messages are sent to @c stderr.
423 */
424 wxLogStderr(FILE fp = NULL);
425 };
426
427
428
429 /**
430 @class wxLogBuffer
431
432 wxLogBuffer is a very simple implementation of log sink which simply collects
433 all the logged messages in a string (except the debug messages which are output
434 in the usual way immediately as we're presumably not interested in collecting
435 them for later). The messages from different log function calls are separated
436 by the new lines.
437
438 All the messages collected so far can be shown to the user (and the current
439 buffer cleared) by calling the overloaded wxLogBuffer::Flush
440 method.
441
442 @library{wxbase}
443 @category{logging}
444 */
445 class wxLogBuffer : public wxLog
446 {
447 public:
448 /**
449 Shows all the messages collected so far to the user (using a message box in the
450 GUI applications or by printing them out to the console in text mode) and
451 clears the internal buffer.
452 */
453 virtual void Flush();
454
455 /**
456 Returns the current buffer contains. Messages from different log function calls
457 are separated with the new lines in the buffer.
458 The buffer can be cleared by Flush() which will
459 also show the current contents to the user.
460 */
461 const wxString GetBuffer();
462 };
463
464
465
466 /**
467 @class wxLogInterposer
468
469 A special version of wxLogChain which uses itself as the
470 new log target. It forwards log messages to the previously installed one in
471 addition to
472 processing them itself.
473
474 Unlike wxLogChain which is usually used directly as is,
475 this class must be derived from to implement wxLog::DoLog
476 and/or wxLog::DoLogString methods.
477
478 wxLogInterposer destroys the previous log target in its destructor. If you
479 don't want this to happen, use wxLogInterposerTemp instead.
480
481 @library{wxbase}
482 @category{logging}
483 */
484 class wxLogInterposer : public wxLogChain
485 {
486 public:
487 /**
488 The default constructor installs this object as the current active log target.
489 */
490 };
491
492
493
494 /**
495 @class wxLogTextCtrl
496
497 Using these target all the log messages can be redirected to a text control.
498 The text control must have been created with @c wxTE_MULTILINE style by the
499 caller previously.
500
501 @library{wxbase}
502 @category{logging}
503
504 @see wxTextCtrl, wxStreamToTextRedirector
505 */
506 class wxLogTextCtrl : public wxLog
507 {
508 public:
509 /**
510 Constructs a log target which sends all the log messages to the given text
511 control. The @a textctrl parameter cannot be @NULL.
512 */
513 wxLogTextCtrl(wxTextCtrl textctrl);
514 };
515
516
517
518 /**
519 @class wxLog
520
521 wxLog class defines the interface for the @e log targets used by wxWidgets
522 logging functions as explained in the @ref overview_log.
523 The only situations when you need to directly use this class is when you want
524 to derive your own log target because the existing ones don't satisfy your
525 needs. Another case is if you wish to customize the behaviour of the standard
526 logging classes (all of which respect the wxLog settings): for example, set
527 which trace messages are logged and which are not or change (or even remove
528 completely) the timestamp on the messages.
529
530 Otherwise, it is completely hidden behind the @e wxLogXXX() functions and
531 you may not even know about its existence.
532
533 @section overview_wxLog_deriving Deriving your own log target
534
535 There are two functions which must be implemented by any derived class to
536 actually process the log messages: DoLog() and
537 DoLogString(). The second function receives a string
538 which just has to be output in some way and the easiest way to write a new log
539 target is to override just this function in the derived class. If more control
540 over the output format is needed, then the first function must be overridden
541 which allows to construct custom messages depending on the log level or even
542 do completely different things depending on the message severity (for example,
543 throw away all messages except warnings and errors, show warnings on the
544 screen and forward the error messages to the user's (or programmer's) cell
545 phone - maybe depending on whether the timestamp tells us if it is day or
546 night in the current time zone).
547 There also functions to support message buffering. Why are they needed?
548 Some of wxLog implementations, most notably the standard wxLogGui class,
549 buffer the messages (for example, to avoid showing the user a zillion of modal
550 message boxes one after another -- which would be really annoying).
551 Flush() shows them all and clears the buffer contents.
552 This function doesn't do anything if the buffer is already empty.
553 See also:
554 @li Flush()
555 @li FlushActive()
556
557 @section overview_wxLog_Trace_Masks Using trace masks
558
559 The functions below allow some limited customization of wxLog behaviour
560 without writing a new log target class (which, aside from being a matter of
561 several minutes, allows you to do anything you want).
562 The verbose messages are the trace messages which are not disabled in the
563 release mode and are generated by wxLogVerbose(). They
564 are not normally shown to the user because they present little interest, but
565 may be activated, for example, in order to help the user find some program
566 problem.
567 As for the (real) trace messages, their handling depends on the settings of
568 the (application global) @e trace mask which can either be specified using
569 SetTraceMask(), GetTraceMask() and wxLogTrace() which takes an integer mask
570 or using AddTraceMask() for string trace masks.
571 The difference between bit-wise and string trace masks is that a message using
572 integer trace mask will only be logged if all bits of the mask are set in the
573 current mask while a message using string mask will be logged simply if the
574 mask had been added before to the list of allowed ones.
575 For example,
576
577 @code
578 wxLogTrace( wxTraceRefCount|wxTraceOleCalls, "Active object ref count: %d", nRef );
579 @endcode
580
581 will do something only if the current trace mask contains both
582 @c wxTraceRefCount and @c wxTraceOle, but
583
584 @code
585 wxLogTrace( wxTRACE_OleCalls, "IFoo::Bar() called" );
586 @endcode
587
588 will log the message if it was preceded by
589
590 @code
591 wxLog::AddTraceMask( wxTRACE_OleCalls);
592 @endcode
593
594 Using string masks is simpler and allows you to easily add custom ones, so this is
595 the preferred way of working with trace messages. The integer trace mask is
596 kept for compatibility and for additional (but very rarely needed) flexibility
597 only.
598 The standard trace masks are given in wxLogTrace() documentation.
599 Finally, the @e wxLog::DoLog() function automatically prepends a time stamp
600 to all the messages. The format of the time stamp may be changed: it can be
601 any string with % specifications fully described in the documentation of the
602 standard @e strftime() function. For example, the default format is
603 "[%d/%b/%y %H:%M:%S] " which gives something like "[17/Sep/98 22:10:16] "
604 (without quotes) for the current date. Setting an empty string as the time
605 format disables timestamping of the messages completely.
606 See also
607 @li AddTraceMask()
608 @li RemoveTraceMask()
609 @li ClearTraceMasks()
610 @li GetTraceMasks()
611 @li IsAllowedTraceMask()
612 @li SetVerbose()
613 @li GetVerbose()
614 @li SetTimestamp()
615 @li GetTimestamp()
616 @li SetTraceMask()
617 @li GetTraceMask()
618 @li SetRepetitionCounting()
619 @li GetRepetitionCounting()
620
621 @note Timestamping is disabled for Visual C++ users in debug builds by
622 default because otherwise it would be impossible to directly go to the line
623 from which the log message was generated by simply clicking in the debugger
624 window on the corresponding error message. If you wish to enable it, please
625 use SetTimestamp() explicitly.
626
627 @section overview_wxLog_Target Manipulating the log target
628
629 The functions in this section work with and manipulate the active log
630 target. The OnLog() is called by the @e wxLogXXX() functions
631 and invokes the DoLog() of the active log target if any.
632 Get/Set methods are used to install/query the current active target and,
633 finally, DontCreateOnDemand() disables the automatic creation of a standard
634 log target if none actually exists. It is only useful when the application
635 is terminating and shouldn't be used in other situations because it may
636 easily lead to a loss of messages. See also
637 @li OnLog()
638 @li GetActiveTarget()
639 @li SetActiveTarget()
640 @li DontCreateOnDemand()
641 @li Suspend()
642 @li Resume()
643
644 @library{wxcore}
645 @category{logging}
646
647 @see @ref overview_log
648 */
649 class wxLog
650 {
651 public:
652 /**
653 Add the @a mask to the list of allowed masks for
654 wxLogTrace().
655
656 @see RemoveTraceMask(), GetTraceMasks()
657 */
658 static void AddTraceMask(const wxString& mask);
659
660 /**
661 Removes all trace masks previously set with
662 AddTraceMask().
663
664 @see RemoveTraceMask()
665 */
666 static void ClearTraceMasks();
667
668 /**
669 Disables time stamping of the log messages.
670 This function is new since wxWidgets version 2.9
671 */
672 static void SetTimestamp(const wxString& format);
673
674 /**
675 Called to process the message of the specified severity. @a msg is the text
676 of the message as specified in the call of @e wxLogXXX() function which
677 generated it and @a timestamp is the moment when the message was generated.
678 The base class version prepends the timestamp to the message, adds a prefix
679 corresponding to the log level and then calls
680 DoLogString() with the resulting string.
681 */
682 virtual void DoLog(wxLogLevel level, const wxString& msg,
683 time_t timestamp);
684
685 /**
686 Called to log the specified string. The timestamp is already included in the
687 string but still passed to this function.
688 A simple implementation may just send the string to @c stdout or, better,
689 @c stderr.
690 */
691 virtual void DoLogString(const wxString& msg, time_t timestamp);
692
693 /**
694 Instructs wxLog to not create new log targets on the fly if there is none
695 currently. (Almost) for internal use only: it is supposed to be called by the
696 application shutdown code.
697 Note that this function also calls
698 ClearTraceMasks().
699 */
700 static void DontCreateOnDemand();
701
702 /**
703 Shows all the messages currently in buffer and clears it. If the buffer
704 is already empty, nothing happens.
705 */
706 virtual void Flush();
707
708 /**
709 Flushes the current log target if any, does nothing if there is none.
710
711 @see Flush()
712 */
713 static void FlushActive();
714
715 /**
716 Returns the pointer to the active log target (may be @NULL).
717 */
718 static wxLog* GetActiveTarget();
719
720 /**
721 Returns the current log level limit.
722 */
723 static wxLogLevel GetLogLevel();
724
725 /**
726 Returns whether the repetition counting mode is enabled.
727 */
728 static bool GetRepetitionCounting();
729
730 /**
731 Returns the current timestamp format string.
732 */
733 static const wxString GetTimestamp();
734
735 /**
736 Returns the current trace mask, see Customization() section
737 for details.
738 */
739 static wxTraceMask GetTraceMask();
740
741 /**
742 Returns the currently allowed list of string trace masks.
743
744 @see AddTraceMask().
745 */
746 static const wxArrayString GetTraceMasks();
747
748 /**
749 Returns whether the verbose mode is currently active.
750 */
751 static bool GetVerbose();
752
753 /**
754 Returns @true if the @a mask is one of allowed masks for
755 wxLogTrace().
756
757 See also: AddTraceMask(), RemoveTraceMask()
758 */
759 static bool IsAllowedTraceMask(const wxString& mask);
760
761 /**
762 There are two functions which must be implemented by any derived class to
763 actually process the log messages: DoLog() and
764 DoLogString(). The second function receives a string
765 which just has to be output in some way and the easiest way to write a new log
766 target is to override just this function in the derived class. If more control
767 over the output format is needed, then the first function must be overridden
768 which allows you to construct custom messages depending on the log level or even
769 do completely different things depending on the message severity (for example,
770 throw away all messages except warnings and errors, show warnings on the
771 screen and forward the error messages to the user's (or programmer's) cell
772 phone - maybe depending on whether the timestamp tells us if it is day or
773 night in the current time zone).
774 There also functions to support message buffering. Why are they needed?
775 Some of wxLog implementations, most notably the standard wxLogGui class,
776 buffer the messages (for example, to avoid showing the user a zillion of modal
777 message boxes one after another -- which would be really annoying).
778 Flush() shows them all and clears the buffer contents.
779 This function doesn't do anything if the buffer is already empty.
780 Flush()
781
782 FlushActive()
783 */
784
785
786 /**
787 Forwards the message at specified level to the @e DoLog() function of the
788 active log target if there is any, does nothing otherwise.
789 */
790 static void OnLog(wxLogLevel level, const wxString& message);
791
792 /**
793 Remove the @a mask from the list of allowed masks for
794 wxLogTrace().
795 See also: AddTraceMask()
796 */
797 static void RemoveTraceMask(const wxString& mask);
798
799 /**
800 Resumes logging previously suspended by a call to Suspend().
801 All messages logged in the meanwhile will be flushed soon.
802 */
803 static void Resume();
804
805 /**
806 Sets the specified log target as the active one.
807
808 Returns the pointer to the previous active log target (may be @NULL).
809 To suppress logging use a new instance of wxLogNull not @NULL. If the
810 active log target is set to @NULL a new default log target will be
811 created when logging occurs.
812 */
813 static wxLog* SetActiveTarget(wxLog* logtarget);
814
815 /**
816 Specifies that log messages with level logLevel should be ignored
817 and not sent to the active log target.
818 */
819 static void SetLogLevel(wxLogLevel logLevel);
820
821 /**
822 Enables logging mode in which a log message is logged once, and in case exactly
823 the same message successively repeats one or more times, only the number of
824 repetitions is logged.
825 */
826 static void SetRepetitionCounting(bool repetCounting = true);
827
828 /**
829 Sets the timestamp format prepended by the default log targets to all
830 messages. The string may contain any normal characters as well as %
831 prefixed format specificators, see @e strftime() manual for details.
832 Passing an empty string to this function disables message time stamping.
833 */
834 static void SetTimestamp(const wxString& format);
835
836 /**
837 Sets the trace mask, see Customization()
838 section for details.
839 */
840 static void SetTraceMask(wxTraceMask mask);
841
842 /**
843 Activates or deactivates verbose mode in which the verbose messages are
844 logged as the normal ones instead of being silently dropped.
845 */
846 static void SetVerbose(bool verbose = true);
847
848 /**
849 Suspends the logging until Resume() is called. Note that
850 the latter must be called the same number of times as the former to undo it,
851 i.e. if you call Suspend() twice you must call Resume() twice as well.
852 Note that suspending the logging means that the log sink won't be be flushed
853 periodically, it doesn't have any effect if the current log target does the
854 logging immediately without waiting for Flush() to be
855 called (the standard GUI log target only shows the log dialog when it is
856 flushed, so Suspend() works as expected with it).
857
858 @see Resume(), wxLogNull
859 */
860 static void Suspend();
861 };
862
863
864
865 /**
866 @class wxLogNull
867
868 This class allows you to temporarily suspend logging. All calls to the log
869 functions during the life time of an object of this class are just ignored.
870
871 In particular, it can be used to suppress the log messages given by wxWidgets
872 itself but it should be noted that it is rarely the best way to cope with this
873 problem as @b all log messages are suppressed, even if they indicate a
874 completely different error than the one the programmer wanted to suppress.
875
876 For instance, the example of the overview:
877
878 @code
879 wxFile file;
880
881 // wxFile.Open() normally complains if file can't be opened, we don't want it
882 {
883 wxLogNull logNo;
884 if ( !file.Open("bar") )
885 ... process error ourselves ...
886 } // ~wxLogNull called, old log sink restored
887
888 wxLogMessage("..."); // ok
889 @endcode
890
891 would be better written as:
892
893 @code
894 wxFile file;
895
896 // don't try to open file if it doesn't exist, we are prepared to deal with
897 // this ourselves - but all other errors are not expected
898 if ( wxFile::Exists("bar") )
899 {
900 // gives an error message if the file couldn't be opened
901 file.Open("bar");
902 }
903 else
904 {
905 ...
906 }
907 @endcode
908
909
910 @library{wxbase}
911 @category{logging}
912 */
913 class wxLogNull : public wxLog
914 {
915 public:
916 /**
917 Suspends logging.
918 */
919 wxLogNull();
920
921 /**
922 Resumes logging.
923 */
924 };
925
926
927
928 // ============================================================================
929 // Global functions/macros
930 // ============================================================================
931
932 /** @ingroup group_funcmacro_log */
933 //@{
934
935 /**
936 This function shows a message to the user in a safe way and should be safe
937 to call even before the application has been initialized or if it is
938 currently in some other strange state (for example, about to crash). Under
939 Windows this function shows a message box using a native dialog instead of
940 wxMessageBox() (which might be unsafe to call), elsewhere it simply prints
941 the message to the standard output using the title as prefix.
942
943 @param title
944 The title of the message box shown to the user or the prefix of the
945 message string.
946 @param text
947 The text to show to the user.
948
949 @see wxLogFatalError()
950
951 @header{wx/log.h}
952 */
953 void wxSafeShowMessage(const wxString& title, const wxString& text);
954
955 /**
956 Returns the error code from the last system call. This function uses
957 @c errno on Unix platforms and @c GetLastError under Win32.
958
959 @see wxSysErrorMsg(), wxLogSysError()
960
961 @header{wx/log.h}
962 */
963 unsigned long wxSysErrorCode();
964
965 /**
966 Returns the error message corresponding to the given system error code. If
967 @a errCode is 0 (default), the last error code (as returned by
968 wxSysErrorCode()) is used.
969
970 @see wxSysErrorCode(), wxLogSysError()
971
972 @header{wx/log.h}
973 */
974 const wxChar* wxSysErrorMsg(unsigned long errCode = 0);
975
976 //@}
977
978 /** @ingroup group_funcmacro_log */
979 //@{
980 /**
981 For all normal, informational messages. They also appear in a message box
982 by default (but it can be changed).
983
984 @header{wx/log.h}
985 */
986 void wxLogMessage(const char* formatString, ... );
987 void wxVLogMessage(const char* formatString, va_list argPtr);
988 //@}
989
990 /** @ingroup group_funcmacro_log */
991 //@{
992 /**
993 For verbose output. Normally, it is suppressed, but might be activated if
994 the user wishes to know more details about the program progress (another,
995 but possibly confusing name for the same function could be @c wxLogInfo).
996
997 @header{wx/log.h}
998 */
999 void wxLogVerbose(const char* formatString, ... );
1000 void wxVLogVerbose(const char* formatString, va_list argPtr);
1001 //@}
1002
1003 /** @ingroup group_funcmacro_log */
1004 //@{
1005 /**
1006 For warnings - they are also normally shown to the user, but don't
1007 interrupt the program work.
1008
1009 @header{wx/log.h}
1010 */
1011 void wxLogWarning(const char* formatString, ... );
1012 void wxVLogWarning(const char* formatString, va_list argPtr);
1013 //@}
1014
1015 /** @ingroup group_funcmacro_log */
1016 //@{
1017 /**
1018 Like wxLogError(), but also terminates the program with the exit code 3.
1019 Using @e abort() standard function also terminates the program with this
1020 exit code.
1021
1022 @header{wx/log.h}
1023 */
1024 void wxLogFatalError(const char* formatString, ... );
1025 void wxVLogFatalError(const char* formatString, va_list argPtr);
1026 //@}
1027
1028 /** @ingroup group_funcmacro_log */
1029 //@{
1030 /**
1031 The functions to use for error messages, i.e. the messages that must be
1032 shown to the user. The default processing is to pop up a message box to
1033 inform the user about it.
1034
1035 @header{wx/log.h}
1036 */
1037 void wxLogError(const char* formatString, ... );
1038 void wxVLogError(const char* formatString, va_list argPtr);
1039 //@}
1040
1041 /** @ingroup group_funcmacro_log */
1042 //@{
1043 /**
1044 Like wxLogDebug(), trace functions only do something in debug builds and
1045 expand to nothing in the release one. The reason for making it a separate
1046 function is that usually there are a lot of trace messages, so it might
1047 make sense to separate them from other debug messages.
1048
1049 wxLogDebug(const char*,const char*,...) and
1050 wxLogDebug(wxTraceMask,const char*,...) can be used instead if you would
1051 like to be able to separate trace messages into different categories which
1052 can be enabled or disabled with the static functions provided in wxLog.
1053
1054 @header{wx/log.h}
1055 */
1056 void wxLogTrace(const char* formatString, ... );
1057 void wxVLogTrace(const char* formatString, va_list argPtr);
1058 //@}
1059
1060 /** @ingroup group_funcmacro_log */
1061 //@{
1062 /**
1063 Like wxLogDebug(), trace functions only do something in debug builds and
1064 expand to nothing in the release one. The reason for making it a separate
1065 function is that usually there are a lot of trace messages, so it might
1066 make sense to separate them from other debug messages.
1067
1068 In this version of wxLogTrace(), trace messages can be separated into
1069 different categories and calls using this function only log the message if
1070 the given @a mask is currently enabled in wxLog. This lets you selectively
1071 trace only some operations and not others by enabling the desired trace
1072 masks with wxLog::AddTraceMask() or by setting the
1073 @ref overview_envvars "@c WXTRACE environment variable".
1074
1075 The predefined string trace masks used by wxWidgets are:
1076
1077 @beginDefList
1078 @itemdef{ wxTRACE_MemAlloc, Trace memory allocation (new/delete) }
1079 @itemdef{ wxTRACE_Messages, Trace window messages/X callbacks }
1080 @itemdef{ wxTRACE_ResAlloc, Trace GDI resource allocation }
1081 @itemdef{ wxTRACE_RefCount, Trace various ref counting operations }
1082 @itemdef{ wxTRACE_OleCalls, Trace OLE method calls (Win32 only) }
1083 @endDefList
1084
1085 @note Since both the mask and the format string are strings, this might
1086 lead to function signature confusion in some cases: if you intend to
1087 call the format string only version of wxLogTrace(), add a "%s"
1088 format string parameter and then supply a second string parameter for
1089 that "%s", the string mask version of wxLogTrace() will erroneously
1090 get called instead, since you are supplying two string parameters to
1091 the function. In this case you'll unfortunately have to avoid having
1092 two leading string parameters, e.g. by adding a bogus integer (with
1093 its "%d" format string).
1094
1095 @header{wx/log.h}
1096 */
1097 void wxLogTrace(const char* mask, const char* formatString, ... );
1098 void wxVLogTrace(const char* mask,
1099 const char* formatString,
1100 va_list argPtr);
1101 //@}
1102
1103 /** @ingroup group_funcmacro_log */
1104 //@{
1105 /**
1106 Like wxLogDebug(), trace functions only do something in debug builds and
1107 expand to nothing in the release one. The reason for making it a separate
1108 function is that usually there are a lot of trace messages, so it might
1109 make sense to separate them from other debug messages.
1110
1111 This version of wxLogTrace() only logs the message if all the bits
1112 corresponding to the @a mask are set in the wxLog trace mask which can be
1113 set by calling wxLog::SetTraceMask(). This version is less flexible than
1114 wxLogDebug(const char*,const char*,...) because it doesn't allow defining
1115 the user trace masks easily. This is why it is deprecated in favour of
1116 using string trace masks.
1117
1118 The following bitmasks are defined for wxTraceMask:
1119
1120 @beginDefList
1121 @itemdef{ wxTraceMemAlloc, Trace memory allocation (new/delete) }
1122 @itemdef{ wxTraceMessages, Trace window messages/X callbacks }
1123 @itemdef{ wxTraceResAlloc, Trace GDI resource allocation }
1124 @itemdef{ wxTraceRefCount, Trace various ref counting operations }
1125 @itemdef{ wxTraceOleCalls, Trace OLE method calls (Win32 only) }
1126 @endDefList
1127
1128 @header{wx/log.h}
1129 */
1130 void wxLogTrace(wxTraceMask mask, const char* formatString, ... );
1131 void wxVLogTrace(wxTraceMask mask, const char* formatString, va_list argPtr);
1132 //@}
1133
1134 /** @ingroup group_funcmacro_log */
1135 //@{
1136 /**
1137 The right functions for debug output. They only do something in debug mode
1138 (when the preprocessor symbol @c __WXDEBUG__ is defined) and expand to
1139 nothing in release mode (otherwise).
1140
1141 @header{wx/log.h}
1142 */
1143 void wxLogDebug(const char* formatString, ... );
1144 void wxVLogDebug(const char* formatString, va_list argPtr);
1145 //@}
1146
1147 /** @ingroup group_funcmacro_log */
1148 //@{
1149 /**
1150 Messages logged by this function will appear in the statusbar of the
1151 @a frame or of the top level application window by default (i.e. when using
1152 the second version of the functions).
1153
1154 If the target frame doesn't have a statusbar, the message will be lost.
1155
1156 @header{wx/log.h}
1157 */
1158 void wxLogStatus(wxFrame* frame, const char* formatString, ... );
1159 void wxVLogStatus(wxFrame* frame, const char* formatString, va_list argPtr);
1160 void wxLogStatus(const char* formatString, ... );
1161 void wxVLogStatus(const char* formatString, va_list argPtr);
1162 //@}
1163
1164 /** @ingroup group_funcmacro_log */
1165 //@{
1166 /**
1167 Mostly used by wxWidgets itself, but might be handy for logging errors
1168 after system call (API function) failure. It logs the specified message
1169 text as well as the last system error code (@e errno or @e ::GetLastError()
1170 depending on the platform) and the corresponding error message. The second
1171 form of this function takes the error code explicitly as the first
1172 argument.
1173
1174 @see wxSysErrorCode(), wxSysErrorMsg()
1175
1176 @header{wx/log.h}
1177 */
1178 void wxLogSysError(const char* formatString, ... );
1179 void wxVLogSysError(const char* formatString, va_list argPtr);
1180 //@}
1181