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