Split documentation of the GUI wxLog classes in a separate file.
[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
73 /**
74 @class wxLogFormatter
75
76 wxLogFormatter class is used to format the log messages. It implements the
77 default formatting and can be derived from to create custom formatters.
78
79 The default implementation formats the message into a string containing
80 the time stamp, level-dependent prefix and the message itself.
81
82 To change it, you can derive from it and override its Format() method. For
83 example, to include the thread id in the log messages you can use
84 @code
85 class LogFormatterWithThread : public wxLogFormatter
86 {
87 virtual wxString Format(wxLogLevel level,
88 const wxString& msg,
89 const wxLogRecordInfo& info) const
90 {
91 return wxString::Format("[%d] %s(%d) : %s",
92 info.threadId, info.filename, info.line, msg);
93 }
94 };
95 @endcode
96 And then associate it with wxLog instance using its SetFormatter(). Then,
97 if you call:
98
99 @code
100 wxLogMessage(_("*** Application started ***"));
101 @endcode
102
103 the log output could be something like:
104
105 @verbatim
106 [7872] d:\testApp\src\testApp.cpp(85) : *** Application started ***
107 @endverbatim
108
109 @library{wxbase}
110 @category{logging}
111
112 @see @ref overview_log
113
114 @since 2.9.4
115 */
116 class wxLogFormatter
117 {
118 public:
119 /**
120 The default ctor does nothing.
121 */
122 wxLogFormatter();
123
124
125 /**
126 This function creates the full log message string.
127
128 Override it to customize the output string format.
129
130 @param level
131 The level of this log record, e.g. ::wxLOG_Error.
132 @param msg
133 The log message itself.
134 @param info
135 All the other information (such as time, component, location...)
136 associated with this log record.
137
138 @return
139 The formated message.
140
141 @note
142 Time stamping is disabled for Visual C++ users in debug builds by
143 default because otherwise it would be impossible to directly go to the line
144 from which the log message was generated by simply clicking in the debugger
145 window on the corresponding error message. If you wish to enable it, override
146 FormatTime().
147 */
148 virtual wxString Format(wxLogLevel level,
149 const wxString& msg,
150 const wxLogRecordInfo& info) const;
151
152 protected:
153 /**
154 This function formats the time stamp part of the log message.
155
156 Override this function if you need to customize just the time stamp.
157
158 @param time
159 Time to format.
160
161 @return
162 The formated time string, may be empty.
163 */
164 virtual wxString FormatTime(time_t time) const;
165 };
166
167
168 /**
169 @class wxLog
170
171 wxLog class defines the interface for the <em>log targets</em> used by wxWidgets
172 logging functions as explained in the @ref overview_log.
173
174 The only situations when you need to directly use this class is when you want
175 to derive your own log target because the existing ones don't satisfy your
176 needs.
177
178 Otherwise, it is completely hidden behind the @ref group_funcmacro_log "wxLogXXX() functions"
179 and you may not even know about its existence.
180
181 @note For console-mode applications, the default target is wxLogStderr, so
182 that all @e wxLogXXX() functions print on @c stderr when @c wxUSE_GUI = 0.
183
184 @library{wxbase}
185 @category{logging}
186
187 @see @ref overview_log, @ref group_funcmacro_log "wxLogXXX() functions"
188 */
189 class wxLog
190 {
191 public:
192 /**
193 @name Trace mask functions
194 */
195 //@{
196
197 /**
198 Add the @a mask to the list of allowed masks for wxLogTrace().
199
200 @see RemoveTraceMask(), GetTraceMasks()
201 */
202 static void AddTraceMask(const wxString& mask);
203
204 /**
205 Removes all trace masks previously set with AddTraceMask().
206
207 @see RemoveTraceMask()
208 */
209 static void ClearTraceMasks();
210
211 /**
212 Returns the currently allowed list of string trace masks.
213
214 @see AddTraceMask().
215 */
216 static const wxArrayString& GetTraceMasks();
217
218 /**
219 Returns @true if the @a mask is one of allowed masks for wxLogTrace().
220
221 See also: AddTraceMask(), RemoveTraceMask()
222 */
223 static bool IsAllowedTraceMask(const wxString& mask);
224
225 /**
226 Remove the @a mask from the list of allowed masks for
227 wxLogTrace().
228
229 @see AddTraceMask()
230 */
231 static void RemoveTraceMask(const wxString& mask);
232
233 //@}
234
235
236
237 /**
238 @name Log target functions
239 */
240 //@{
241
242 /**
243 Instructs wxLog to not create new log targets on the fly if there is none
244 currently (see GetActiveTarget()).
245
246 (Almost) for internal use only: it is supposed to be called by the
247 application shutdown code (where you don't want the log target to be
248 automatically created anymore).
249
250 Note that this function also calls ClearTraceMasks().
251 */
252 static void DontCreateOnDemand();
253
254 /**
255 Returns the pointer to the active log target (may be @NULL).
256
257 Notice that if SetActiveTarget() hadn't been previously explicitly
258 called, this function will by default try to create a log target by
259 calling wxAppTraits::CreateLogTarget() which may be overridden in a
260 user-defined traits class to change the default behaviour. You may also
261 call DontCreateOnDemand() to disable this behaviour.
262
263 When this function is called from threads other than main one,
264 auto-creation doesn't happen. But if the thread has a thread-specific
265 log target previously set by SetThreadActiveTarget(), it is returned
266 instead of the global one. Otherwise, the global log target is
267 returned.
268 */
269 static wxLog* GetActiveTarget();
270
271 /**
272 Sets the specified log target as the active one.
273
274 Returns the pointer to the previous active log target (may be @NULL).
275 To suppress logging use a new instance of wxLogNull not @NULL. If the
276 active log target is set to @NULL a new default log target will be
277 created when logging occurs.
278
279 @see SetThreadActiveTarget()
280 */
281 static wxLog* SetActiveTarget(wxLog* logtarget);
282
283 /**
284 Sets a thread-specific log target.
285
286 The log target passed to this function will be used for all messages
287 logged by the current thread using the usual wxLog functions. This
288 shouldn't be called from the main thread which never uses a thread-
289 specific log target but can be used for the other threads to handle
290 thread logging completely separately; instead of buffering thread log
291 messages in the main thread logger.
292
293 Notice that unlike for SetActiveTarget(), wxWidgets does not destroy
294 the thread-specific log targets when the thread terminates so doing
295 this is your responsibility.
296
297 This method is only available if @c wxUSE_THREADS is 1, i.e. wxWidgets
298 was compiled with threads support.
299
300 @param logger
301 The new thread-specific log target, possibly @NULL.
302 @return
303 The previous thread-specific log target, initially @NULL.
304
305 @since 2.9.1
306 */
307 static wxLog *SetThreadActiveTarget(wxLog *logger);
308
309 /**
310 Flushes the current log target if any, does nothing if there is none.
311
312 When this method is called from the main thread context, it also
313 flushes any previously buffered messages logged by the other threads.
314 When it is called from the other threads it simply calls Flush() on the
315 currently active log target, so it mostly makes sense to do this if a
316 thread has its own logger set with SetThreadActiveTarget().
317 */
318 static void FlushActive();
319
320 /**
321 Resumes logging previously suspended by a call to Suspend().
322 All messages logged in the meanwhile will be flushed soon.
323 */
324 static void Resume();
325
326 /**
327 Suspends the logging until Resume() is called.
328
329 Note that the latter must be called the same number of times as the former
330 to undo it, i.e. if you call Suspend() twice you must call Resume() twice as well.
331
332 Note that suspending the logging means that the log sink won't be flushed
333 periodically, it doesn't have any effect if the current log target does the
334 logging immediately without waiting for Flush() to be called (the standard
335 GUI log target only shows the log dialog when it is flushed, so Suspend()
336 works as expected with it).
337
338 @see Resume(), wxLogNull
339 */
340 static void Suspend();
341
342 //@}
343
344
345
346 /**
347 @name Log level functions
348 */
349 //@{
350
351 /**
352 Returns the current log level limit.
353
354 All messages at levels strictly greater than the value returned by this
355 function are not logged at all.
356
357 @see SetLogLevel(), IsLevelEnabled()
358 */
359 static wxLogLevel GetLogLevel();
360
361 /**
362 Returns true if logging at this level is enabled for the current thread.
363
364 This function only returns @true if logging is globally enabled and if
365 @a level is less than or equal to the maximal log level enabled for the
366 given @a component.
367
368 @see IsEnabled(), SetLogLevel(), GetLogLevel(), SetComponentLevel()
369
370 @since 2.9.1
371 */
372 static bool IsLevelEnabled(wxLogLevel level, wxString component);
373
374 /**
375 Sets the log level for the given component.
376
377 For example, to disable all but error messages from wxWidgets network
378 classes you may use
379 @code
380 wxLog::SetComponentLevel("wx/net", wxLOG_Error);
381 @endcode
382
383 SetLogLevel() may be used to set the global log level.
384
385 @param component
386 Non-empty component name, possibly using slashes (@c /) to separate
387 it into several parts.
388 @param level
389 Maximal level of log messages from this component which will be
390 handled instead of being simply discarded.
391
392 @since 2.9.1
393 */
394 static void SetComponentLevel(const wxString& component, wxLogLevel level);
395
396 /**
397 Specifies that log messages with level greater (numerically) than
398 @a logLevel should be ignored and not sent to the active log target.
399
400 @see SetComponentLevel()
401 */
402 static void SetLogLevel(wxLogLevel logLevel);
403
404 //@}
405
406
407
408 /**
409 @name Enable/disable features functions
410 */
411 //@{
412
413 /**
414 Globally enable or disable logging.
415
416 Calling this function with @false argument disables all log messages
417 for the current thread.
418
419 @see wxLogNull, IsEnabled()
420
421 @return
422 The old state, i.e. @true if logging was previously enabled and
423 @false if it was disabled.
424 */
425 static bool EnableLogging(bool enable = true);
426
427 /**
428 Returns true if logging is enabled at all now.
429
430 @see IsLevelEnabled(), EnableLogging()
431 */
432 static bool IsEnabled();
433
434 /**
435 Returns whether the repetition counting mode is enabled.
436 */
437 static bool GetRepetitionCounting();
438
439 /**
440 Enables logging mode in which a log message is logged once, and in case exactly
441 the same message successively repeats one or more times, only the number of
442 repetitions is logged.
443 */
444 static void SetRepetitionCounting(bool repetCounting = true);
445
446 /**
447 Returns the current timestamp format string.
448
449 Notice that the current time stamp is only used by the default log
450 formatter and custom formatters may ignore this format.
451 */
452 static const wxString& GetTimestamp();
453
454 /**
455 Sets the timestamp format prepended by the default log targets to all
456 messages. The string may contain any normal characters as well as %
457 prefixed format specifiers, see @e strftime() manual for details.
458 Passing an empty string to this function disables message time stamping.
459
460 Notice that the current time stamp is only used by the default log
461 formatter and custom formatters may ignore this format. You can also
462 define a custom wxLogFormatter to customize the time stamp handling
463 beyond changing its format.
464 */
465 static void SetTimestamp(const wxString& format);
466
467 /**
468 Disables time stamping of the log messages.
469
470 Notice that the current time stamp is only used by the default log
471 formatter and custom formatters may ignore calls to this function.
472
473 @since 2.9.0
474 */
475 static void DisableTimestamp();
476
477 /**
478 Returns whether the verbose mode is currently active.
479 */
480 static bool GetVerbose();
481
482 /**
483 Activates or deactivates verbose mode in which the verbose messages are
484 logged as the normal ones instead of being silently dropped.
485
486 The verbose messages are the trace messages which are not disabled in the
487 release mode and are generated by wxLogVerbose().
488
489 @see @ref overview_log
490 */
491 static void SetVerbose(bool verbose = true);
492
493 //@}
494
495
496 /**
497 Sets the specified formatter as the active one.
498
499 @param formatter
500 The new formatter. If @NULL, reset to the default formatter.
501
502 Returns the pointer to the previous formatter. You must delete it
503 if you don't plan to attach it again to a wxLog object later.
504
505 @since 2.9.4
506 */
507 wxLogFormatter *SetFormatter(wxLogFormatter* formatter);
508
509
510 /**
511 Some of wxLog implementations, most notably the standard wxLogGui class,
512 buffer the messages (for example, to avoid showing the user a zillion of modal
513 message boxes one after another -- which would be really annoying).
514 This function shows them all and clears the buffer contents.
515 If the buffer is already empty, nothing happens.
516
517 If you override this method in a derived class, call the base class
518 version first, before doing anything else.
519 */
520 virtual void Flush();
521
522 /**
523 Log the given record.
524
525 This function should only be called from the DoLog() implementations in
526 the derived classes if they need to call DoLogRecord() on another log
527 object (they can, of course, just use wxLog::DoLogRecord() call syntax
528 to call it on the object itself). It should not be used for logging new
529 messages which can be only sent to the currently active logger using
530 OnLog() which also checks if the logging (for this level) is enabled
531 while this method just directly calls DoLog().
532
533 Example of use of this class from wxLogChain:
534 @code
535 void wxLogChain::DoLogRecord(wxLogLevel level,
536 const wxString& msg,
537 const wxLogRecordInfo& info)
538 {
539 // let the previous logger show it
540 if ( m_logOld && IsPassingMessages() )
541 m_logOld->LogRecord(level, msg, info);
542
543 // and also send it to the new one
544 if ( m_logNew && m_logNew != this )
545 m_logNew->LogRecord(level, msg, info);
546 }
547 @endcode
548
549 @since 2.9.1
550 */
551 void LogRecord(wxLogLevel level, const wxString& msg, const wxLogRecordInfo& info);
552
553 protected:
554 /**
555 @name Logging callbacks.
556
557 The functions which should be overridden by custom log targets.
558
559 When defining a new log target, you have a choice between overriding
560 DoLogRecord(), which provides maximal flexibility, DoLogTextAtLevel()
561 which can be used if you don't intend to change the default log
562 messages formatting but want to handle log messages of different levels
563 differently or, in the simplest case, DoLogText().
564 */
565 //@{
566
567 /**
568 Called to log a new record.
569
570 Any log message created by wxLogXXX() functions is passed to this
571 method of the active log target. The default implementation prepends
572 the timestamp and, for some log levels (e.g. error and warning), the
573 corresponding prefix to @a msg and passes it to DoLogTextAtLevel().
574
575 You may override this method to implement custom formatting of the
576 log messages or to implement custom filtering of log messages (e.g. you
577 could discard all log messages coming from the given source file).
578 */
579 virtual void DoLogRecord(wxLogLevel level,
580 const wxString& msg,
581 const wxLogRecordInfo& info);
582
583 /**
584 Called to log the specified string at given level.
585
586 The base class versions logs debug and trace messages on the system
587 default debug output channel and passes all the other messages to
588 DoLogText().
589 */
590 virtual void DoLogTextAtLevel(wxLogLevel level, const wxString& msg);
591
592 /**
593 Called to log the specified string.
594
595 A simple implementation might just send the string to @c stdout or
596 @c stderr or save it in a file (of course, the already existing
597 wxLogStderr can be used for this).
598
599 The base class version of this function asserts so it must be
600 overridden if you don't override DoLogRecord() or DoLogTextAtLevel().
601 */
602 virtual void DoLogText(const wxString& msg);
603
604 //@}
605 };
606
607
608
609 /**
610 @class wxLogChain
611
612 This simple class allows you to chain log sinks, that is to install a new sink but
613 keep passing log messages to the old one instead of replacing it completely as
614 wxLog::SetActiveTarget does.
615
616 It is especially useful when you want to divert the logs somewhere (for
617 example to a file or a log window) but also keep showing the error messages
618 using the standard dialogs as wxLogGui does by default.
619
620 Example of usage:
621
622 @code
623 wxLogChain *logChain = new wxLogChain(new wxLogStderr);
624
625 // all the log messages are sent to stderr and also processed as usually
626 ...
627
628 // don't delete logChain directly as this would leave a dangling
629 // pointer as active log target, use SetActiveTarget() instead
630 delete wxLog::SetActiveTarget(...something else or NULL...);
631 @endcode
632
633 @library{wxbase}
634 @category{logging}
635 */
636 class wxLogChain : public wxLog
637 {
638 public:
639 /**
640 Sets the specified @c logger (which may be @NULL) as the default log
641 target but the log messages are also passed to the previous log target if any.
642 */
643 wxLogChain(wxLog* logger);
644
645 /**
646 Destroys the previous log target.
647 */
648 virtual ~wxLogChain();
649
650 /**
651 Detaches the old log target so it won't be destroyed when the wxLogChain object
652 is destroyed.
653 */
654 void DetachOldLog();
655
656 /**
657 Returns the pointer to the previously active log target (which may be @NULL).
658 */
659 wxLog* GetOldLog() const;
660
661 /**
662 Returns @true if the messages are passed to the previously active log
663 target (default) or @false if PassMessages() had been called.
664 */
665 bool IsPassingMessages() const;
666
667 /**
668 By default, the log messages are passed to the previously active log target.
669 Calling this function with @false parameter disables this behaviour
670 (presumably temporarily, as you shouldn't use wxLogChain at all otherwise) and
671 it can be reenabled by calling it again with @a passMessages set to @true.
672 */
673 void PassMessages(bool passMessages);
674
675 /**
676 Sets another log target to use (may be @NULL).
677
678 The log target specified in the wxLogChain(wxLog*) constructor or in a
679 previous call to this function is deleted.
680 This doesn't change the old log target value (the one the messages are
681 forwarded to) which still remains the same as was active when wxLogChain
682 object was created.
683 */
684 void SetLog(wxLog* logger);
685 };
686
687
688
689 /**
690 @class wxLogInterposerTemp
691
692 A special version of wxLogChain which uses itself as the new log target.
693 It forwards log messages to the previously installed one in addition to
694 processing them itself. Unlike wxLogInterposer, it doesn't delete the old
695 target which means it can be used to temporarily redirect log output.
696
697 As per wxLogInterposer, this class must be derived from to implement
698 wxLog::DoLog and/or wxLog::DoLogString methods.
699
700 @library{wxbase}
701 @category{logging}
702 */
703 class wxLogInterposerTemp : public wxLogChain
704 {
705 public:
706 /**
707 The default constructor installs this object as the current active log target.
708 */
709 wxLogInterposerTemp();
710 };
711
712
713
714 /**
715 @class wxLogStream
716
717 This class can be used to redirect the log messages to a C++ stream.
718
719 Please note that this class is only available if wxWidgets was compiled with
720 the standard iostream library support (@c wxUSE_STD_IOSTREAM must be on).
721
722 @library{wxbase}
723 @category{logging}
724
725 @see wxLogStderr, wxStreamToTextRedirector
726 */
727 class wxLogStream : public wxLog
728 {
729 public:
730 /**
731 Constructs a log target which sends all the log messages to the given
732 output stream. If it is @NULL, the messages are sent to @c cerr.
733 */
734 wxLogStream(std::ostream *ostr = NULL);
735 };
736
737
738
739 /**
740 @class wxLogStderr
741
742 This class can be used to redirect the log messages to a C file stream (not to
743 be confused with C++ streams).
744
745 It is the default log target for the non-GUI wxWidgets applications which
746 send all the output to @c stderr.
747
748 @library{wxbase}
749 @category{logging}
750
751 @see wxLogStream
752 */
753 class wxLogStderr : public wxLog
754 {
755 public:
756 /**
757 Constructs a log target which sends all the log messages to the given
758 @c FILE. If it is @NULL, the messages are sent to @c stderr.
759 */
760 wxLogStderr(FILE* fp = NULL);
761 };
762
763
764
765 /**
766 @class wxLogBuffer
767
768 wxLogBuffer is a very simple implementation of log sink which simply collects
769 all the logged messages in a string (except the debug messages which are output
770 in the usual way immediately as we're presumably not interested in collecting
771 them for later). The messages from different log function calls are separated
772 by the new lines.
773
774 All the messages collected so far can be shown to the user (and the current
775 buffer cleared) by calling the overloaded wxLogBuffer::Flush method.
776
777 @library{wxbase}
778 @category{logging}
779 */
780 class wxLogBuffer : public wxLog
781 {
782 public:
783 /**
784 The default ctor does nothing.
785 */
786 wxLogBuffer();
787
788 /**
789 Shows all the messages collected so far to the user (using a message box in the
790 GUI applications or by printing them out to the console in text mode) and
791 clears the internal buffer.
792 */
793 virtual void Flush();
794
795 /**
796 Returns the current buffer contains. Messages from different log function calls
797 are separated with the new lines in the buffer.
798 The buffer can be cleared by Flush() which will also show the current
799 contents to the user.
800 */
801 const wxString& GetBuffer() const;
802 };
803
804
805
806 /**
807 @class wxLogInterposer
808
809 A special version of wxLogChain which uses itself as the new log target.
810 It forwards log messages to the previously installed one in addition to
811 processing them itself.
812
813 Unlike wxLogChain which is usually used directly as is, this class must be
814 derived from to implement wxLog::DoLog and/or wxLog::DoLogString methods.
815
816 wxLogInterposer destroys the previous log target in its destructor.
817 If you don't want this to happen, use wxLogInterposerTemp instead.
818
819 @library{wxbase}
820 @category{logging}
821 */
822 class wxLogInterposer : public wxLogChain
823 {
824 public:
825 /**
826 The default constructor installs this object as the current active log target.
827 */
828 wxLogInterposer();
829 };
830
831
832
833 /**
834 @class wxLogNull
835
836 This class allows you to temporarily suspend logging. All calls to the log
837 functions during the life time of an object of this class are just ignored.
838
839 In particular, it can be used to suppress the log messages given by wxWidgets
840 itself but it should be noted that it is rarely the best way to cope with this
841 problem as @b all log messages are suppressed, even if they indicate a
842 completely different error than the one the programmer wanted to suppress.
843
844 For instance, the example of the overview:
845
846 @code
847 wxFile file;
848
849 // wxFile.Open() normally complains if file can't be opened, we don't want it
850 {
851 wxLogNull logNo;
852 if ( !file.Open("bar") )
853 ... process error ourselves ...
854 } // ~wxLogNull called, old log sink restored
855
856 wxLogMessage("..."); // ok
857 @endcode
858
859 would be better written as:
860
861 @code
862 wxFile file;
863
864 // don't try to open file if it doesn't exist, we are prepared to deal with
865 // this ourselves - but all other errors are not expected
866 if ( wxFile::Exists("bar") )
867 {
868 // gives an error message if the file couldn't be opened
869 file.Open("bar");
870 }
871 else
872 {
873 ...
874 }
875 @endcode
876
877
878 @library{wxbase}
879 @category{logging}
880 */
881 class wxLogNull
882 {
883 public:
884 /**
885 Suspends logging.
886 */
887 wxLogNull();
888
889 /**
890 Resumes logging.
891 */
892 ~wxLogNull();
893 };
894
895
896
897 // ============================================================================
898 // Global functions/macros
899 // ============================================================================
900
901 /** @addtogroup group_funcmacro_log */
902 //@{
903
904 /**
905 This function shows a message to the user in a safe way and should be safe
906 to call even before the application has been initialized or if it is
907 currently in some other strange state (for example, about to crash). Under
908 Windows this function shows a message box using a native dialog instead of
909 wxMessageBox() (which might be unsafe to call), elsewhere it simply prints
910 the message to the standard output using the title as prefix.
911
912 @param title
913 The title of the message box shown to the user or the prefix of the
914 message string.
915 @param text
916 The text to show to the user.
917
918 @see wxLogFatalError()
919
920 @header{wx/log.h}
921 */
922 void wxSafeShowMessage(const wxString& title, const wxString& text);
923
924 /**
925 Returns the error code from the last system call. This function uses
926 @c errno on Unix platforms and @c GetLastError under Win32.
927
928 @see wxSysErrorMsg(), wxLogSysError()
929
930 @header{wx/log.h}
931 */
932 unsigned long wxSysErrorCode();
933
934 /**
935 Returns the error message corresponding to the given system error code. If
936 @a errCode is 0 (default), the last error code (as returned by
937 wxSysErrorCode()) is used.
938
939 @see wxSysErrorCode(), wxLogSysError()
940
941 @header{wx/log.h}
942 */
943 const wxChar* wxSysErrorMsg(unsigned long errCode = 0);
944
945 //@}
946
947 /** @addtogroup group_funcmacro_log */
948 //@{
949 /**
950 Logs a message with the given wxLogLevel.
951 E.g. using @c wxLOG_Message as first argument, this function behaves like wxLogMessage().
952
953 @header{wx/log.h}
954 */
955 void wxLogGeneric(wxLogLevel level, const char* formatString, ... );
956 void wxVLogGeneric(wxLogLevel level, const char* formatString, va_list argPtr);
957 //@}
958
959 /** @addtogroup group_funcmacro_log */
960 //@{
961 /**
962 For all normal, informational messages. They also appear in a message box
963 by default (but it can be changed).
964
965 @header{wx/log.h}
966 */
967 void wxLogMessage(const char* formatString, ... );
968 void wxVLogMessage(const char* formatString, va_list argPtr);
969 //@}
970
971 /** @addtogroup group_funcmacro_log */
972 //@{
973 /**
974 For verbose output. Normally, it is suppressed, but might be activated if
975 the user wishes to know more details about the program progress (another,
976 but possibly confusing name for the same function could be @c wxLogInfo).
977
978 @header{wx/log.h}
979 */
980 void wxLogVerbose(const char* formatString, ... );
981 void wxVLogVerbose(const char* formatString, va_list argPtr);
982 //@}
983
984 /** @addtogroup group_funcmacro_log */
985 //@{
986 /**
987 For warnings - they are also normally shown to the user, but don't
988 interrupt the program work.
989
990 @header{wx/log.h}
991 */
992 void wxLogWarning(const char* formatString, ... );
993 void wxVLogWarning(const char* formatString, va_list argPtr);
994 //@}
995
996 /** @addtogroup group_funcmacro_log */
997 //@{
998 /**
999 Like wxLogError(), but also terminates the program with the exit code 3.
1000 Using @e abort() standard function also terminates the program with this
1001 exit code.
1002
1003 @header{wx/log.h}
1004 */
1005 void wxLogFatalError(const char* formatString, ... );
1006 void wxVLogFatalError(const char* formatString, va_list argPtr);
1007 //@}
1008
1009 /** @addtogroup group_funcmacro_log */
1010 //@{
1011 /**
1012 The functions to use for error messages, i.e. the messages that must be
1013 shown to the user. The default processing is to pop up a message box to
1014 inform the user about it.
1015
1016 @header{wx/log.h}
1017 */
1018 void wxLogError(const char* formatString, ... );
1019 void wxVLogError(const char* formatString, va_list argPtr);
1020 //@}
1021
1022 /** @addtogroup group_funcmacro_log */
1023 //@{
1024 /**
1025 Log a message at @c wxLOG_Trace log level (see ::wxLogLevelValues enum).
1026
1027 Notice that the use of trace masks is not recommended any more as setting
1028 the log components (please see @ref overview_log_enable) provides a way to
1029 do the same thing for log messages of any level, and not just the tracing
1030 ones.
1031
1032 Like wxLogDebug(), trace functions only do something in debug builds and
1033 expand to nothing in the release one. The reason for making it a separate
1034 function is that usually there are a lot of trace messages, so it might
1035 make sense to separate them from other debug messages.
1036
1037 Trace messages can be separated into different categories; these functions in facts
1038 only log the message if the given @a mask is currently enabled in wxLog.
1039 This lets you selectively trace only some operations and not others by enabling the
1040 desired trace masks with wxLog::AddTraceMask() or by setting the
1041 @ref overview_envvars "@c WXTRACE environment variable".
1042
1043 The predefined string trace masks used by wxWidgets are:
1044
1045 @beginDefList
1046 @itemdef{ wxTRACE_MemAlloc, Trace memory allocation (new/delete) }
1047 @itemdef{ wxTRACE_Messages, Trace window messages/X callbacks }
1048 @itemdef{ wxTRACE_ResAlloc, Trace GDI resource allocation }
1049 @itemdef{ wxTRACE_RefCount, Trace various ref counting operations }
1050 @itemdef{ wxTRACE_OleCalls, Trace OLE method calls (Win32 only) }
1051 @endDefList
1052
1053 @header{wx/log.h}
1054 */
1055 void wxLogTrace(const char* mask, const char* formatString, ... );
1056 void wxVLogTrace(const char* mask, const char* formatString, va_list argPtr);
1057 //@}
1058
1059 /** @addtogroup group_funcmacro_log */
1060 //@{
1061 /**
1062 Like wxLogDebug(), trace functions only do something in debug builds and
1063 expand to nothing in the release one. The reason for making it a separate
1064 function is that usually there are a lot of trace messages, so it might
1065 make sense to separate them from other debug messages.
1066
1067 @deprecated
1068 This version of wxLogTrace() only logs the message if all the bits
1069 corresponding to the @a mask are set in the wxLog trace mask which can be
1070 set by calling wxLog::SetTraceMask(). This version is less flexible than
1071 wxLogTrace(const char*,const char*,...) because it doesn't allow defining
1072 the user trace masks easily. This is why it is deprecated in favour of
1073 using string trace masks.
1074
1075 The following bitmasks are defined for wxTraceMask:
1076
1077 @beginDefList
1078 @itemdef{ wxTraceMemAlloc, Trace memory allocation (new/delete) }
1079 @itemdef{ wxTraceMessages, Trace window messages/X callbacks }
1080 @itemdef{ wxTraceResAlloc, Trace GDI resource allocation }
1081 @itemdef{ wxTraceRefCount, Trace various ref counting operations }
1082 @itemdef{ wxTraceOleCalls, Trace OLE method calls (Win32 only) }
1083 @endDefList
1084
1085 @header{wx/log.h}
1086 */
1087 void wxLogTrace(wxTraceMask mask, const char* formatString, ... );
1088 void wxVLogTrace(wxTraceMask mask, const char* formatString, va_list argPtr);
1089 //@}
1090
1091 /** @addtogroup group_funcmacro_log */
1092 //@{
1093 /**
1094 The right functions for debug output. They only do something in debug mode
1095 (when the preprocessor symbol @c __WXDEBUG__ is defined) and expand to
1096 nothing in release mode (otherwise).
1097
1098 @header{wx/log.h}
1099 */
1100 void wxLogDebug(const char* formatString, ... );
1101 void wxVLogDebug(const char* formatString, va_list argPtr);
1102 //@}
1103
1104 /** @addtogroup group_funcmacro_log */
1105 //@{
1106 /**
1107 Messages logged by this function will appear in the statusbar of the
1108 @a frame or of the top level application window by default (i.e. when using
1109 the second version of the functions).
1110
1111 If the target frame doesn't have a statusbar, the message will be lost.
1112
1113 @header{wx/log.h}
1114 */
1115 void wxLogStatus(wxFrame* frame, const char* formatString, ... );
1116 void wxVLogStatus(wxFrame* frame, const char* formatString, va_list argPtr);
1117 void wxLogStatus(const char* formatString, ... );
1118 void wxVLogStatus(const char* formatString, va_list argPtr);
1119 //@}
1120
1121 /** @addtogroup group_funcmacro_log */
1122 //@{
1123 /**
1124 Mostly used by wxWidgets itself, but might be handy for logging errors
1125 after system call (API function) failure. It logs the specified message
1126 text as well as the last system error code (@e errno or @e GetLastError()
1127 depending on the platform) and the corresponding error message. The second
1128 form of this function takes the error code explicitly as the first
1129 argument.
1130
1131 @see wxSysErrorCode(), wxSysErrorMsg()
1132
1133 @header{wx/log.h}
1134 */
1135 void wxLogSysError(const char* formatString, ... );
1136 void wxVLogSysError(const char* formatString, va_list argPtr);
1137 //@}
1138
1139 /** @addtogroup group_funcmacro_debug */
1140 //@{
1141
1142 /**
1143 @def wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD()
1144
1145 Use this macro to disable logging at debug and trace levels in release
1146 build when not using wxIMPLEMENT_APP().
1147
1148 @see wxDISABLE_DEBUG_SUPPORT(),
1149 wxDISABLE_ASSERTS_IN_RELEASE_BUILD(),
1150 @ref overview_debugging
1151
1152 @since 2.9.1
1153
1154 @header{wx/log.h}
1155 */
1156 #define wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD()
1157
1158 //@}
1159