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