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