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