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