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