]> git.saurik.com Git - wxWidgets.git/blob - include/wx/log.h
changed AddPendingEvent() to take const wxEvent reference, it doesn't need to modify it
[wxWidgets.git] / include / wx / log.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/log.h
3 // Purpose: Assorted wxLogXXX functions, and wxLog (sink for logs)
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 29/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_LOG_H_
13 #define _WX_LOG_H_
14
15 #include "wx/defs.h"
16
17 // ----------------------------------------------------------------------------
18 // common constants for use in wxUSE_LOG/!wxUSE_LOG
19 // ----------------------------------------------------------------------------
20
21 // the trace masks have been superceded by symbolic trace constants, they're
22 // for compatibility only andwill be removed soon - do NOT use them
23
24 // meaning of different bits of the trace mask (which allows selectively
25 // enable/disable some trace messages)
26 #define wxTraceMemAlloc 0x0001 // trace memory allocation (new/delete)
27 #define wxTraceMessages 0x0002 // trace window messages/X callbacks
28 #define wxTraceResAlloc 0x0004 // trace GDI resource allocation
29 #define wxTraceRefCount 0x0008 // trace various ref counting operations
30
31 #ifdef __WXMSW__
32 #define wxTraceOleCalls 0x0100 // OLE interface calls
33 #endif
34
35 // ----------------------------------------------------------------------------
36 // types
37 // ----------------------------------------------------------------------------
38
39 // NB: these types are needed even if wxUSE_LOG == 0
40 typedef unsigned long wxTraceMask;
41 typedef unsigned long wxLogLevel;
42
43 // ----------------------------------------------------------------------------
44 // headers
45 // ----------------------------------------------------------------------------
46
47 #include "wx/string.h"
48 #include "wx/strvararg.h"
49
50 #if wxUSE_LOG
51
52 #include "wx/arrstr.h"
53
54 #ifndef __WXWINCE__
55 #include <time.h> // for time_t
56 #endif
57
58 #include "wx/dynarray.h"
59
60 #ifndef wxUSE_LOG_DEBUG
61 # ifdef __WXDEBUG__
62 # define wxUSE_LOG_DEBUG 1
63 # else // !__WXDEBUG__
64 # define wxUSE_LOG_DEBUG 0
65 # endif
66 #endif
67
68 // ----------------------------------------------------------------------------
69 // forward declarations
70 // ----------------------------------------------------------------------------
71
72 #if wxUSE_GUI
73 class WXDLLIMPEXP_CORE wxTextCtrl;
74 class WXDLLIMPEXP_CORE wxLogFrame;
75 class WXDLLIMPEXP_CORE wxFrame;
76 class WXDLLIMPEXP_CORE wxWindow;
77 #endif // wxUSE_GUI
78
79 // ----------------------------------------------------------------------------
80 // constants
81 // ----------------------------------------------------------------------------
82
83 // different standard log levels (you may also define your own)
84 enum wxLogLevelValues
85 {
86 wxLOG_FatalError, // program can't continue, abort immediately
87 wxLOG_Error, // a serious error, user must be informed about it
88 wxLOG_Warning, // user is normally informed about it but may be ignored
89 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
90 wxLOG_Status, // informational: might go to the status line of GUI app
91 wxLOG_Info, // informational message (a.k.a. 'Verbose')
92 wxLOG_Debug, // never shown to the user, disabled in release mode
93 wxLOG_Trace, // trace messages are also only enabled in debug mode
94 wxLOG_Progress, // used for progress indicator (not yet)
95 wxLOG_User = 100, // user defined levels start here
96 wxLOG_Max = 10000
97 };
98
99 // symbolic trace masks - wxLogTrace("foo", "some trace message...") will be
100 // discarded unless the string "foo" has been added to the list of allowed
101 // ones with AddTraceMask()
102
103 #define wxTRACE_MemAlloc wxT("memalloc") // trace memory allocation (new/delete)
104 #define wxTRACE_Messages wxT("messages") // trace window messages/X callbacks
105 #define wxTRACE_ResAlloc wxT("resalloc") // trace GDI resource allocation
106 #define wxTRACE_RefCount wxT("refcount") // trace various ref counting operations
107
108 #ifdef __WXMSW__
109 #define wxTRACE_OleCalls wxT("ole") // OLE interface calls
110 #endif
111
112 #include "wx/iosfwrap.h"
113
114 // ----------------------------------------------------------------------------
115 // derive from this class to redirect (or suppress, or ...) log messages
116 // normally, only a single instance of this class exists but it's not enforced
117 // ----------------------------------------------------------------------------
118
119 class WXDLLIMPEXP_BASE wxLog
120 {
121 public:
122 // ctor
123 wxLog(){}
124
125 // these functions allow to completely disable all log messages
126
127 // is logging disabled now?
128 static bool IsEnabled() { return ms_doLog; }
129
130 // change the flag state, return the previous one
131 static bool EnableLogging(bool doIt = true)
132 { bool doLogOld = ms_doLog; ms_doLog = doIt; return doLogOld; }
133
134 // static sink function - see DoLog() for function to overload in the
135 // derived classes
136 static void OnLog(wxLogLevel level, const wxString& szString, time_t t);
137
138 // message buffering
139
140 // flush shows all messages if they're not logged immediately (FILE
141 // and iostream logs don't need it, but wxGuiLog does to avoid showing
142 // 17 modal dialogs one after another)
143 virtual void Flush();
144
145 // flush the active target if any
146 static void FlushActive()
147 {
148 if ( !ms_suspendCount )
149 {
150 wxLog *log = GetActiveTarget();
151 if ( log )
152 log->Flush();
153 }
154 }
155
156 // only one sink is active at each moment
157 // get current log target, will call wxApp::CreateLogTarget() to
158 // create one if none exists
159 static wxLog *GetActiveTarget();
160
161 // change log target, pLogger may be NULL
162 static wxLog *SetActiveTarget(wxLog *pLogger);
163
164 // suspend the message flushing of the main target until the next call
165 // to Resume() - this is mainly for internal use (to prevent wxYield()
166 // from flashing the messages)
167 static void Suspend() { ms_suspendCount++; }
168
169 // must be called for each Suspend()!
170 static void Resume() { ms_suspendCount--; }
171
172 // functions controlling the default wxLog behaviour
173 // verbose mode is activated by standard command-line '-verbose'
174 // option
175 static void SetVerbose(bool bVerbose = true) { ms_bVerbose = bVerbose; }
176
177 // Set log level. Log messages with level > logLevel will not be logged.
178 static void SetLogLevel(wxLogLevel logLevel) { ms_logLevel = logLevel; }
179
180 // should GetActiveTarget() try to create a new log object if the
181 // current is NULL?
182 static void DontCreateOnDemand();
183
184 // Make GetActiveTarget() create a new log object again.
185 static void DoCreateOnDemand();
186
187 // log the count of repeating messages instead of logging the messages
188 // multiple times
189 static void SetRepetitionCounting(bool bRepetCounting = true)
190 { ms_bRepetCounting = bRepetCounting; }
191
192 // gets duplicate counting status
193 static bool GetRepetitionCounting() { return ms_bRepetCounting; }
194
195 // trace mask (see wxTraceXXX constants for details)
196 static void SetTraceMask(wxTraceMask ulMask) { ms_ulTraceMask = ulMask; }
197
198 // add string trace mask
199 static void AddTraceMask(const wxString& str)
200 { ms_aTraceMasks.push_back(str); }
201
202 // add string trace mask
203 static void RemoveTraceMask(const wxString& str);
204
205 // remove all string trace masks
206 static void ClearTraceMasks();
207
208 // get string trace masks
209 static const wxArrayString &GetTraceMasks() { return ms_aTraceMasks; }
210
211 // sets the timestamp string: this is used as strftime() format string
212 // for the log targets which add time stamps to the messages - set it
213 // to NULL to disable time stamping completely.
214 static void SetTimestamp(const wxString& ts) { ms_timestamp = ts; }
215
216
217 // accessors
218
219 // gets the verbose status
220 static bool GetVerbose() { return ms_bVerbose; }
221
222 // get trace mask
223 static wxTraceMask GetTraceMask() { return ms_ulTraceMask; }
224
225 // is this trace mask in the list?
226 static bool IsAllowedTraceMask(const wxString& mask);
227
228 // return the current loglevel limit
229 static wxLogLevel GetLogLevel() { return ms_logLevel; }
230
231 // get the current timestamp format string (may be NULL)
232 static const wxString& GetTimestamp() { return ms_timestamp; }
233
234
235 // helpers
236
237 // put the time stamp into the string if ms_timestamp != NULL (don't
238 // change it otherwise)
239 static void TimeStamp(wxString *str);
240
241 // make dtor virtual for all derived classes
242 virtual ~wxLog();
243
244
245 // this method exists for backwards compatibility only, don't use
246 bool HasPendingMessages() const { return true; }
247
248 #if WXWIN_COMPATIBILITY_2_6
249 // this function doesn't do anything any more, don't call it
250 wxDEPRECATED( static wxChar *SetLogBuffer(wxChar *buf, size_t size = 0) );
251 #endif
252
253 protected:
254 // the logging functions that can be overriden
255
256 // default DoLog() prepends the time stamp and a prefix corresponding
257 // to the message to szString and then passes it to DoLogString()
258 virtual void DoLog(wxLogLevel level, const wxString& szString, time_t t);
259 #if WXWIN_COMPATIBILITY_2_8
260 // these shouldn't be used by new code
261 wxDEPRECATED_BUT_USED_INTERNALLY(
262 virtual void DoLog(wxLogLevel level, const char *szString, time_t t)
263 );
264
265 wxDEPRECATED_BUT_USED_INTERNALLY(
266 virtual void DoLog(wxLogLevel level, const wchar_t *wzString, time_t t)
267 );
268 #endif // WXWIN_COMPATIBILITY_2_8
269
270 void LogString(const wxString& szString, time_t t)
271 { DoLogString(szString, t); }
272
273 // default DoLogString does nothing but is not pure virtual because if
274 // you override DoLog() you might not need it at all
275 virtual void DoLogString(const wxString& szString, time_t t);
276 #if WXWIN_COMPATIBILITY_2_8
277 // these shouldn't be used by new code
278 virtual void DoLogString(const char *WXUNUSED(szString),
279 time_t WXUNUSED(t)) {}
280 virtual void DoLogString(const wchar_t *WXUNUSED(szString),
281 time_t WXUNUSED(t)) {}
282 #endif
283
284 // log a line containing the number of times the previous message was
285 // repeated
286 // returns: the number
287 static unsigned DoLogNumberOfRepeats();
288
289 private:
290 // static variables
291 // ----------------
292
293 // traditional behaviour or counting repetitions
294 static bool ms_bRepetCounting;
295 static wxString ms_prevString; // previous message that was logged
296 // how many times the previous message was logged
297 static unsigned ms_prevCounter;
298 static time_t ms_prevTimeStamp;// timestamp of the previous message
299 static wxLogLevel ms_prevLevel; // level of the previous message
300
301 static wxLog *ms_pLogger; // currently active log sink
302 static bool ms_doLog; // false => all logging disabled
303 static bool ms_bAutoCreate; // create new log targets on demand?
304 static bool ms_bVerbose; // false => ignore LogInfo messages
305
306 static wxLogLevel ms_logLevel; // limit logging to levels <= ms_logLevel
307
308 static size_t ms_suspendCount; // if positive, logs are not flushed
309
310 // format string for strftime(), if NULL, time stamping log messages is
311 // disabled
312 static wxString ms_timestamp;
313
314 static wxTraceMask ms_ulTraceMask; // controls wxLogTrace behaviour
315 static wxArrayString ms_aTraceMasks; // more powerful filter for wxLogTrace
316 };
317
318 // ----------------------------------------------------------------------------
319 // "trivial" derivations of wxLog
320 // ----------------------------------------------------------------------------
321
322 // log everything to a buffer
323 class WXDLLIMPEXP_BASE wxLogBuffer : public wxLog
324 {
325 public:
326 wxLogBuffer() { }
327
328 // get the string contents with all messages logged
329 const wxString& GetBuffer() const { return m_str; }
330
331 // show the buffer contents to the user in the best possible way (this uses
332 // wxMessageOutputMessageBox) and clear it
333 virtual void Flush();
334
335 protected:
336 virtual void DoLog(wxLogLevel level, const wxString& szString, time_t t);
337 virtual void DoLogString(const wxString& szString, time_t t);
338
339 private:
340 wxString m_str;
341
342 DECLARE_NO_COPY_CLASS(wxLogBuffer)
343 };
344
345
346 // log everything to a "FILE *", stderr by default
347 class WXDLLIMPEXP_BASE wxLogStderr : public wxLog
348 {
349 public:
350 // redirect log output to a FILE
351 wxLogStderr(FILE *fp = (FILE *) NULL);
352
353 protected:
354 // implement sink function
355 virtual void DoLogString(const wxString& szString, time_t t);
356
357 FILE *m_fp;
358
359 DECLARE_NO_COPY_CLASS(wxLogStderr)
360 };
361
362 #if wxUSE_STD_IOSTREAM
363
364 // log everything to an "ostream", cerr by default
365 class WXDLLIMPEXP_BASE wxLogStream : public wxLog
366 {
367 public:
368 // redirect log output to an ostream
369 wxLogStream(wxSTD ostream *ostr = (wxSTD ostream *) NULL);
370
371 protected:
372 // implement sink function
373 virtual void DoLogString(const wxString& szString, time_t t);
374
375 // using ptr here to avoid including <iostream.h> from this file
376 wxSTD ostream *m_ostr;
377 };
378
379 #endif // wxUSE_STD_IOSTREAM
380
381 // ----------------------------------------------------------------------------
382 // /dev/null log target: suppress logging until this object goes out of scope
383 // ----------------------------------------------------------------------------
384
385 // example of usage:
386 /*
387 void Foo()
388 {
389 wxFile file;
390
391 // wxFile.Open() normally complains if file can't be opened, we don't
392 // want it
393 wxLogNull logNo;
394
395 if ( !file.Open("bar") )
396 ... process error ourselves ...
397
398 // ~wxLogNull called, old log sink restored
399 }
400 */
401 class WXDLLIMPEXP_BASE wxLogNull
402 {
403 public:
404 wxLogNull() : m_flagOld(wxLog::EnableLogging(false)) { }
405 ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld); }
406
407 private:
408 bool m_flagOld; // the previous value of the wxLog::ms_doLog
409 };
410
411 // ----------------------------------------------------------------------------
412 // chaining log target: installs itself as a log target and passes all
413 // messages to the real log target given to it in the ctor but also forwards
414 // them to the previously active one
415 //
416 // note that you don't have to call SetActiveTarget() with this class, it
417 // does it itself in its ctor
418 // ----------------------------------------------------------------------------
419
420 class WXDLLIMPEXP_BASE wxLogChain : public wxLog
421 {
422 public:
423 wxLogChain(wxLog *logger);
424 virtual ~wxLogChain();
425
426 // change the new log target
427 void SetLog(wxLog *logger);
428
429 // this can be used to temporarily disable (and then reenable) passing
430 // messages to the old logger (by default we do pass them)
431 void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; }
432
433 // are we passing the messages to the previous log target?
434 bool IsPassingMessages() const { return m_bPassMessages; }
435
436 // return the previous log target (may be NULL)
437 wxLog *GetOldLog() const { return m_logOld; }
438
439 // override base class version to flush the old logger as well
440 virtual void Flush();
441
442 // call to avoid destroying the old log target
443 void DetachOldLog() { m_logOld = NULL; }
444
445 protected:
446 // pass the chain to the old logger if needed
447 virtual void DoLog(wxLogLevel level, const wxString& szString, time_t t);
448
449 private:
450 // the current log target
451 wxLog *m_logNew;
452
453 // the previous log target
454 wxLog *m_logOld;
455
456 // do we pass the messages to the old logger?
457 bool m_bPassMessages;
458
459 DECLARE_NO_COPY_CLASS(wxLogChain)
460 };
461
462 // a chain log target which uses itself as the new logger
463
464 #define wxLogPassThrough wxLogInterposer
465
466 class WXDLLIMPEXP_BASE wxLogInterposer : public wxLogChain
467 {
468 public:
469 wxLogInterposer();
470
471 private:
472 DECLARE_NO_COPY_CLASS(wxLogInterposer)
473 };
474
475 // a temporary interposer which doesn't destroy the old log target
476 // (calls DetachOldLog)
477
478 class WXDLLIMPEXP_BASE wxLogInterposerTemp : public wxLogChain
479 {
480 public:
481 wxLogInterposerTemp();
482
483 private:
484 DECLARE_NO_COPY_CLASS(wxLogInterposerTemp)
485 };
486
487 #if wxUSE_GUI
488 // include GUI log targets:
489 #include "wx/generic/logg.h"
490 #endif // wxUSE_GUI
491
492 // ============================================================================
493 // global functions
494 // ============================================================================
495
496 // ----------------------------------------------------------------------------
497 // Log functions should be used by application instead of stdio, iostream &c
498 // for log messages for easy redirection
499 // ----------------------------------------------------------------------------
500
501 // ----------------------------------------------------------------------------
502 // get error code/error message from system in a portable way
503 // ----------------------------------------------------------------------------
504
505 // return the last system error code
506 WXDLLIMPEXP_BASE unsigned long wxSysErrorCode();
507
508 // return the error message for given (or last if 0) error code
509 WXDLLIMPEXP_BASE const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0);
510
511 // ----------------------------------------------------------------------------
512 // define wxLog<level>
513 // ----------------------------------------------------------------------------
514
515 #define DECLARE_LOG_FUNCTION(level) \
516 extern void WXDLLIMPEXP_BASE \
517 wxDoLog##level##Wchar(const wxChar *format, ...); \
518 extern void WXDLLIMPEXP_BASE \
519 wxDoLog##level##Utf8(const char *format, ...); \
520 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
521 1, (const wxFormatString&), \
522 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
523 DECLARE_LOG_FUNCTION_WATCOM(level) \
524 extern void WXDLLIMPEXP_BASE wxVLog##level(const wxString& format, \
525 va_list argptr)
526
527 #ifdef __WATCOMC__
528 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
529 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
530 // something too big for Borland C++ to handle
531 #define DECLARE_LOG_FUNCTION_WATCOM(level) \
532 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
533 1, (const wxString&), \
534 (wxFormatString(f1))) \
535 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
536 1, (const wxCStrData&), \
537 (wxFormatString(f1))) \
538 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
539 1, (const char*), \
540 (wxFormatString(f1))) \
541 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
542 1, (const wchar_t*), \
543 (wxFormatString(f1)))
544 #else
545 #define DECLARE_LOG_FUNCTION_WATCOM(level)
546 #endif
547
548
549 #define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
550 extern void expdecl wxDoLog##level##Wchar(argclass arg, \
551 const wxChar *format, ...); \
552 extern void expdecl wxDoLog##level##Utf8(argclass arg, \
553 const char *format, ...); \
554 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
555 2, (argclass, const wxFormatString&), \
556 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
557 DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
558 extern void expdecl wxVLog##level(argclass arg, \
559 const wxString& format, \
560 va_list argptr)
561
562 #ifdef __WATCOMC__
563 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
564 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
565 // something too big for Borland C++ to handle
566 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
567 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
568 2, (argclass, const wxString&), \
569 (f1, wxFormatString(f2))) \
570 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
571 2, (argclass, const wxCStrData&), \
572 (f1, wxFormatString(f2))) \
573 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
574 2, (argclass, const char*), \
575 (f1, wxFormatString(f2))) \
576 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
577 2, (argclass, const wchar_t*), \
578 (f1, wxFormatString(f2)))
579 #else
580 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl)
581 #endif
582
583
584 #else // !wxUSE_LOG
585
586 #ifdef __WATCOMC__
587 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
588 #define WX_WATCOM_ONLY_CODE( x ) x
589 #else
590 #define WX_WATCOM_ONLY_CODE( x )
591 #endif
592
593 // log functions do nothing at all
594 #define DECLARE_LOG_FUNCTION(level) \
595 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxString&)) \
596 WX_WATCOM_ONLY_CODE( \
597 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const char*)) \
598 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wchar_t*)) \
599 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxCStrData&)) \
600 ) \
601 inline void wxVLog##level(const wxString& WXUNUSED(format), \
602 va_list WXUNUSED(argptr)) { } \
603
604 #define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
605 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxString&)) \
606 WX_WATCOM_ONLY_CODE( \
607 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const char*)) \
608 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wchar_t*)) \
609 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxCStrData&)) \
610 ) \
611 inline void wxVLog##level(argclass WXUNUSED(arg), \
612 const wxString& WXUNUSED(format), \
613 va_list WXUNUSED(argptr)) {}
614
615 // Empty Class to fake wxLogNull
616 class WXDLLIMPEXP_BASE wxLogNull
617 {
618 public:
619 wxLogNull() { }
620 };
621
622 // Dummy macros to replace some functions.
623 #define wxSysErrorCode() (unsigned long)0
624 #define wxSysErrorMsg( X ) (const wxChar*)NULL
625
626 // Fake symbolic trace masks... for those that are used frequently
627 #define wxTRACE_OleCalls wxEmptyString // OLE interface calls
628
629 #endif // wxUSE_LOG/!wxUSE_LOG
630
631 #define DECLARE_LOG_FUNCTION2(level, argclass, arg) \
632 DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, WXDLLIMPEXP_BASE)
633
634 // VC6 produces a warning if we a macro expanding to nothing to
635 // DECLARE_LOG_FUNCTION2:
636 #if defined(__VISUALC__) && __VISUALC__ < 1300
637 // "not enough actual parameters for macro 'DECLARE_LOG_FUNCTION2_EXP'"
638 #pragma warning(disable:4003)
639 #endif
640
641 // a generic function for all levels (level is passes as parameter)
642 DECLARE_LOG_FUNCTION2(Generic, wxLogLevel, level);
643
644 // one function per each level
645 DECLARE_LOG_FUNCTION(FatalError);
646 DECLARE_LOG_FUNCTION(Error);
647 DECLARE_LOG_FUNCTION(Warning);
648 DECLARE_LOG_FUNCTION(Message);
649 DECLARE_LOG_FUNCTION(Info);
650 DECLARE_LOG_FUNCTION(Verbose);
651
652 // this function sends the log message to the status line of the top level
653 // application frame, if any
654 DECLARE_LOG_FUNCTION(Status);
655
656 #if wxUSE_GUI
657 // this one is the same as previous except that it allows to explicitly
658 class WXDLLEXPORT wxFrame;
659 // specify the frame to which the output should go
660 DECLARE_LOG_FUNCTION2_EXP(Status, wxFrame *, pFrame, WXDLLIMPEXP_CORE);
661 #endif // wxUSE_GUI
662
663 // additional one: as wxLogError, but also logs last system call error code
664 // and the corresponding error message if available
665 DECLARE_LOG_FUNCTION(SysError);
666
667 // and another one which also takes the error code (for those broken APIs
668 // that don't set the errno (like registry APIs in Win32))
669 DECLARE_LOG_FUNCTION2(SysError, long, lErrCode);
670 #ifdef __WATCOMC__
671 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
672 DECLARE_LOG_FUNCTION2(SysError, unsigned long, lErrCode);
673 #endif
674
675 // debug functions do nothing in release mode
676 #if wxUSE_LOG && wxUSE_LOG_DEBUG
677 DECLARE_LOG_FUNCTION(Debug);
678
679 // there is no more unconditional LogTrace: it is not different from
680 // LogDebug and it creates overload ambiguities
681 //DECLARE_LOG_FUNCTION(Trace);
682
683 // this version only logs the message if the mask had been added to the
684 // list of masks with AddTraceMask()
685 DECLARE_LOG_FUNCTION2(Trace, const wxString&, mask);
686 #ifdef __WATCOMC__
687 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
688 DECLARE_LOG_FUNCTION2(Trace, const char*, mask);
689 DECLARE_LOG_FUNCTION2(Trace, const wchar_t*, mask);
690 #endif
691
692 // and this one does nothing if all of level bits are not set in
693 // wxLog::GetActive()->GetTraceMask() -- it's deprecated in favour of
694 // string identifiers
695 DECLARE_LOG_FUNCTION2(Trace, wxTraceMask, mask);
696 #ifdef __WATCOMC__
697 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
698 DECLARE_LOG_FUNCTION2(Trace, int, mask);
699 #endif
700 #else //!debug || !wxUSE_LOG
701 // these functions do nothing in release builds, but don't define them as
702 // nothing as it could result in different code structure in debug and
703 // release and this could result in trouble when these macros are used
704 // inside if/else
705 //
706 // note that making wxVLogDebug/Trace() themselves (empty inline) functions
707 // is a bad idea as some compilers are stupid enough to not inline even
708 // empty functions if their parameters are complicated enough, but by
709 // defining them as an empty inline function we ensure that even dumbest
710 // compilers optimise them away
711 inline void wxLogNop() { }
712
713 #define wxVLogDebug(fmt, valist) wxLogNop()
714 #define wxVLogTrace(mask, fmt, valist) wxLogNop()
715
716 #ifdef HAVE_VARIADIC_MACROS
717 // unlike the inline functions below, this completely removes the
718 // wxLogXXX calls from the object file:
719 #define wxLogDebug(fmt, ...) wxLogNop()
720 #define wxLogTrace(mask, fmt, ...) wxLogNop()
721 #else // !HAVE_VARIADIC_MACROS
722 //inline void wxLogDebug(const wxString& fmt, ...) {}
723 WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug, 1, (const wxString&))
724 //inline void wxLogTrace(wxTraceMask, const wxString& fmt, ...) {}
725 //inline void wxLogTrace(const wxString&, const wxString& fmt, ...) {}
726 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (wxTraceMask, const wxString&))
727 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (const wxString&, const wxString&))
728 #ifdef __WATCOMC__
729 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
730 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (const char*, const char*))
731 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (const wchar_t*, const wchar_t*))
732 #endif
733 #endif // HAVE_VARIADIC_MACROS/!HAVE_VARIADIC_MACROS
734 #endif // debug/!debug
735
736 #if defined(__VISUALC__) && __VISUALC__ < 1300
737 #pragma warning(default:4003)
738 #endif
739
740 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
741 // i.e. without using wxMessageBox() for example because it could crash
742 void WXDLLIMPEXP_BASE
743 wxSafeShowMessage(const wxString& title, const wxString& text);
744
745 // ----------------------------------------------------------------------------
746 // debug only logging functions: use them with API name and error code
747 // ----------------------------------------------------------------------------
748
749 #ifdef __WXDEBUG__
750 // make life easier for people using VC++ IDE: clicking on the message
751 // will take us immediately to the place of the failed API
752 #ifdef __VISUALC__
753 #define wxLogApiError(api, rc) \
754 wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
755 __FILE__, __LINE__, api, \
756 (long)rc, wxSysErrorMsg(rc))
757 #else // !VC++
758 #define wxLogApiError(api, rc) \
759 wxLogDebug(wxT("In file %s at line %d: '%s' failed with ") \
760 wxT("error 0x%08lx (%s)."), \
761 __FILE__, __LINE__, api, \
762 (long)rc, wxSysErrorMsg(rc))
763 #endif // VC++/!VC++
764
765 #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
766
767 #else //!debug
768 #define wxLogApiError(api, err) wxLogNop()
769 #define wxLogLastError(api) wxLogNop()
770 #endif //debug/!debug
771
772 // wxCocoa has additiional trace masks
773 #if defined(__WXCOCOA__)
774 #include "wx/cocoa/log.h"
775 #endif
776
777 #ifdef WX_WATCOM_ONLY_CODE
778 #undef WX_WATCOM_ONLY_CODE
779 #endif
780
781 #endif // _WX_LOG_H_
782