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