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