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