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