]> git.saurik.com Git - wxWidgets.git/blob - include/wx/log.h
Add information about the log message generation location to wxLog.
[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 #include "wx/hashmap.h"
58
59 #if wxUSE_THREADS
60 #include "wx/thread.h"
61 #endif // wxUSE_THREADS
62
63 // wxUSE_LOG_DEBUG enables the debug log messages
64 #ifndef wxUSE_LOG_DEBUG
65 #if wxDEBUG_LEVEL
66 #define wxUSE_LOG_DEBUG 1
67 #else // !wxDEBUG_LEVEL
68 #define wxUSE_LOG_DEBUG 0
69 #endif
70 #endif
71
72 // wxUSE_LOG_TRACE enables the trace messages, they are disabled by default
73 #ifndef wxUSE_LOG_TRACE
74 #if wxDEBUG_LEVEL
75 #define wxUSE_LOG_TRACE 1
76 #else // !wxDEBUG_LEVEL
77 #define wxUSE_LOG_TRACE 0
78 #endif
79 #endif // wxUSE_LOG_TRACE
80
81 // ----------------------------------------------------------------------------
82 // forward declarations
83 // ----------------------------------------------------------------------------
84
85 #if wxUSE_GUI
86 class WXDLLIMPEXP_FWD_CORE wxFrame;
87 #endif // wxUSE_GUI
88
89 // ----------------------------------------------------------------------------
90 // constants
91 // ----------------------------------------------------------------------------
92
93 // different standard log levels (you may also define your own)
94 enum wxLogLevelValues
95 {
96 wxLOG_FatalError, // program can't continue, abort immediately
97 wxLOG_Error, // a serious error, user must be informed about it
98 wxLOG_Warning, // user is normally informed about it but may be ignored
99 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
100 wxLOG_Status, // informational: might go to the status line of GUI app
101 wxLOG_Info, // informational message (a.k.a. 'Verbose')
102 wxLOG_Debug, // never shown to the user, disabled in release mode
103 wxLOG_Trace, // trace messages are also only enabled in debug mode
104 wxLOG_Progress, // used for progress indicator (not yet)
105 wxLOG_User = 100, // user defined levels start here
106 wxLOG_Max = 10000
107 };
108
109 // symbolic trace masks - wxLogTrace("foo", "some trace message...") will be
110 // discarded unless the string "foo" has been added to the list of allowed
111 // ones with AddTraceMask()
112
113 #define wxTRACE_MemAlloc wxT("memalloc") // trace memory allocation (new/delete)
114 #define wxTRACE_Messages wxT("messages") // trace window messages/X callbacks
115 #define wxTRACE_ResAlloc wxT("resalloc") // trace GDI resource allocation
116 #define wxTRACE_RefCount wxT("refcount") // trace various ref counting operations
117
118 #ifdef __WXMSW__
119 #define wxTRACE_OleCalls wxT("ole") // OLE interface calls
120 #endif
121
122 #include "wx/iosfwrap.h"
123
124 // ----------------------------------------------------------------------------
125 // information about a log record, i.e. unit of log output
126 // ----------------------------------------------------------------------------
127
128 class wxLogRecordInfo
129 {
130 public:
131 // default ctor creates an uninitialized object
132 wxLogRecordInfo()
133 {
134 memset(this, 0, sizeof(this));
135 }
136
137 // normal ctor, used by wxLogger specifies the location of the log
138 // statement; its time stamp and thread id are set up here
139 wxLogRecordInfo(const char *filename_,
140 int line_,
141 const char *func_)
142 {
143 filename = filename_;
144 func = func_;
145 line = line_;
146
147 timestamp = time(NULL);
148
149 #if wxUSE_THREADS
150 threadId = wxThread::GetCurrentId();
151 #endif // wxUSE_THREADS
152
153 m_data = NULL;
154 }
155
156 // we need to define copy ctor and assignment operator because of m_data
157 wxLogRecordInfo(const wxLogRecordInfo& other)
158 {
159 Copy(other);
160 }
161
162 wxLogRecordInfo& operator=(const wxLogRecordInfo& other)
163 {
164 if ( &other != this )
165 {
166 delete m_data;
167 Copy(other);
168 }
169
170 return *this;
171 }
172
173 // dtor is non-virtual, this class is not meant to be derived from
174 ~wxLogRecordInfo()
175 {
176 delete m_data;
177 }
178
179
180 // the file name and line number of the file where the log record was
181 // generated, if available or NULL and 0 otherwise
182 const char *filename;
183 int line;
184
185 // the name of the function where the log record was generated (may be NULL
186 // if the compiler doesn't support __FUNCTION__)
187 const char *func;
188
189 // time of record generation
190 time_t timestamp;
191
192 #if wxUSE_THREADS
193 // id of the thread which logged this record
194 wxThreadIdType threadId;
195 #endif // wxUSE_THREADS
196
197
198 // store an arbitrary value in this record context
199 //
200 // wxWidgets always uses keys starting with "wx.", e.g. "wx.sys_error"
201 void StoreValue(const wxString& key, wxUIntPtr val)
202 {
203 if ( !m_data )
204 m_data = new ExtraData;
205
206 m_data->numValues[key] = val;
207 }
208
209 void StoreValue(const wxString& key, const wxString& val)
210 {
211 if ( !m_data )
212 m_data = new ExtraData;
213
214 m_data->strValues[key] = val;
215 }
216
217
218 // these functions retrieve the value of either numeric or string key,
219 // return false if not found
220 bool GetNumValue(const wxString& key, wxUIntPtr *val) const
221 {
222 if ( !m_data )
223 return false;
224
225 wxStringToNumHashMap::const_iterator it = m_data->numValues.find(key);
226 if ( it == m_data->numValues.end() )
227 return false;
228
229 *val = it->second;
230
231 return true;
232 }
233
234 bool GetStrValue(const wxString& key, wxString *val) const
235 {
236 if ( !m_data )
237 return false;
238
239 wxStringToStringHashMap::const_iterator it = m_data->strValues.find(key);
240 if ( it == m_data->strValues.end() )
241 return false;
242
243 *val = it->second;
244
245 return true;
246 }
247
248 private:
249 void Copy(const wxLogRecordInfo& other)
250 {
251 memcpy(this, &other, sizeof(wxLogRecordInfo));
252 if ( other.m_data )
253 m_data = new ExtraData(*other.m_data);
254 }
255
256 // extra data associated with the log record: this is completely optional
257 // and can be used to pass information from the log function to the log
258 // sink (e.g. wxLogSysError() uses this to pass the error code)
259 struct ExtraData
260 {
261 wxStringToNumHashMap numValues;
262 wxStringToStringHashMap strValues;
263 };
264
265 // NULL if not used
266 ExtraData *m_data;
267 };
268
269 #define wxLOG_KEY_TRACE_MASK "wx.trace_mask"
270
271 // ----------------------------------------------------------------------------
272 // derive from this class to redirect (or suppress, or ...) log messages
273 // normally, only a single instance of this class exists but it's not enforced
274 // ----------------------------------------------------------------------------
275
276 class WXDLLIMPEXP_BASE wxLog
277 {
278 public:
279 // ctor
280 wxLog() { }
281
282 // make dtor virtual for all derived classes
283 virtual ~wxLog();
284
285
286 // these functions allow to completely disable all log messages
287
288 // is logging enabled at all now?
289 static bool IsEnabled() { return ms_doLog; }
290
291 // is logging at this level enabled?
292 static bool IsLevelEnabled(wxLogLevel level)
293 { return IsEnabled() && level <= ms_logLevel; }
294
295 // change the flag state, return the previous one
296 static bool EnableLogging(bool doIt = true)
297 { bool doLogOld = ms_doLog; ms_doLog = doIt; return doLogOld; }
298
299 // message buffering
300
301 // flush shows all messages if they're not logged immediately (FILE
302 // and iostream logs don't need it, but wxGuiLog does to avoid showing
303 // 17 modal dialogs one after another)
304 virtual void Flush();
305
306 // flush the active target if any
307 static void FlushActive()
308 {
309 if ( !ms_suspendCount )
310 {
311 wxLog *log = GetActiveTarget();
312 if ( log )
313 log->Flush();
314 }
315 }
316
317 // only one sink is active at each moment
318 // get current log target, will call wxApp::CreateLogTarget() to
319 // create one if none exists
320 static wxLog *GetActiveTarget();
321
322 // change log target, pLogger may be NULL
323 static wxLog *SetActiveTarget(wxLog *pLogger);
324
325 // suspend the message flushing of the main target until the next call
326 // to Resume() - this is mainly for internal use (to prevent wxYield()
327 // from flashing the messages)
328 static void Suspend() { ms_suspendCount++; }
329
330 // must be called for each Suspend()!
331 static void Resume() { ms_suspendCount--; }
332
333 // functions controlling the default wxLog behaviour
334 // verbose mode is activated by standard command-line '--verbose'
335 // option
336 static void SetVerbose(bool bVerbose = true) { ms_bVerbose = bVerbose; }
337
338 // Set log level. Log messages with level > logLevel will not be logged.
339 static void SetLogLevel(wxLogLevel logLevel) { ms_logLevel = logLevel; }
340
341 // should GetActiveTarget() try to create a new log object if the
342 // current is NULL?
343 static void DontCreateOnDemand();
344
345 // Make GetActiveTarget() create a new log object again.
346 static void DoCreateOnDemand();
347
348 // log the count of repeating messages instead of logging the messages
349 // multiple times
350 static void SetRepetitionCounting(bool bRepetCounting = true)
351 { ms_bRepetCounting = bRepetCounting; }
352
353 // gets duplicate counting status
354 static bool GetRepetitionCounting() { return ms_bRepetCounting; }
355
356 // add string trace mask
357 static void AddTraceMask(const wxString& str);
358
359 // add string trace mask
360 static void RemoveTraceMask(const wxString& str);
361
362 // remove all string trace masks
363 static void ClearTraceMasks();
364
365 // get string trace masks: note that this is MT-unsafe if other threads can
366 // call AddTraceMask() concurrently
367 static const wxArrayString& GetTraceMasks() { return ms_aTraceMasks; }
368
369 // sets the time stamp string format: this is used as strftime() format
370 // string for the log targets which add time stamps to the messages; set
371 // it to empty string to disable time stamping completely.
372 static void SetTimestamp(const wxString& ts) { ms_timestamp = ts; }
373
374 // disable time stamping of log messages
375 static void DisableTimestamp() { SetTimestamp(wxEmptyString); }
376
377
378 // accessors
379
380 // gets the verbose status
381 static bool GetVerbose() { return ms_bVerbose; }
382
383 // is this trace mask in the list?
384 static bool IsAllowedTraceMask(const wxString& mask);
385
386 // return the current loglevel limit
387 static wxLogLevel GetLogLevel() { return ms_logLevel; }
388
389 // get the current timestamp format string (maybe empty)
390 static const wxString& GetTimestamp() { return ms_timestamp; }
391
392
393
394 // helpers: all functions in this section are mostly for internal use only,
395 // don't call them from your code even if they are not formally deprecated
396
397 // put the time stamp into the string if ms_timestamp != NULL (don't
398 // change it otherwise)
399 static void TimeStamp(wxString *str);
400
401 // these methods should only be called from derived classes DoLogRecord(),
402 // DoLogTextAtLevel() and DoLogText() implementations respectively and
403 // shouldn't be called directly, use logging functions instead
404 void LogRecord(wxLogLevel level,
405 const wxString& msg,
406 const wxLogRecordInfo& info)
407 {
408 DoLogRecord(level, msg, info);
409 }
410
411 void LogTextAtLevel(wxLogLevel level, const wxString& msg)
412 {
413 DoLogTextAtLevel(level, msg);
414 }
415
416 void LogText(const wxString& msg)
417 {
418 DoLogText(msg);
419 }
420
421 // this is a helper used by wxLogXXX() functions, don't call it directly
422 // and see DoLog() for function to overload in the derived classes
423 static void OnLog(wxLogLevel level,
424 const wxString& msg,
425 const wxLogRecordInfo& info);
426
427 // version called when no information about the location of the log record
428 // generation is available (but the time stamp is), it mainly exists for
429 // backwards compatibility, don't use it in new code
430 static void OnLog(wxLogLevel level, const wxString& msg, time_t t);
431
432 // a helper calling the above overload with current time
433 static void OnLog(wxLogLevel level, const wxString& msg)
434 {
435 OnLog(level, msg, time(NULL));
436 }
437
438
439 // this method exists for backwards compatibility only, don't use
440 bool HasPendingMessages() const { return true; }
441
442 #if WXWIN_COMPATIBILITY_2_6
443 // this function doesn't do anything any more, don't call it
444 wxDEPRECATED_INLINE(
445 static wxChar *SetLogBuffer(wxChar *, size_t = 0), return NULL;
446 );
447 #endif // WXWIN_COMPATIBILITY_2_6
448
449 // don't use integer masks any more, use string trace masks instead
450 #if WXWIN_COMPATIBILITY_2_8
451 wxDEPRECATED_INLINE( static void SetTraceMask(wxTraceMask ulMask),
452 ms_ulTraceMask = ulMask; )
453 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE( static wxTraceMask GetTraceMask(),
454 return ms_ulTraceMask; )
455 #endif // WXWIN_COMPATIBILITY_2_8
456
457 protected:
458 // the logging functions that can be overridden: DoLogRecord() is called
459 // for every "record", i.e. a unit of log output, to be logged and by
460 // default formats the message and passes it to DoLogTextAtLevel() which in
461 // turn passes it to DoLogText() by default
462
463 // override this method if you want to change message formatting or do
464 // dynamic filtering
465 virtual void DoLogRecord(wxLogLevel level,
466 const wxString& msg,
467 const wxLogRecordInfo& info);
468
469 // override this method to redirect output to different channels depending
470 // on its level only; if even the level doesn't matter, override
471 // DoLogText() instead
472 virtual void DoLogTextAtLevel(wxLogLevel level, const wxString& msg);
473
474 // this function is not pure virtual as it might not be needed if you do
475 // the logging in overridden DoLogRecord() or DoLogTextAtLevel() directly
476 // but if you do not override them in your derived class you must override
477 // this one as the default implementation of it simply asserts
478 virtual void DoLogText(const wxString& msg);
479
480
481 // the rest of the functions are for backwards compatibility only, don't
482 // use them in new code; if you're updating your existing code you need to
483 // switch to overriding DoLogRecord/Text() above (although as long as these
484 // functions exist, log classes using them will continue to work)
485 #if WXWIN_COMPATIBILITY_2_8
486 wxDEPRECATED_BUT_USED_INTERNALLY(
487 virtual void DoLog(wxLogLevel level, const char *szString, time_t t)
488 );
489
490 wxDEPRECATED_BUT_USED_INTERNALLY(
491 virtual void DoLog(wxLogLevel level, const wchar_t *wzString, time_t t)
492 );
493
494 // these shouldn't be used by new code
495 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
496 virtual void DoLogString(const char *WXUNUSED(szString),
497 time_t WXUNUSED(t)),
498 wxEMPTY_PARAMETER_VALUE
499 )
500
501 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
502 virtual void DoLogString(const wchar_t *WXUNUSED(wzString),
503 time_t WXUNUSED(t)),
504 wxEMPTY_PARAMETER_VALUE
505 )
506 #endif // WXWIN_COMPATIBILITY_2_8
507
508
509 // log a message indicating the number of times the previous message was
510 // repeated if previous repetition counter is strictly positive, does
511 // nothing otherwise; return the old value of repetition counter
512 unsigned LogLastRepeatIfNeeded();
513
514 private:
515 // implement of LogLastRepeatIfNeeded(): it assumes that the
516 // caller had already locked GetPreviousLogCS()
517 unsigned LogLastRepeatIfNeededUnlocked();
518
519 // static variables
520 // ----------------
521
522 // if true, don't log the same message multiple times, only log it once
523 // with the number of times it was repeated
524 static bool ms_bRepetCounting;
525
526 static wxLog *ms_pLogger; // currently active log sink
527 static bool ms_doLog; // false => all logging disabled
528 static bool ms_bAutoCreate; // create new log targets on demand?
529 static bool ms_bVerbose; // false => ignore LogInfo messages
530
531 static wxLogLevel ms_logLevel; // limit logging to levels <= ms_logLevel
532
533 static size_t ms_suspendCount; // if positive, logs are not flushed
534
535 // format string for strftime(), if empty, time stamping log messages is
536 // disabled
537 static wxString ms_timestamp;
538
539 #if WXWIN_COMPATIBILITY_2_8
540 static wxTraceMask ms_ulTraceMask; // controls wxLogTrace behaviour
541 #endif // WXWIN_COMPATIBILITY_2_8
542
543 // currently enabled trace masks
544 static wxArrayString ms_aTraceMasks;
545 };
546
547 // ----------------------------------------------------------------------------
548 // "trivial" derivations of wxLog
549 // ----------------------------------------------------------------------------
550
551 // log everything except for the debug/trace messages (which are passed to
552 // wxMessageOutputDebug) to a buffer
553 class WXDLLIMPEXP_BASE wxLogBuffer : public wxLog
554 {
555 public:
556 wxLogBuffer() { }
557
558 // get the string contents with all messages logged
559 const wxString& GetBuffer() const { return m_str; }
560
561 // show the buffer contents to the user in the best possible way (this uses
562 // wxMessageOutputMessageBox) and clear it
563 virtual void Flush();
564
565 protected:
566 virtual void DoLogTextAtLevel(wxLogLevel level, const wxString& msg);
567
568 private:
569 wxString m_str;
570
571 wxDECLARE_NO_COPY_CLASS(wxLogBuffer);
572 };
573
574
575 // log everything to a "FILE *", stderr by default
576 class WXDLLIMPEXP_BASE wxLogStderr : public wxLog
577 {
578 public:
579 // redirect log output to a FILE
580 wxLogStderr(FILE *fp = NULL);
581
582 protected:
583 // implement sink function
584 virtual void DoLogText(const wxString& msg);
585
586 FILE *m_fp;
587
588 wxDECLARE_NO_COPY_CLASS(wxLogStderr);
589 };
590
591 #if wxUSE_STD_IOSTREAM
592
593 // log everything to an "ostream", cerr by default
594 class WXDLLIMPEXP_BASE wxLogStream : public wxLog
595 {
596 public:
597 // redirect log output to an ostream
598 wxLogStream(wxSTD ostream *ostr = (wxSTD ostream *) NULL);
599
600 protected:
601 // implement sink function
602 virtual void DoLogText(const wxString& msg);
603
604 // using ptr here to avoid including <iostream.h> from this file
605 wxSTD ostream *m_ostr;
606 };
607
608 #endif // wxUSE_STD_IOSTREAM
609
610 // ----------------------------------------------------------------------------
611 // /dev/null log target: suppress logging until this object goes out of scope
612 // ----------------------------------------------------------------------------
613
614 // example of usage:
615 /*
616 void Foo()
617 {
618 wxFile file;
619
620 // wxFile.Open() normally complains if file can't be opened, we don't
621 // want it
622 wxLogNull logNo;
623
624 if ( !file.Open("bar") )
625 ... process error ourselves ...
626
627 // ~wxLogNull called, old log sink restored
628 }
629 */
630 class WXDLLIMPEXP_BASE wxLogNull
631 {
632 public:
633 wxLogNull() : m_flagOld(wxLog::EnableLogging(false)) { }
634 ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld); }
635
636 private:
637 bool m_flagOld; // the previous value of the wxLog::ms_doLog
638 };
639
640 // ----------------------------------------------------------------------------
641 // chaining log target: installs itself as a log target and passes all
642 // messages to the real log target given to it in the ctor but also forwards
643 // them to the previously active one
644 //
645 // note that you don't have to call SetActiveTarget() with this class, it
646 // does it itself in its ctor
647 // ----------------------------------------------------------------------------
648
649 class WXDLLIMPEXP_BASE wxLogChain : public wxLog
650 {
651 public:
652 wxLogChain(wxLog *logger);
653 virtual ~wxLogChain();
654
655 // change the new log target
656 void SetLog(wxLog *logger);
657
658 // this can be used to temporarily disable (and then reenable) passing
659 // messages to the old logger (by default we do pass them)
660 void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; }
661
662 // are we passing the messages to the previous log target?
663 bool IsPassingMessages() const { return m_bPassMessages; }
664
665 // return the previous log target (may be NULL)
666 wxLog *GetOldLog() const { return m_logOld; }
667
668 // override base class version to flush the old logger as well
669 virtual void Flush();
670
671 // call to avoid destroying the old log target
672 void DetachOldLog() { m_logOld = NULL; }
673
674 protected:
675 // pass the record to the old logger if needed
676 virtual void DoLogRecord(wxLogLevel level,
677 const wxString& msg,
678 const wxLogRecordInfo& info);
679
680 private:
681 // the current log target
682 wxLog *m_logNew;
683
684 // the previous log target
685 wxLog *m_logOld;
686
687 // do we pass the messages to the old logger?
688 bool m_bPassMessages;
689
690 wxDECLARE_NO_COPY_CLASS(wxLogChain);
691 };
692
693 // a chain log target which uses itself as the new logger
694
695 #define wxLogPassThrough wxLogInterposer
696
697 class WXDLLIMPEXP_BASE wxLogInterposer : public wxLogChain
698 {
699 public:
700 wxLogInterposer();
701
702 private:
703 wxDECLARE_NO_COPY_CLASS(wxLogInterposer);
704 };
705
706 // a temporary interposer which doesn't destroy the old log target
707 // (calls DetachOldLog)
708
709 class WXDLLIMPEXP_BASE wxLogInterposerTemp : public wxLogChain
710 {
711 public:
712 wxLogInterposerTemp();
713
714 private:
715 wxDECLARE_NO_COPY_CLASS(wxLogInterposerTemp);
716 };
717
718 #if wxUSE_GUI
719 // include GUI log targets:
720 #include "wx/generic/logg.h"
721 #endif // wxUSE_GUI
722
723 // ----------------------------------------------------------------------------
724 // wxLogger
725 // ----------------------------------------------------------------------------
726
727 // wxLogger is a helper class used by wxLogXXX() functions implementation,
728 // don't use it directly as it's experimental and subject to change (OTOH it
729 // might become public in the future if it's deemed to be useful enough)
730
731 // contains information about the context from which a log message originates
732 // and provides Log() vararg method which forwards to wxLog::OnLog() and passes
733 // this context to it
734 class wxLogger
735 {
736 public:
737 // ctor takes the basic information about the log record
738 wxLogger(wxLogLevel level,
739 const char *filename,
740 int line,
741 const char *func)
742 : m_level(level),
743 m_info(filename, line, func)
744 {
745 }
746
747 // store extra data in our log record and return this object itself (so
748 // that further calls to its functions could be chained)
749 template <typename T>
750 wxLogger& Store(const wxString& key, T val)
751 {
752 m_info.StoreValue(key, val);
753 return *this;
754 }
755
756 // hack for "overloaded" wxLogXXX() functions: calling this method
757 // indicates that we may have an extra first argument preceding the format
758 // string and that if we do have it, we should store it in m_info using the
759 // given key (while by default 0 value will be used)
760 wxLogger& MaybeStore(const wxString& key)
761 {
762 wxASSERT_MSG( m_optKey.empty(), "can only have one optional value" );
763 m_optKey = key;
764
765 m_info.StoreValue(key, 0);
766 return *this;
767 }
768
769
770 // non-vararg function used by wxVLogXXX():
771
772 // log the message at the level specified in the ctor if this log message
773 // is enabled
774 void LogV(const wxString& format, va_list argptr)
775 {
776 // remember that fatal errors can't be disabled
777 if ( m_level == wxLOG_FatalError || wxLog::IsLevelEnabled(m_level) )
778 DoCallOnLog(format, argptr);
779 }
780
781 // overloads used by functions with optional leading arguments (whose
782 // values are stored in the key passed to MaybeStore())
783 void LogV(long num, const wxString& format, va_list argptr)
784 {
785 Store(m_optKey, num);
786
787 LogV(format, argptr);
788 }
789
790 void LogV(void *ptr, const wxString& format, va_list argptr)
791 {
792 Store(m_optKey, wxPtrToUInt(ptr));
793
794 LogV(format, argptr);
795 }
796
797
798 // vararg functions used by wxLogXXX():
799
800 // will log the message at the level specified in the ctor
801 //
802 // notice that this function supposes that the caller already checked that
803 // the level was enabled and does no checks itself
804 WX_DEFINE_VARARG_FUNC_VOID
805 (
806 Log,
807 1, (const wxFormatString&),
808 DoLog, DoLogUtf8
809 )
810
811 // same as Log() but with an extra numeric or pointer parameters: this is
812 // used to pass an optional value by storing it in m_info under the name
813 // passed to MaybeStore() and is required to support "overloaded" versions
814 // of wxLogStatus() and wxLogSysError()
815 WX_DEFINE_VARARG_FUNC_VOID
816 (
817 Log,
818 2, (long, const wxFormatString&),
819 DoLogWithNum, DoLogWithNumUtf8
820 )
821
822 WX_DEFINE_VARARG_FUNC_VOID
823 (
824 Log,
825 2, (void *, const wxFormatString&),
826 DoLogWithPtr, DoLogWithPtrUtf8
827 )
828
829 // log the message at the level specified as its first argument
830 //
831 // as the macros don't have access to the level argument in this case, this
832 // function does check that the level is enabled itself
833 WX_DEFINE_VARARG_FUNC_VOID
834 (
835 LogAtLevel,
836 2, (wxLogLevel, const wxFormatString&),
837 DoLogAtLevel, DoLogAtLevelUtf8
838 )
839
840 // special versions for wxLogTrace() which is passed either string or
841 // integer (TODO) mask as first argument determining whether the message
842 // should be logged or not
843 WX_DEFINE_VARARG_FUNC_VOID
844 (
845 LogTrace,
846 2, (const wxString&, const wxFormatString&),
847 DoLogTrace, DoLogTraceUtf8
848 )
849
850 #ifdef __WATCOMC__
851 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
852 WX_VARARG_WATCOM_WORKAROUND(void, Log,
853 1, (const wxString&),
854 (wxFormatString(f1)))
855 WX_VARARG_WATCOM_WORKAROUND(void, Log,
856 1, (const wxCStrData&),
857 (wxFormatString(f1)))
858 WX_VARARG_WATCOM_WORKAROUND(void, Log,
859 1, (const char*),
860 (wxFormatString(f1)))
861 WX_VARARG_WATCOM_WORKAROUND(void, Log,
862 1, (const wchar_t*),
863 (wxFormatString(f1)))
864
865 WX_VARARG_WATCOM_WORKAROUND(void, Log,
866 2, (long, const wxString&),
867 (f1, wxFormatString(f2)))
868 WX_VARARG_WATCOM_WORKAROUND(void, Log,
869 2, (long, const wxCStrData&),
870 (f1, wxFormatString(f2)))
871 WX_VARARG_WATCOM_WORKAROUND(void, Log,
872 2, (long, const char *),
873 (f1, wxFormatString(f2)))
874 WX_VARARG_WATCOM_WORKAROUND(void, Log,
875 2, (long, const wchar_t *),
876 (f1, wxFormatString(f2)))
877
878 WX_VARARG_WATCOM_WORKAROUND(void, Log,
879 2, (void *, const wxString&),
880 (f1, wxFormatString(f2)))
881 WX_VARARG_WATCOM_WORKAROUND(void, Log,
882 2, (void *, const wxCStrData&),
883 (f1, wxFormatString(f2)))
884 WX_VARARG_WATCOM_WORKAROUND(void, Log,
885 2, (void *, const char *),
886 (f1, wxFormatString(f2)))
887 WX_VARARG_WATCOM_WORKAROUND(void, Log,
888 2, (void *, const wchar_t *),
889 (f1, wxFormatString(f2)))
890
891 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel,
892 2, (wxLogLevel, const wxString&),
893 (f1, wxFormatString(f2)))
894 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel,
895 2, (wxLogLevel, const wxCStrData&),
896 (f1, wxFormatString(f2)))
897 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel,
898 2, (wxLogLevel, const char *),
899 (f1, wxFormatString(f2)))
900 WX_VARARG_WATCOM_WORKAROUND(void, LogAtLevel,
901 2, (wxLogLevel, const wchar_t *),
902 (f1, wxFormatString(f2)))
903
904 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace,
905 2, (const wxString&, const wxString&),
906 (f1, wxFormatString(f2)))
907 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace,
908 2, (const wxString&, const wxCStrData&),
909 (f1, wxFormatString(f2)))
910 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace,
911 2, (const wxString&, const char *),
912 (f1, wxFormatString(f2)))
913 WX_VARARG_WATCOM_WORKAROUND(void, LogTrace,
914 2, (const wxString&, const wchar_t *),
915 (f1, wxFormatString(f2)))
916 #endif // __WATCOMC__
917
918 private:
919 #if !wxUSE_UTF8_LOCALE_ONLY
920 void DoLog(const wxChar *format, ...)
921 {
922 va_list argptr;
923 va_start(argptr, format);
924 DoCallOnLog(format, argptr);
925 va_end(argptr);
926 }
927
928 void DoLogWithNum(long num, const wxChar *format, ...)
929 {
930 Store(m_optKey, num);
931
932 va_list argptr;
933 va_start(argptr, format);
934 DoCallOnLog(format, argptr);
935 va_end(argptr);
936 }
937
938 void DoLogWithPtr(void *ptr, const wxChar *format, ...)
939 {
940 Store(m_optKey, wxPtrToUInt(ptr));
941
942 va_list argptr;
943 va_start(argptr, format);
944 DoCallOnLog(format, argptr);
945 va_end(argptr);
946 }
947
948 void DoLogAtLevel(wxLogLevel level, const wxChar *format, ...)
949 {
950 if ( !wxLog::IsLevelEnabled(level) )
951 return;
952
953 va_list argptr;
954 va_start(argptr, format);
955 DoCallOnLog(level, format, argptr);
956 va_end(argptr);
957 }
958
959 void DoLogTrace(const wxString& mask, const wxChar *format, ...)
960 {
961 if ( !wxLog::IsAllowedTraceMask(mask) )
962 return;
963
964 Store(wxLOG_KEY_TRACE_MASK, mask);
965
966 va_list argptr;
967 va_start(argptr, format);
968 DoCallOnLog(format, argptr);
969 va_end(argptr);
970 }
971 #endif // !wxUSE_UTF8_LOCALE_ONLY
972
973 #if wxUSE_UNICODE_UTF8
974 void DoLogUtf8(const char *format, ...)
975 {
976 va_list argptr;
977 va_start(argptr, format);
978 DoCallOnLog(format, argptr);
979 va_end(argptr);
980 }
981
982 void DoLogWithNumUtf8(long num, const char *format, ...)
983 {
984 Store(m_optKey, num);
985
986 va_list argptr;
987 va_start(argptr, format);
988 DoCallOnLog(format, argptr);
989 va_end(argptr);
990 }
991
992 void DoLogWithPtrUtf8(void *ptr, const char *format, ...)
993 {
994 Store(m_optKey, wxPtrToUInt(ptr));
995
996 va_list argptr;
997 va_start(argptr, format);
998 DoCallOnLog(format, argptr);
999 va_end(argptr);
1000 }
1001
1002 void DoLogAtLevelUtf8(wxLogLevel level, const char *format, ...)
1003 {
1004 if ( !wxLog::IsLevelEnabled(level) )
1005 return;
1006
1007 va_list argptr;
1008 va_start(argptr, format);
1009 DoCallOnLog(level, format, argptr);
1010 va_end(argptr);
1011 }
1012
1013 void DoLogTraceUtf8(const wxString& mask, const char *format, ...)
1014 {
1015 if ( !wxLog::IsAllowedTraceMask(mask) )
1016 return;
1017
1018 Store(wxLOG_KEY_TRACE_MASK, mask);
1019
1020 va_list argptr;
1021 va_start(argptr, format);
1022 DoCallOnLog(format, argptr);
1023 va_end(argptr);
1024 }
1025 #endif // wxUSE_UNICODE_UTF8
1026
1027 void DoCallOnLog(wxLogLevel level, const wxString& format, va_list argptr)
1028 {
1029 wxLog::OnLog(level, wxString::FormatV(format, argptr), m_info);
1030 }
1031
1032 void DoCallOnLog(const wxString& format, va_list argptr)
1033 {
1034 wxLog::OnLog(m_level, wxString::FormatV(format, argptr), m_info);
1035 }
1036
1037
1038 const wxLogLevel m_level;
1039 wxLogRecordInfo m_info;
1040
1041 wxString m_optKey;
1042
1043 wxDECLARE_NO_COPY_CLASS(wxLogger);
1044 };
1045
1046 // ============================================================================
1047 // global functions
1048 // ============================================================================
1049
1050 // ----------------------------------------------------------------------------
1051 // get error code/error message from system in a portable way
1052 // ----------------------------------------------------------------------------
1053
1054 // return the last system error code
1055 WXDLLIMPEXP_BASE unsigned long wxSysErrorCode();
1056
1057 // return the error message for given (or last if 0) error code
1058 WXDLLIMPEXP_BASE const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0);
1059
1060 // ----------------------------------------------------------------------------
1061 // define wxLog<level>() functions which can be used by application instead of
1062 // stdio, iostream &c for log messages for easy redirection
1063 // ----------------------------------------------------------------------------
1064
1065 /*
1066 The code below is unreadable because it (unfortunately unavoidably)
1067 contains a lot of macro magic but all it does is to define wxLogXXX() such
1068 that you can call them as vararg functions to log a message at the
1069 corresponding level.
1070
1071 More precisely, it defines:
1072
1073 - wxLog{FatalError,Error,Warning,Message,Verbose,Debug}() functions
1074 taking the format string and additional vararg arguments if needed.
1075 - wxLogGeneric(wxLogLevel level, const wxString& format, ...) which
1076 takes the log level explicitly.
1077 - wxLogSysError(const wxString& format, ...) and wxLogSysError(long
1078 err, const wxString& format, ...) which log a wxLOG_Error severity
1079 message with the error message corresponding to the system error code
1080 err or the last error.
1081 - wxLogStatus(const wxString& format, ...) which logs the message into
1082 the status bar of the main application window and its overload
1083 wxLogStatus(wxFrame *frame, const wxString& format, ...) which logs it
1084 into the status bar of the specified frame.
1085 - wxLogTrace(Mask mask, const wxString& format, ...) which only logs
1086 the message is the specified mask is enabled. This comes in two kinds:
1087 Mask can be a wxString or a long. Both are deprecated.
1088
1089 In addition, wxVLogXXX() versions of all the functions above are also
1090 defined. They take a va_list argument instead of "...".
1091 */
1092
1093 // creates wxLogger object for the current location
1094 #define wxMAKE_LOGGER(level) \
1095 wxLogger(wxLOG_##level, __FILE__, __LINE__, __WXFUNCTION__)
1096
1097 // this macro generates the expression which logs whatever follows it in
1098 // parentheses at the level specified as argument
1099 #define wxDO_LOG(level) wxMAKE_LOGGER(level).Log
1100
1101 // this is the non-vararg equivalent
1102 #define wxDO_LOGV(level, format, argptr) \
1103 wxMAKE_LOGGER(level).LogV(format, argptr)
1104
1105 // this macro declares wxLog<level>() macro which logs whatever follows it if
1106 // logging at specified level is enabled (notice that if it is false, the
1107 // following arguments are not even evaluated which is good as it avoids
1108 // unnecessary overhead)
1109 //
1110 // Note: the strange if/else construct is needed to make the following code
1111 //
1112 // if ( cond )
1113 // wxLogError("!!!");
1114 // else
1115 // ...
1116 //
1117 // work as expected, without it the second "else" would match the "if"
1118 // inside wxLogError(). Unfortunately code like
1119 //
1120 // if ( cond )
1121 // wxLogError("!!!");
1122 //
1123 // now provokes "suggest explicit braces to avoid ambiguous 'else'"
1124 // warnings from g++ 4.3 and later with -Wparentheses on but they can be
1125 // easily fixed by adding curly braces around wxLogError() and at least
1126 // the code still does do the right thing.
1127 #define wxDO_LOG_IF_ENABLED(level) \
1128 if ( !wxLog::IsLevelEnabled(wxLOG_##level) ) \
1129 {} \
1130 else \
1131 wxDO_LOG(level)
1132
1133 // wxLogFatalError() is special as it can't be disabled
1134 #define wxLogFatalError wxDO_LOG(FatalError)
1135 #define wxVLogFatalError(format, argptr) wxDO_LOGV(FatalError, format, argptr)
1136
1137 #define wxLogError wxDO_LOG_IF_ENABLED(Error)
1138 #define wxVLogError(format, argptr) wxDO_LOGV(Error, format, argptr)
1139
1140 #define wxLogWarning wxDO_LOG_IF_ENABLED(Warning)
1141 #define wxVLogWarning(format, argptr) wxDO_LOGV(Warning, format, argptr)
1142
1143 #define wxLogMessage wxDO_LOG_IF_ENABLED(Message)
1144 #define wxVLogMessage(format, argptr) wxDO_LOGV(Message, format, argptr)
1145
1146 // this one is special as it only logs if we're in verbose mode
1147 #define wxLogVerbose \
1148 if ( !(wxLog::IsLevelEnabled(wxLOG_Info) && wxLog::GetVerbose()) ) \
1149 {} \
1150 else \
1151 wxDO_LOG(Info)
1152 #define wxVLogVerbose(format, argptr) \
1153 if ( !(wxLog::IsLevelEnabled(wxLOG_Info) && wxLog::GetVerbose()) ) \
1154 {} \
1155 else \
1156 wxDO_LOGV(Info, format, argptr)
1157
1158 // deprecated synonyms for wxLogVerbose() and wxVLogVerbose()
1159 #define wxLogInfo wxLogVerbose
1160 #define wxVLogInfo wxVLogVerbose
1161
1162
1163 // another special case: the level is passed as first argument of the function
1164 // and so is not available to the macro
1165 //
1166 // notice that because of this, arguments of wxLogGeneric() are currently
1167 // always evaluated, unlike for the other log functions
1168 #define wxLogGeneric wxMAKE_LOGGER(Max).LogAtLevel
1169 #define wxVLogGeneric(level, format, argptr) \
1170 if ( !wxLog::IsLevelEnabled(wxLOG_##level) ) \
1171 {} \
1172 else \
1173 wxDO_LOGV(level, format, argptr)
1174
1175
1176 // wxLogSysError() needs to stash the error code value in the log record info
1177 // so it needs special handling too; additional complications arise because the
1178 // error code may or not be present as the first argument
1179 #define wxLOG_KEY_SYS_ERROR_CODE "wx.sys_error"
1180
1181 #define wxLogSysError \
1182 if ( !wxLog::IsLevelEnabled(wxLOG_Error) ) \
1183 {} \
1184 else \
1185 wxMAKE_LOGGER(Error).MaybeStore(wxLOG_KEY_SYS_ERROR_CODE).Log
1186
1187 // unfortunately we can't have overloaded macros so we can't define versions
1188 // both with and without error code argument and have to rely on LogV()
1189 // overloads in wxLogger to select between them
1190 #define wxVLogSysError \
1191 wxMAKE_LOGGER(Error).MaybeStore(wxLOG_KEY_SYS_ERROR_CODE).LogV
1192
1193 #if wxUSE_GUI
1194 // wxLogStatus() is similar to wxLogSysError() as it allows to optionally
1195 // specify the frame to which the message should go
1196 #define wxLOG_KEY_FRAME "wx.frame"
1197
1198 #define wxLogStatus \
1199 if ( !wxLog::IsLevelEnabled(wxLOG_Status) ) \
1200 {} \
1201 else \
1202 wxMAKE_LOGGER(Status).MaybeStore(wxLOG_KEY_FRAME).Log
1203
1204 #define wxVLogStatus(format, argptr) \
1205 wxMAKE_LOGGER(Status).MaybeStore(wxLOG_KEY_FRAME).LogV
1206 #endif // wxUSE_GUI
1207
1208
1209 #else // !wxUSE_LOG
1210
1211 #undef wxUSE_LOG_DEBUG
1212 #define wxUSE_LOG_DEBUG 0
1213
1214 #undef wxUSE_LOG_TRACE
1215 #define wxUSE_LOG_TRACE 0
1216
1217 #if defined(__WATCOMC__) || defined(__MINGW32__)
1218 // Mingw has similar problem with wxLogSysError:
1219 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x ) x
1220 #else
1221 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x )
1222 #endif
1223
1224 // define macros for defining log functions which do nothing at all
1225 //
1226 // WX_WATCOM_ONLY_CODE is needed to work around
1227 // http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1228 #define wxDEFINE_EMPTY_LOG_FUNCTION(level) \
1229 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxString&)) \
1230 WX_WATCOM_ONLY_CODE( \
1231 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const char*)) \
1232 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wchar_t*)) \
1233 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxCStrData&)) \
1234 ) \
1235 inline void wxVLog##level(const wxString& WXUNUSED(format), \
1236 va_list WXUNUSED(argptr)) { } \
1237
1238 #define wxDEFINE_EMPTY_LOG_FUNCTION2(level, argclass) \
1239 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxString&)) \
1240 WX_WATCOM_OR_MINGW_ONLY_CODE( \
1241 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const char*)) \
1242 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wchar_t*)) \
1243 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxCStrData&)) \
1244 ) \
1245 inline void wxVLog##level(argclass WXUNUSED(arg), \
1246 const wxString& WXUNUSED(format), \
1247 va_list WXUNUSED(argptr)) {}
1248
1249 wxDEFINE_EMPTY_LOG_FUNCTION(FatalError);
1250 wxDEFINE_EMPTY_LOG_FUNCTION(Error);
1251 wxDEFINE_EMPTY_LOG_FUNCTION(SysError);
1252 wxDEFINE_EMPTY_LOG_FUNCTION2(SysError, long);
1253 wxDEFINE_EMPTY_LOG_FUNCTION(Warning);
1254 wxDEFINE_EMPTY_LOG_FUNCTION(Message);
1255 wxDEFINE_EMPTY_LOG_FUNCTION(Info);
1256 wxDEFINE_EMPTY_LOG_FUNCTION(Verbose);
1257
1258 wxDEFINE_EMPTY_LOG_FUNCTION2(Generic, wxLogLevel);
1259
1260 #if wxUSE_GUI
1261 wxDEFINE_EMPTY_LOG_FUNCTION(Status);
1262 wxDEFINE_EMPTY_LOG_FUNCTION2(Status, wxFrame *);
1263 #endif // wxUSE_GUI
1264
1265 // Empty Class to fake wxLogNull
1266 class WXDLLIMPEXP_BASE wxLogNull
1267 {
1268 public:
1269 wxLogNull() { }
1270 };
1271
1272 // Dummy macros to replace some functions.
1273 #define wxSysErrorCode() (unsigned long)0
1274 #define wxSysErrorMsg( X ) (const wxChar*)NULL
1275
1276 // Fake symbolic trace masks... for those that are used frequently
1277 #define wxTRACE_OleCalls wxEmptyString // OLE interface calls
1278
1279 #endif // wxUSE_LOG/!wxUSE_LOG
1280
1281
1282 // debug functions can be completely disabled in optimized builds
1283
1284 // if these log functions are disabled, we prefer to define them as (empty)
1285 // variadic macros as this completely removes them and their argument
1286 // evaluation from the object code but if this is not supported by compiler we
1287 // use empty inline functions instead (defining them as nothing would result in
1288 // compiler warnings)
1289 //
1290 // note that making wxVLogDebug/Trace() themselves (empty inline) functions is
1291 // a bad idea as some compilers are stupid enough to not inline even empty
1292 // functions if their parameters are complicated enough, but by defining them
1293 // as an empty inline function we ensure that even dumbest compilers optimise
1294 // them away
1295 #ifdef __BORLANDC__
1296 // but Borland gives "W8019: Code has no effect" for wxLogNop() so we need
1297 // to define it differently for it to avoid these warnings (same problem as
1298 // with wxUnusedVar())
1299 #define wxLogNop() { }
1300 #else
1301 inline void wxLogNop() { }
1302 #endif
1303
1304 #if wxUSE_LOG_DEBUG
1305 #define wxLogDebug wxDO_LOG_IF_ENABLED(Debug)
1306 #define wxVLogDebug(format, argptr) wxDO_LOGV(Debug, format, argptr)
1307 #else // !wxUSE_LOG_DEBUG
1308 #define wxVLogDebug(fmt, valist) wxLogNop()
1309
1310 #ifdef HAVE_VARIADIC_MACROS
1311 #define wxLogDebug(fmt, ...) wxLogNop()
1312 #else // !HAVE_VARIADIC_MACROS
1313 WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug, 1, (const wxString&))
1314 #endif
1315 #endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
1316
1317 #if wxUSE_LOG_TRACE
1318 #define wxLogTrace \
1319 if ( !wxLog::IsLevelEnabled(wxLOG_Trace) ) \
1320 {} \
1321 else \
1322 wxMAKE_LOGGER(Trace).LogTrace
1323 #else // !wxUSE_LOG_TRACE
1324 #define wxVLogTrace(mask, fmt, valist) wxLogNop()
1325
1326 #ifdef HAVE_VARIADIC_MACROS
1327 #define wxLogTrace(mask, fmt, ...) wxLogNop()
1328 #else // !HAVE_VARIADIC_MACROS
1329 #if WXWIN_COMPATIBILITY_2_8
1330 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (wxTraceMask, const wxString&))
1331 #endif
1332 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (const wxString&, const wxString&))
1333 #ifdef __WATCOMC__
1334 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1335 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (const char*, const char*))
1336 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (const wchar_t*, const wchar_t*))
1337 #endif
1338 #endif // HAVE_VARIADIC_MACROS/!HAVE_VARIADIC_MACROS
1339 #endif // wxUSE_LOG_TRACE/!wxUSE_LOG_TRACE
1340
1341 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
1342 // i.e. without using wxMessageBox() for example because it could crash
1343 void WXDLLIMPEXP_BASE
1344 wxSafeShowMessage(const wxString& title, const wxString& text);
1345
1346 // ----------------------------------------------------------------------------
1347 // debug only logging functions: use them with API name and error code
1348 // ----------------------------------------------------------------------------
1349
1350 #if wxUSE_LOG_DEBUG
1351 // make life easier for people using VC++ IDE: clicking on the message
1352 // will take us immediately to the place of the failed API
1353 #ifdef __VISUALC__
1354 #define wxLogApiError(api, rc) \
1355 wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
1356 __FILE__, __LINE__, api, \
1357 (long)rc, wxSysErrorMsg(rc))
1358 #else // !VC++
1359 #define wxLogApiError(api, rc) \
1360 wxLogDebug(wxT("In file %s at line %d: '%s' failed with ") \
1361 wxT("error 0x%08lx (%s)."), \
1362 __FILE__, __LINE__, api, \
1363 (long)rc, wxSysErrorMsg(rc))
1364 #endif // VC++/!VC++
1365
1366 #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
1367
1368 #else // !wxUSE_LOG_DEBUG
1369 #define wxLogApiError(api, err) wxLogNop()
1370 #define wxLogLastError(api) wxLogNop()
1371 #endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
1372
1373 // wxCocoa has additiional trace masks
1374 #if defined(__WXCOCOA__)
1375 #include "wx/cocoa/log.h"
1376 #endif
1377
1378 #ifdef WX_WATCOM_ONLY_CODE
1379 #undef WX_WATCOM_ONLY_CODE
1380 #endif
1381
1382 #endif // _WX_LOG_H_
1383