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