]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/log.h
adding principal class for command line builds (High Resolution Support), changing...
[wxWidgets.git] / interface / wx / log.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: log.h
54e280d8 3// Purpose: interface of wxLog* classes
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
4a6665c6
FM
9
10/**
11 Different standard log levels (you may also define your own) used with
75e488d5 12 by standard wxLog functions wxLogGeneric(), wxLogError(), wxLogWarning(), etc...
4a6665c6
FM
13*/
14enum 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
4a6665c6
FM
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*/
35typedef unsigned long wxLogLevel;
36
bc73d5ae
VZ
37/**
38 Information about a log record (unit of the log output).
39 */
af588446 40class wxLogRecordInfo
bc73d5ae 41{
af588446
VZ
42public:
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
bc73d5ae
VZ
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};
4a6665c6 70
e54c96f1 71
4ffdb640
VZ
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*/
116class wxLogFormatter
117{
118public:
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
152protected:
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
23324ae1
FM
168/**
169 @class wxLog
7c913512 170
54e280d8 171 wxLog class defines the interface for the <em>log targets</em> used by wxWidgets
3e6f95dc 172 logging functions as explained in the @ref overview_log.
54e280d8 173
23324ae1
FM
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
54e280d8 176 needs.
7c913512 177
54e280d8
FM
178 Otherwise, it is completely hidden behind the @ref group_funcmacro_log "wxLogXXX() functions"
179 and you may not even know about its existence.
7c913512 180
a44f3b5a
FM
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
4ffdb640 184 @library{wxbase}
5bc128d6 185 @category{logging}
3c4f71cc 186
54e280d8 187 @see @ref overview_log, @ref group_funcmacro_log "wxLogXXX() functions"
5bc128d6
RR
188*/
189class wxLog
190{
191public:
54e280d8
FM
192 /**
193 @name Trace mask functions
194 */
195 //@{
196
5bc128d6 197 /**
6a93e794 198 Add the @a mask to the list of allowed masks for wxLogTrace().
3c4f71cc 199
5bc128d6
RR
200 @see RemoveTraceMask(), GetTraceMasks()
201 */
202 static void AddTraceMask(const wxString& mask);
3c4f71cc 203
5bc128d6 204 /**
6a93e794 205 Removes all trace masks previously set with AddTraceMask().
3c4f71cc 206
5bc128d6
RR
207 @see RemoveTraceMask()
208 */
209 static void ClearTraceMasks();
3c4f71cc 210
23324ae1 211 /**
54e280d8 212 Returns the currently allowed list of string trace masks.
6a93e794 213
54e280d8 214 @see AddTraceMask().
23324ae1 215 */
54e280d8 216 static const wxArrayString& GetTraceMasks();
23324ae1 217
ba3af101 218 /**
54e280d8 219 Returns @true if the @a mask is one of allowed masks for wxLogTrace().
ba3af101 220
54e280d8
FM
221 See also: AddTraceMask(), RemoveTraceMask()
222 */
223 static bool IsAllowedTraceMask(const wxString& mask);
ba3af101 224
54e280d8
FM
225 /**
226 Remove the @a mask from the list of allowed masks for
227 wxLogTrace().
ba3af101 228
54e280d8
FM
229 @see AddTraceMask()
230 */
231 static void RemoveTraceMask(const wxString& mask);
232
233 //@}
ba3af101 234
232addd1 235
232addd1 236
54e280d8
FM
237 /**
238 @name Log target functions
23324ae1 239 */
54e280d8
FM
240 //@{
241
23324ae1 242 /**
54e280d8
FM
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).
3c4f71cc 249
54e280d8 250 Note that this function also calls ClearTraceMasks().
23324ae1 251 */
54e280d8 252 static void DontCreateOnDemand();
23324ae1
FM
253
254 /**
255 Returns the pointer to the active log target (may be @NULL).
acad886c
VZ
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.
23324ae1 268 */
4cc4bfaf 269 static wxLog* GetActiveTarget();
23324ae1
FM
270
271 /**
54e280d8 272 Sets the specified log target as the active one.
ba3af101 273
54e280d8
FM
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.
ba3af101 278
54e280d8 279 @see SetThreadActiveTarget()
23324ae1 280 */
54e280d8 281 static wxLog* SetActiveTarget(wxLog* logtarget);
23324ae1
FM
282
283 /**
54e280d8 284 Sets a thread-specific log target.
23324ae1 285
54e280d8
FM
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.
23324ae1 292
54e280d8
FM
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.
23324ae1 304
54e280d8
FM
305 @since 2.9.1
306 */
307 static wxLog *SetThreadActiveTarget(wxLog *logger);
308
23324ae1 309 /**
54e280d8 310 Flushes the current log target if any, does nothing if there is none.
3c4f71cc 311
54e280d8
FM
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().
23324ae1 317 */
54e280d8
FM
318 static void FlushActive();
319
23324ae1 320 /**
54e280d8
FM
321 Resumes logging previously suspended by a call to Suspend().
322 All messages logged in the meanwhile will be flushed soon.
23324ae1 323 */
54e280d8 324 static void Resume();
23324ae1 325
23324ae1 326 /**
54e280d8 327 Suspends the logging until Resume() is called.
8067ee11 328
54e280d8
FM
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
d13b34d3 332 Note that suspending the logging means that the log sink won't be flushed
54e280d8
FM
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
23324ae1 339 */
54e280d8
FM
340 static void Suspend();
341
342 //@}
343
344
23324ae1 345
ba3af101 346 /**
54e280d8
FM
347 @name Log level functions
348 */
349 //@{
350
351 /**
352 Returns the current log level limit.
ba3af101 353
54e280d8
FM
354 All messages at levels strictly greater than the value returned by this
355 function are not logged at all.
ba3af101 356
54e280d8
FM
357 @see SetLogLevel(), IsLevelEnabled()
358 */
359 static wxLogLevel GetLogLevel();
360
ba3af101 361 /**
53ff8df7 362 Returns true if logging at this level is enabled for the current thread.
ba3af101
VZ
363
364 This function only returns @true if logging is globally enabled and if
c602c59b
VZ
365 @a level is less than or equal to the maximal log level enabled for the
366 given @a component.
ba3af101 367
c602c59b
VZ
368 @see IsEnabled(), SetLogLevel(), GetLogLevel(), SetComponentLevel()
369
370 @since 2.9.1
ba3af101 371 */
c602c59b 372 static bool IsLevelEnabled(wxLogLevel level, wxString component);
ba3af101 373
c602c59b
VZ
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
23324ae1 396 /**
4a6665c6
FM
397 Specifies that log messages with level greater (numerically) than
398 @a logLevel should be ignored and not sent to the active log target.
c602c59b
VZ
399
400 @see SetComponentLevel()
23324ae1
FM
401 */
402 static void SetLogLevel(wxLogLevel logLevel);
54e280d8
FM
403
404 //@}
405
406
23324ae1
FM
407
408 /**
54e280d8 409 @name Enable/disable features functions
23324ae1 410 */
54e280d8
FM
411 //@{
412
acad886c 413 /**
54e280d8 414 Globally enable or disable logging.
acad886c 415
54e280d8
FM
416 Calling this function with @false argument disables all log messages
417 for the current thread.
acad886c 418
54e280d8 419 @see wxLogNull, IsEnabled()
acad886c 420
acad886c 421 @return
54e280d8
FM
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);
acad886c 426
54e280d8
FM
427 /**
428 Returns true if logging is enabled at all now.
429
430 @see IsLevelEnabled(), EnableLogging()
acad886c 431 */
54e280d8
FM
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.
4ffdb640
VZ
448
449 Notice that the current time stamp is only used by the default log
450 formatter and custom formatters may ignore this format.
54e280d8
FM
451 */
452 static const wxString& GetTimestamp();
acad886c 453
23324ae1
FM
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 %
d13b34d3 457 prefixed format specifiers, see @e strftime() manual for details.
23324ae1 458 Passing an empty string to this function disables message time stamping.
4ffdb640
VZ
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.
23324ae1
FM
464 */
465 static void SetTimestamp(const wxString& format);
466
bce9df55
FM
467 /**
468 Disables time stamping of the log messages.
469
4ffdb640
VZ
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
bce9df55
FM
473 @since 2.9.0
474 */
475 static void DisableTimestamp();
54e280d8 476
23324ae1 477 /**
54e280d8 478 Returns whether the verbose mode is currently active.
23324ae1 479 */
54e280d8 480 static bool GetVerbose();
23324ae1
FM
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.
54e280d8
FM
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
23324ae1 490 */
4cc4bfaf 491 static void SetVerbose(bool verbose = true);
54e280d8
FM
492
493 //@}
494
4ffdb640
VZ
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);
54e280d8 508
23324ae1
FM
509
510 /**
54e280d8
FM
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.
3c4f71cc 516
54e280d8
FM
517 If you override this method in a derived class, call the base class
518 version first, before doing anything else.
23324ae1 519 */
54e280d8
FM
520 virtual void Flush();
521
efce878a 522 /**
bc73d5ae 523 Log the given record.
efce878a
VZ
524
525 This function should only be called from the DoLog() implementations in
bc73d5ae
VZ
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().
efce878a
VZ
532
533 Example of use of this class from wxLogChain:
534 @code
bc73d5ae
VZ
535 void wxLogChain::DoLogRecord(wxLogLevel level,
536 const wxString& msg,
537 const wxLogRecordInfo& info)
efce878a
VZ
538 {
539 // let the previous logger show it
540 if ( m_logOld && IsPassingMessages() )
bc73d5ae 541 m_logOld->LogRecord(level, msg, info);
efce878a
VZ
542
543 // and also send it to the new one
544 if ( m_logNew && m_logNew != this )
bc73d5ae 545 m_logNew->LogRecord(level, msg, info);
efce878a
VZ
546 }
547 @endcode
548
bc73d5ae 549 @since 2.9.1
efce878a 550 */
86381d42 551 void LogRecord(wxLogLevel level, const wxString& msg, const wxLogRecordInfo& info);
efce878a 552
5e6e278d 553protected:
bc73d5ae
VZ
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 //@{
5e6e278d
FM
566
567 /**
85898d8b 568 Called to log a new record.
bc73d5ae
VZ
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().
5e6e278d 574
bc73d5ae
VZ
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().
5e6e278d 589 */
bc73d5ae 590 virtual void DoLogTextAtLevel(wxLogLevel level, const wxString& msg);
5e6e278d
FM
591
592 /**
bc73d5ae 593 Called to log the specified string.
5e6e278d 594
bc73d5ae
VZ
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().
5e6e278d 601 */
bc73d5ae
VZ
602 virtual void DoLogText(const wxString& msg);
603
604 //@}
23324ae1
FM
605};
606
607
e54c96f1 608
1c177548
VZ
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*/
636class wxLogChain : public wxLog
637{
638public:
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*/
703class wxLogInterposerTemp : public wxLogChain
704{
705public:
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*/
727class wxLogStream : public wxLog
728{
729public:
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*/
753class wxLogStderr : public wxLog
754{
755public:
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*/
780class wxLogBuffer : public wxLog
781{
782public:
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*/
822class wxLogInterposer : public wxLogChain
823{
824public:
825 /**
826 The default constructor installs this object as the current active log target.
827 */
828 wxLogInterposer();
829};
830
831
832
23324ae1
FM
833/**
834 @class wxLogNull
7c913512 835
3e6f95dc 836 This class allows you to temporarily suspend logging. All calls to the log
23324ae1 837 functions during the life time of an object of this class are just ignored.
7c913512 838
23324ae1
FM
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.
7c913512 843
23324ae1 844 For instance, the example of the overview:
7c913512 845
23324ae1 846 @code
6a93e794 847 wxFile file;
7c913512 848
23324ae1
FM
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
7c913512 855
23324ae1
FM
856 wxLogMessage("..."); // ok
857 @endcode
7c913512 858
23324ae1 859 would be better written as:
7c913512 860
23324ae1 861 @code
6a93e794 862 wxFile file;
7c913512 863
23324ae1
FM
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
7c913512
FM
876
877
23324ae1
FM
878 @library{wxbase}
879 @category{logging}
880*/
6a9994cf 881class wxLogNull
23324ae1
FM
882{
883public:
884 /**
885 Suspends logging.
886 */
887 wxLogNull();
888
889 /**
890 Resumes logging.
891 */
6a93e794 892 ~wxLogNull();
23324ae1
FM
893};
894
895
e54c96f1 896
23324ae1
FM
897// ============================================================================
898// Global functions/macros
899// ============================================================================
900
b21126db 901/** @addtogroup group_funcmacro_log */
ef477678
BP
902//@{
903
23324ae1 904/**
ef477678
BP
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.
7c913512
FM
911
912 @param title
ef477678
BP
913 The title of the message box shown to the user or the prefix of the
914 message string.
7c913512 915 @param text
ef477678 916 The text to show to the user.
7c913512 917
e54c96f1 918 @see wxLogFatalError()
ef477678
BP
919
920 @header{wx/log.h}
23324ae1 921*/
ef477678
BP
922void 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.
23324ae1 927
ef477678 928 @see wxSysErrorMsg(), wxLogSysError()
96d7cc9b 929
ef477678
BP
930 @header{wx/log.h}
931*/
932unsigned long wxSysErrorCode();
96d7cc9b 933
ef477678
BP
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*/
943const wxChar* wxSysErrorMsg(unsigned long errCode = 0);
944
945//@}
946
75e488d5
FM
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*/
955void wxLogGeneric(wxLogLevel level, const char* formatString, ... );
956void wxVLogGeneric(wxLogLevel level, const char* formatString, va_list argPtr);
957//@}
958
b21126db 959/** @addtogroup group_funcmacro_log */
96d7cc9b
FM
960//@{
961/**
ef477678
BP
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}
96d7cc9b
FM
966*/
967void wxLogMessage(const char* formatString, ... );
968void wxVLogMessage(const char* formatString, va_list argPtr);
969//@}
970
b21126db 971/** @addtogroup group_funcmacro_log */
96d7cc9b
FM
972//@{
973/**
ef477678
BP
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}
96d7cc9b
FM
979*/
980void wxLogVerbose(const char* formatString, ... );
981void wxVLogVerbose(const char* formatString, va_list argPtr);
982//@}
983
b21126db 984/** @addtogroup group_funcmacro_log */
96d7cc9b
FM
985//@{
986/**
ef477678
BP
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}
96d7cc9b
FM
991*/
992void wxLogWarning(const char* formatString, ... );
993void wxVLogWarning(const char* formatString, va_list argPtr);
994//@}
995
b21126db 996/** @addtogroup group_funcmacro_log */
96d7cc9b
FM
997//@{
998/**
ef477678
BP
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}
96d7cc9b
FM
1004*/
1005void wxLogFatalError(const char* formatString, ... );
ef477678 1006void wxVLogFatalError(const char* formatString, va_list argPtr);
96d7cc9b
FM
1007//@}
1008
b21126db 1009/** @addtogroup group_funcmacro_log */
96d7cc9b
FM
1010//@{
1011/**
ef477678
BP
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}
96d7cc9b
FM
1017*/
1018void wxLogError(const char* formatString, ... );
1019void wxVLogError(const char* formatString, va_list argPtr);
1020//@}
1021
b21126db 1022/** @addtogroup group_funcmacro_log */
96d7cc9b
FM
1023//@{
1024/**
695d5232 1025 Log a message at @c wxLOG_Trace log level (see ::wxLogLevelValues enum).
7bfc1038
VZ
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
ef477678
BP
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
695d5232
FM
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
ef477678
BP
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
ef477678
BP
1053 @header{wx/log.h}
1054*/
1055void wxLogTrace(const char* mask, const char* formatString, ... );
695d5232 1056void wxVLogTrace(const char* mask, const char* formatString, va_list argPtr);
96d7cc9b
FM
1057//@}
1058
b21126db 1059/** @addtogroup group_funcmacro_log */
ef477678
BP
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
22f24132 1067 @deprecated
ef477678
BP
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
34085a0d 1071 wxLogTrace(const char*,const char*,...) because it doesn't allow defining
ef477678
BP
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*/
1087void wxLogTrace(wxTraceMask mask, const char* formatString, ... );
1088void wxVLogTrace(wxTraceMask mask, const char* formatString, va_list argPtr);
1089//@}
96d7cc9b 1090
b21126db 1091/** @addtogroup group_funcmacro_log */
96d7cc9b
FM
1092//@{
1093/**
ef477678
BP
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
96d7cc9b 1096 nothing in release mode (otherwise).
ef477678
BP
1097
1098 @header{wx/log.h}
96d7cc9b
FM
1099*/
1100void wxLogDebug(const char* formatString, ... );
1101void wxVLogDebug(const char* formatString, va_list argPtr);
1102//@}
1103
b21126db 1104/** @addtogroup group_funcmacro_log */
96d7cc9b
FM
1105//@{
1106/**
ef477678
BP
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
96d7cc9b 1109 the second version of the functions).
ef477678 1110
96d7cc9b 1111 If the target frame doesn't have a statusbar, the message will be lost.
ef477678
BP
1112
1113 @header{wx/log.h}
96d7cc9b 1114*/
ef477678
BP
1115void wxLogStatus(wxFrame* frame, const char* formatString, ... );
1116void wxVLogStatus(wxFrame* frame, const char* formatString, va_list argPtr);
96d7cc9b
FM
1117void wxLogStatus(const char* formatString, ... );
1118void wxVLogStatus(const char* formatString, va_list argPtr);
1119//@}
1120
b21126db 1121/** @addtogroup group_funcmacro_log */
96d7cc9b
FM
1122//@{
1123/**
ef477678
BP
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
deed8373 1126 text as well as the last system error code (@e errno or @e GetLastError()
ef477678
BP
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.
96d7cc9b
FM
1130
1131 @see wxSysErrorCode(), wxSysErrorMsg()
ef477678
BP
1132
1133 @header{wx/log.h}
96d7cc9b
FM
1134*/
1135void wxLogSysError(const char* formatString, ... );
ef477678 1136void wxVLogSysError(const char* formatString, va_list argPtr);
39fb8056
FM
1137//@}
1138
7d9550df
VZ
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
e4431849 1146 build when not using wxIMPLEMENT_APP().
7d9550df
VZ
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