]> git.saurik.com Git - wxWidgets.git/blame - include/wx/log.h
adapting to autorelease of factory methods
[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
0b4f47a3
DS
17// ----------------------------------------------------------------------------
18// common constants for use in wxUSE_LOG/!wxUSE_LOG
19// ----------------------------------------------------------------------------
20
21// the trace masks have been superceded by symbolic trace constants, they're
22// for compatibility only andwill be removed soon - do NOT use them
23
24// meaning of different bits of the trace mask (which allows selectively
25// enable/disable some trace messages)
26#define wxTraceMemAlloc 0x0001 // trace memory allocation (new/delete)
27#define wxTraceMessages 0x0002 // trace window messages/X callbacks
28#define wxTraceResAlloc 0x0004 // trace GDI resource allocation
29#define wxTraceRefCount 0x0008 // trace various ref counting operations
30
31#ifdef __WXMSW__
32 #define wxTraceOleCalls 0x0100 // OLE interface calls
33#endif
34
546db2a8
VZ
35// ----------------------------------------------------------------------------
36// types
37// ----------------------------------------------------------------------------
38
1782be31 39// NB: these types are needed even if wxUSE_LOG == 0
546db2a8
VZ
40typedef unsigned long wxTraceMask;
41typedef unsigned long wxLogLevel;
42
43// ----------------------------------------------------------------------------
44// headers
45// ----------------------------------------------------------------------------
46
b6e4e44a 47#include "wx/string.h"
c9f78968 48#include "wx/strvararg.h"
b6e4e44a 49
1782be31
VZ
50#if wxUSE_LOG
51
1782be31
VZ
52#include "wx/arrstr.h"
53
9b4da627 54#ifndef __WXPALMOS5__
0e0126c2 55#ifndef __WXWINCE__
1782be31 56 #include <time.h> // for time_t
0e0126c2 57#endif
9b4da627 58#endif // ! __WXPALMOS5__
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
f96233d5 201 static void AddTraceMask(const wxString& str);
d1b20379
DS
202
203 // add string trace mask
d6b9496a 204 static void RemoveTraceMask(const wxString& str);
d1b20379
DS
205
206 // remove all string trace masks
36bd6902 207 static void ClearTraceMasks();
d1b20379 208
f96233d5
VZ
209 // get string trace masks: note that this is MT-unsafe if other threads can
210 // call AddTraceMask() concurrently
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
efce878a
VZ
246 // this method should only be called from derived classes DoLog()
247 // implementations and shouldn't be called directly, use logging functions
248 // instead
249 void Log(wxLogLevel level, const wxString& msg, time_t t)
250 {
251 DoLog(level, msg, t);
252 }
253
d6b9496a 254 // make dtor virtual for all derived classes
f9837791 255 virtual ~wxLog();
c801d85f 256
c801d85f 257
1ec5cbf3 258 // this method exists for backwards compatibility only, don't use
d1b20379 259 bool HasPendingMessages() const { return true; }
1ec5cbf3 260
2e7f3845
VZ
261#if WXWIN_COMPATIBILITY_2_6
262 // this function doesn't do anything any more, don't call it
263 wxDEPRECATED( static wxChar *SetLogBuffer(wxChar *buf, size_t size = 0) );
264#endif
265
1ec5cbf3 266protected:
efce878a 267 // the logging functions that can be overridden
d1b20379
DS
268
269 // default DoLog() prepends the time stamp and a prefix corresponding
270 // to the message to szString and then passes it to DoLogString()
5a20d2ce
VS
271 virtual void DoLog(wxLogLevel level, const wxString& szString, time_t t);
272#if WXWIN_COMPATIBILITY_2_8
273 // these shouldn't be used by new code
5d88a6b5
VZ
274 wxDEPRECATED_BUT_USED_INTERNALLY(
275 virtual void DoLog(wxLogLevel level, const char *szString, time_t t)
276 );
277
278 wxDEPRECATED_BUT_USED_INTERNALLY(
279 virtual void DoLog(wxLogLevel level, const wchar_t *wzString, time_t t)
280 );
281#endif // WXWIN_COMPATIBILITY_2_8
5a20d2ce
VS
282
283 void LogString(const wxString& szString, time_t t)
284 { DoLogString(szString, t); }
d1b20379
DS
285
286 // default DoLogString does nothing but is not pure virtual because if
287 // you override DoLog() you might not need it at all
5a20d2ce
VS
288 virtual void DoLogString(const wxString& szString, time_t t);
289#if WXWIN_COMPATIBILITY_2_8
290 // these shouldn't be used by new code
291 virtual void DoLogString(const char *WXUNUSED(szString),
292 time_t WXUNUSED(t)) {}
293 virtual void DoLogString(const wchar_t *WXUNUSED(szString),
294 time_t WXUNUSED(t)) {}
b99891b0
VZ
295#endif // WXWIN_COMPATIBILITY_2_8
296
297 // this macro should be used in the derived classes to avoid warnings about
298 // hiding the other DoLog() overloads when overriding DoLog(wxString) --
299 // but don't use it with MSVC which doesn't give this warning but does give
300 // warning when a deprecated function is overridden
301#if WXWIN_COMPATIBILITY_2_8 && !defined(__VISUALC__)
302 #define wxSUPPRESS_DOLOG_HIDE_WARNING() \
303 virtual void DoLog(wxLogLevel, const char *, time_t) { } \
304 virtual void DoLog(wxLogLevel, const wchar_t *, time_t) { }
305
306 #define wxSUPPRESS_DOLOGSTRING_HIDE_WARNING() \
307 virtual void DoLogString(const char *, time_t) { } \
308 virtual void DoLogString(const wchar_t *, time_t) { }
309#else
310 #define wxSUPPRESS_DOLOG_HIDE_WARNING()
311 #define wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
5a20d2ce 312#endif
c801d85f 313
2064113c 314 // log a message indicating the number of times the previous message was
0250efd6
VZ
315 // repeated if ms_prevCounter > 0, does nothing otherwise; return the old
316 // value of ms_prevCounter
dbaa16de 317 unsigned LogLastRepeatIfNeeded();
f9837791 318
d6b9496a 319private:
dbaa16de
VZ
320 // implement of LogLastRepeatIfNeeded(): it assumes that the
321 // caller had already locked ms_prevCS
322 unsigned LogLastRepeatIfNeededUnlocked();
323
d6b9496a
VZ
324 // static variables
325 // ----------------
06db8ebd 326
2064113c
VZ
327 // if true, don't log the same message multiple times, only log it once
328 // with the number of times it was repeated
f9837791 329 static bool ms_bRepetCounting;
2064113c 330
f9837791 331 static wxString ms_prevString; // previous message that was logged
2064113c 332 static unsigned ms_prevCounter; // how many times it was repeated
f9837791
VZ
333 static time_t ms_prevTimeStamp;// timestamp of the previous message
334 static wxLogLevel ms_prevLevel; // level of the previous message
335
d6b9496a 336 static wxLog *ms_pLogger; // currently active log sink
d1b20379 337 static bool ms_doLog; // false => all logging disabled
d6b9496a 338 static bool ms_bAutoCreate; // create new log targets on demand?
d1b20379 339 static bool ms_bVerbose; // false => ignore LogInfo messages
fe7b1156 340
edc73852
RD
341 static wxLogLevel ms_logLevel; // limit logging to levels <= ms_logLevel
342
2ed3265e
VZ
343 static size_t ms_suspendCount; // if positive, logs are not flushed
344
d2e1ef19
VZ
345 // format string for strftime(), if NULL, time stamping log messages is
346 // disabled
d993e05b 347 static wxString ms_timestamp;
d2e1ef19 348
d6b9496a
VZ
349 static wxTraceMask ms_ulTraceMask; // controls wxLogTrace behaviour
350 static wxArrayString ms_aTraceMasks; // more powerful filter for wxLogTrace
c801d85f
KB
351};
352
353// ----------------------------------------------------------------------------
354// "trivial" derivations of wxLog
355// ----------------------------------------------------------------------------
356
d3fc1755
VZ
357// log everything to a buffer
358class WXDLLIMPEXP_BASE wxLogBuffer : public wxLog
359{
360public:
361 wxLogBuffer() { }
362
363 // get the string contents with all messages logged
364 const wxString& GetBuffer() const { return m_str; }
365
366 // show the buffer contents to the user in the best possible way (this uses
367 // wxMessageOutputMessageBox) and clear it
368 virtual void Flush();
369
370protected:
5a20d2ce
VS
371 virtual void DoLog(wxLogLevel level, const wxString& szString, time_t t);
372 virtual void DoLogString(const wxString& szString, time_t t);
d3fc1755 373
b99891b0
VZ
374 wxSUPPRESS_DOLOG_HIDE_WARNING()
375 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
376
d3fc1755
VZ
377private:
378 wxString m_str;
379
c0c133e1 380 wxDECLARE_NO_COPY_CLASS(wxLogBuffer);
d3fc1755
VZ
381};
382
0f8218d7 383
c801d85f 384// log everything to a "FILE *", stderr by default
bddd7a8d 385class WXDLLIMPEXP_BASE wxLogStderr : public wxLog
c801d85f
KB
386{
387public:
d6b9496a 388 // redirect log output to a FILE
d3b9f782 389 wxLogStderr(FILE *fp = NULL);
c801d85f 390
03147cd0 391protected:
d6b9496a 392 // implement sink function
5a20d2ce 393 virtual void DoLogString(const wxString& szString, time_t t);
c801d85f 394
b99891b0
VZ
395 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
396
d6b9496a 397 FILE *m_fp;
d3fc1755 398
c0c133e1 399 wxDECLARE_NO_COPY_CLASS(wxLogStderr);
c801d85f
KB
400};
401
4bf78aae 402#if wxUSE_STD_IOSTREAM
03147cd0 403
c801d85f 404// log everything to an "ostream", cerr by default
bddd7a8d 405class WXDLLIMPEXP_BASE wxLogStream : public wxLog
c801d85f
KB
406{
407public:
d6b9496a 408 // redirect log output to an ostream
dd107c50 409 wxLogStream(wxSTD ostream *ostr = (wxSTD ostream *) NULL);
c801d85f
KB
410
411protected:
d6b9496a 412 // implement sink function
5a20d2ce 413 virtual void DoLogString(const wxString& szString, time_t t);
c801d85f 414
b99891b0
VZ
415 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
416
d6b9496a 417 // using ptr here to avoid including <iostream.h> from this file
dd107c50 418 wxSTD ostream *m_ostr;
c801d85f 419};
03147cd0
VZ
420
421#endif // wxUSE_STD_IOSTREAM
c801d85f 422
03147cd0
VZ
423// ----------------------------------------------------------------------------
424// /dev/null log target: suppress logging until this object goes out of scope
425// ----------------------------------------------------------------------------
426
427// example of usage:
428/*
429 void Foo()
430 {
431 wxFile file;
432
433 // wxFile.Open() normally complains if file can't be opened, we don't
434 // want it
435 wxLogNull logNo;
436
437 if ( !file.Open("bar") )
438 ... process error ourselves ...
439
440 // ~wxLogNull called, old log sink restored
441 }
442 */
bddd7a8d 443class WXDLLIMPEXP_BASE wxLogNull
03147cd0
VZ
444{
445public:
d1b20379 446 wxLogNull() : m_flagOld(wxLog::EnableLogging(false)) { }
be52b341 447 ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld); }
03147cd0
VZ
448
449private:
450 bool m_flagOld; // the previous value of the wxLog::ms_doLog
451};
452
453// ----------------------------------------------------------------------------
454// chaining log target: installs itself as a log target and passes all
455// messages to the real log target given to it in the ctor but also forwards
456// them to the previously active one
457//
458// note that you don't have to call SetActiveTarget() with this class, it
459// does it itself in its ctor
460// ----------------------------------------------------------------------------
461
bddd7a8d 462class WXDLLIMPEXP_BASE wxLogChain : public wxLog
03147cd0
VZ
463{
464public:
465 wxLogChain(wxLog *logger);
8b30a4e4 466 virtual ~wxLogChain();
03147cd0
VZ
467
468 // change the new log target
469 void SetLog(wxLog *logger);
470
471 // this can be used to temporarily disable (and then reenable) passing
472 // messages to the old logger (by default we do pass them)
473 void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; }
474
475 // are we passing the messages to the previous log target?
476 bool IsPassingMessages() const { return m_bPassMessages; }
477
478 // return the previous log target (may be NULL)
479 wxLog *GetOldLog() const { return m_logOld; }
480
481 // override base class version to flush the old logger as well
482 virtual void Flush();
483
47fe7ff3
JS
484 // call to avoid destroying the old log target
485 void DetachOldLog() { m_logOld = NULL; }
486
03147cd0
VZ
487protected:
488 // pass the chain to the old logger if needed
5a20d2ce 489 virtual void DoLog(wxLogLevel level, const wxString& szString, time_t t);
03147cd0 490
b99891b0
VZ
491 wxSUPPRESS_DOLOG_HIDE_WARNING()
492
03147cd0
VZ
493private:
494 // the current log target
495 wxLog *m_logNew;
496
497 // the previous log target
498 wxLog *m_logOld;
499
500 // do we pass the messages to the old logger?
501 bool m_bPassMessages;
22f3361e 502
c0c133e1 503 wxDECLARE_NO_COPY_CLASS(wxLogChain);
03147cd0
VZ
504};
505
506// a chain log target which uses itself as the new logger
47fe7ff3
JS
507
508#define wxLogPassThrough wxLogInterposer
509
510class WXDLLIMPEXP_BASE wxLogInterposer : public wxLogChain
511{
512public:
513 wxLogInterposer();
514
515private:
c0c133e1 516 wxDECLARE_NO_COPY_CLASS(wxLogInterposer);
47fe7ff3
JS
517};
518
519// a temporary interposer which doesn't destroy the old log target
520// (calls DetachOldLog)
521
522class WXDLLIMPEXP_BASE wxLogInterposerTemp : public wxLogChain
03147cd0
VZ
523{
524public:
47fe7ff3 525 wxLogInterposerTemp();
fc7a2a60
VZ
526
527private:
c0c133e1 528 wxDECLARE_NO_COPY_CLASS(wxLogInterposerTemp);
03147cd0
VZ
529};
530
8ca28fb7 531#if wxUSE_GUI
7e8c564c
VS
532 // include GUI log targets:
533 #include "wx/generic/logg.h"
e90c1d2a 534#endif // wxUSE_GUI
03f38c58 535
c801d85f
KB
536// ============================================================================
537// global functions
538// ============================================================================
539
540// ----------------------------------------------------------------------------
541// Log functions should be used by application instead of stdio, iostream &c
542// for log messages for easy redirection
543// ----------------------------------------------------------------------------
544
88ac883a
VZ
545// ----------------------------------------------------------------------------
546// get error code/error message from system in a portable way
547// ----------------------------------------------------------------------------
548
549// return the last system error code
bddd7a8d 550WXDLLIMPEXP_BASE unsigned long wxSysErrorCode();
c11d62a6 551
88ac883a 552// return the error message for given (or last if 0) error code
bddd7a8d 553WXDLLIMPEXP_BASE const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0);
88ac883a 554
c11d62a6 555// ----------------------------------------------------------------------------
c801d85f 556// define wxLog<level>
c11d62a6 557// ----------------------------------------------------------------------------
c801d85f 558
2523e9b7 559#define DECLARE_LOG_FUNCTION(level) \
81727065 560 extern void WXDLLIMPEXP_BASE \
d1f6e2cf
VS
561 wxDoLog##level##Wchar(const wxChar *format, ...); \
562 extern void WXDLLIMPEXP_BASE \
563 wxDoLog##level##Utf8(const char *format, ...); \
2523e9b7 564 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
1528e0b8 565 1, (const wxFormatString&), \
d1f6e2cf 566 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
2523e9b7
VS
567 DECLARE_LOG_FUNCTION_WATCOM(level) \
568 extern void WXDLLIMPEXP_BASE wxVLog##level(const wxString& format, \
569 va_list argptr)
570
571#ifdef __WATCOMC__
572 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
573 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
574 // something too big for Borland C++ to handle
575 #define DECLARE_LOG_FUNCTION_WATCOM(level) \
59a14f69
VS
576 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
577 1, (const wxString&), \
578 (wxFormatString(f1))) \
579 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
580 1, (const wxCStrData&), \
581 (wxFormatString(f1))) \
582 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
d1f6e2cf 583 1, (const char*), \
59a14f69
VS
584 (wxFormatString(f1))) \
585 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
d1f6e2cf 586 1, (const wchar_t*), \
59a14f69 587 (wxFormatString(f1)))
2523e9b7
VS
588#else
589 #define DECLARE_LOG_FUNCTION_WATCOM(level)
590#endif
591
c9f78968 592
2523e9b7 593#define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
d1f6e2cf
VS
594 extern void expdecl wxDoLog##level##Wchar(argclass arg, \
595 const wxChar *format, ...); \
596 extern void expdecl wxDoLog##level##Utf8(argclass arg, \
597 const char *format, ...); \
2523e9b7 598 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, \
1528e0b8 599 2, (argclass, const wxFormatString&), \
d1f6e2cf 600 wxDoLog##level##Wchar, wxDoLog##level##Utf8) \
2523e9b7 601 DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
c9f78968 602 extern void expdecl wxVLog##level(argclass arg, \
81727065 603 const wxString& format, \
2523e9b7
VS
604 va_list argptr)
605
606#ifdef __WATCOMC__
607 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351;
608 // can't use WX_WATCOM_ONLY_CODE here because the macro would expand to
609 // something too big for Borland C++ to handle
610 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl) \
59a14f69
VS
611 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
612 2, (argclass, const wxString&), \
613 (f1, wxFormatString(f2))) \
614 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
615 2, (argclass, const wxCStrData&), \
616 (f1, wxFormatString(f2))) \
617 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
2523e9b7 618 2, (argclass, const char*), \
59a14f69
VS
619 (f1, wxFormatString(f2))) \
620 WX_VARARG_WATCOM_WORKAROUND(void, wxLog##level, \
2523e9b7 621 2, (argclass, const wchar_t*), \
59a14f69 622 (f1, wxFormatString(f2)))
2523e9b7
VS
623#else
624 #define DECLARE_LOG_FUNCTION2_EXP_WATCOM(level, argclass, arg, expdecl)
625#endif
626
c9f78968 627
88ac883a
VZ
628#else // !wxUSE_LOG
629
82e77a80
VS
630#ifdef __WATCOMC__
631 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
632 #define WX_WATCOM_ONLY_CODE( x ) x
633#else
634 #define WX_WATCOM_ONLY_CODE( x )
635#endif
636
99fda03a
VS
637#if defined(__WATCOMC__) || defined(__MINGW32__)
638 // Mingw has similar problem with wxLogSysError:
639 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x ) x
640#else
641 #define WX_WATCOM_OR_MINGW_ONLY_CODE( x )
642#endif
643
88ac883a 644// log functions do nothing at all
2523e9b7
VS
645#define DECLARE_LOG_FUNCTION(level) \
646 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxString&)) \
647 WX_WATCOM_ONLY_CODE( \
648 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const char*)) \
649 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wchar_t*)) \
650 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxCStrData&)) \
651 ) \
81727065 652 inline void wxVLog##level(const wxString& WXUNUSED(format), \
59a14f69 653 va_list WXUNUSED(argptr)) { } \
c9f78968 654
2523e9b7
VS
655#define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
656 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxString&)) \
99fda03a 657 WX_WATCOM_OR_MINGW_ONLY_CODE( \
2523e9b7
VS
658 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const char*)) \
659 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wchar_t*)) \
660 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxCStrData&)) \
661 ) \
c9f78968 662 inline void wxVLog##level(argclass WXUNUSED(arg), \
59a14f69
VS
663 const wxString& WXUNUSED(format), \
664 va_list WXUNUSED(argptr)) {}
2523e9b7 665
e30285ab 666// Empty Class to fake wxLogNull
bddd7a8d 667class WXDLLIMPEXP_BASE wxLogNull
e30285ab
VZ
668{
669public:
886dd7d2 670 wxLogNull() { }
e30285ab
VZ
671};
672
673// Dummy macros to replace some functions.
674#define wxSysErrorCode() (unsigned long)0
675#define wxSysErrorMsg( X ) (const wxChar*)NULL
676
677// Fake symbolic trace masks... for those that are used frequently
fda7962d 678#define wxTRACE_OleCalls wxEmptyString // OLE interface calls
e30285ab 679
88ac883a 680#endif // wxUSE_LOG/!wxUSE_LOG
bdeb1f0d 681
33936026
WS
682#define DECLARE_LOG_FUNCTION2(level, argclass, arg) \
683 DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, WXDLLIMPEXP_BASE)
0b4f47a3 684
463c2e5b 685// VC6 produces a warning if we a macro expanding to nothing to
2523e9b7 686// DECLARE_LOG_FUNCTION2:
463c2e5b 687#if defined(__VISUALC__) && __VISUALC__ < 1300
2523e9b7 688 // "not enough actual parameters for macro 'DECLARE_LOG_FUNCTION2_EXP'"
463c2e5b
VS
689 #pragma warning(disable:4003)
690#endif
c801d85f 691
88ac883a 692// a generic function for all levels (level is passes as parameter)
33936026 693DECLARE_LOG_FUNCTION2(Generic, wxLogLevel, level);
c801d85f 694
88ac883a
VZ
695// one function per each level
696DECLARE_LOG_FUNCTION(FatalError);
697DECLARE_LOG_FUNCTION(Error);
698DECLARE_LOG_FUNCTION(Warning);
699DECLARE_LOG_FUNCTION(Message);
700DECLARE_LOG_FUNCTION(Info);
701DECLARE_LOG_FUNCTION(Verbose);
470b7da3 702
88ac883a
VZ
703// this function sends the log message to the status line of the top level
704// application frame, if any
2523e9b7 705DECLARE_LOG_FUNCTION(Status);
470b7da3 706
886dd7d2
VZ
707#if wxUSE_GUI
708 // this one is the same as previous except that it allows to explicitly
b5dbe15d 709 class WXDLLIMPEXP_FWD_CORE wxFrame;
886dd7d2 710 // specify the frame to which the output should go
2523e9b7 711 DECLARE_LOG_FUNCTION2_EXP(Status, wxFrame *, pFrame, WXDLLIMPEXP_CORE);
886dd7d2 712#endif // wxUSE_GUI
c801d85f 713
88ac883a
VZ
714// additional one: as wxLogError, but also logs last system call error code
715// and the corresponding error message if available
2523e9b7 716DECLARE_LOG_FUNCTION(SysError);
c801d85f 717
88ac883a
VZ
718// and another one which also takes the error code (for those broken APIs
719// that don't set the errno (like registry APIs in Win32))
2523e9b7
VS
720DECLARE_LOG_FUNCTION2(SysError, long, lErrCode);
721#ifdef __WATCOMC__
722// workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
723DECLARE_LOG_FUNCTION2(SysError, unsigned long, lErrCode);
724#endif
88ac883a
VZ
725
726// debug functions do nothing in release mode
bdeb1f0d 727#if wxUSE_LOG && wxUSE_LOG_DEBUG
d6b9496a
VZ
728 DECLARE_LOG_FUNCTION(Debug);
729
b103e4f3
VZ
730 // there is no more unconditional LogTrace: it is not different from
731 // LogDebug and it creates overload ambiguities
732 //DECLARE_LOG_FUNCTION(Trace);
d6b9496a 733
b103e4f3
VZ
734 // this version only logs the message if the mask had been added to the
735 // list of masks with AddTraceMask()
2523e9b7
VS
736 DECLARE_LOG_FUNCTION2(Trace, const wxString&, mask);
737#ifdef __WATCOMC__
738 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
739 DECLARE_LOG_FUNCTION2(Trace, const char*, mask);
740 DECLARE_LOG_FUNCTION2(Trace, const wchar_t*, mask);
741#endif
742
b103e4f3
VZ
743 // and this one does nothing if all of level bits are not set in
744 // wxLog::GetActive()->GetTraceMask() -- it's deprecated in favour of
d6b9496a 745 // string identifiers
2523e9b7
VS
746 DECLARE_LOG_FUNCTION2(Trace, wxTraceMask, mask);
747#ifdef __WATCOMC__
748 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
749 DECLARE_LOG_FUNCTION2(Trace, int, mask);
750#endif
bdeb1f0d 751#else //!debug || !wxUSE_LOG
388a1f66
VZ
752 // these functions do nothing in release builds, but don't define them as
753 // nothing as it could result in different code structure in debug and
754 // release and this could result in trouble when these macros are used
755 // inside if/else
756 //
757 // note that making wxVLogDebug/Trace() themselves (empty inline) functions
758 // is a bad idea as some compilers are stupid enough to not inline even
759 // empty functions if their parameters are complicated enough, but by
760 // defining them as an empty inline function we ensure that even dumbest
761 // compilers optimise them away
dd639a4f
VZ
762#ifdef __BORLANDC__
763 // but Borland gives "W8019: Code has no effect" for wxLogNop() so we need
764 // to define it differently for it to avoid these warnings (same problem as
765 // with wxUnusedVar())
766 #define wxLogNop() { }
767#else
388a1f66 768 inline void wxLogNop() { }
dd639a4f 769#endif
388a1f66
VZ
770
771 #define wxVLogDebug(fmt, valist) wxLogNop()
772 #define wxVLogTrace(mask, fmt, valist) wxLogNop()
ca766534
VS
773
774 #ifdef HAVE_VARIADIC_MACROS
388a1f66
VZ
775 // unlike the inline functions below, this completely removes the
776 // wxLogXXX calls from the object file:
777 #define wxLogDebug(fmt, ...) wxLogNop()
778 #define wxLogTrace(mask, fmt, ...) wxLogNop()
ca766534 779 #else // !HAVE_VARIADIC_MACROS
c9f78968 780 //inline void wxLogDebug(const wxString& fmt, ...) {}
44be939a 781 WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug, 1, (const wxString&))
c9f78968
VS
782 //inline void wxLogTrace(wxTraceMask, const wxString& fmt, ...) {}
783 //inline void wxLogTrace(const wxString&, const wxString& fmt, ...) {}
44be939a
VS
784 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (wxTraceMask, const wxString&))
785 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (const wxString&, const wxString&))
786 #ifdef __WATCOMC__
787 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
788 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (const char*, const char*))
789 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (const wchar_t*, const wchar_t*))
790 #endif
ca766534 791 #endif // HAVE_VARIADIC_MACROS/!HAVE_VARIADIC_MACROS
88ac883a 792#endif // debug/!debug
c801d85f 793
463c2e5b
VS
794#if defined(__VISUALC__) && __VISUALC__ < 1300
795 #pragma warning(default:4003)
796#endif
797
c11d62a6
VZ
798// wxLogFatalError helper: show the (fatal) error to the user in a safe way,
799// i.e. without using wxMessageBox() for example because it could crash
bddd7a8d 800void WXDLLIMPEXP_BASE
886dd7d2 801wxSafeShowMessage(const wxString& title, const wxString& text);
c11d62a6 802
88ac883a
VZ
803// ----------------------------------------------------------------------------
804// debug only logging functions: use them with API name and error code
805// ----------------------------------------------------------------------------
c801d85f 806
e90babdf 807#ifdef __WXDEBUG__
42e69d6b
VZ
808 // make life easier for people using VC++ IDE: clicking on the message
809 // will take us immediately to the place of the failed API
810#ifdef __VISUALC__
4b7f2165
VZ
811 #define wxLogApiError(api, rc) \
812 wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
0accd1cf 813 __FILE__, __LINE__, api, \
8b94d999 814 (long)rc, wxSysErrorMsg(rc))
42e69d6b 815#else // !VC++
4b7f2165 816 #define wxLogApiError(api, rc) \
18da7cf2
VZ
817 wxLogDebug(wxT("In file %s at line %d: '%s' failed with ") \
818 wxT("error 0x%08lx (%s)."), \
0accd1cf 819 __FILE__, __LINE__, api, \
8b94d999 820 (long)rc, wxSysErrorMsg(rc))
42e69d6b
VZ
821#endif // VC++/!VC++
822
823 #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
824
c801d85f 825#else //!debug
388a1f66
VZ
826 #define wxLogApiError(api, err) wxLogNop()
827 #define wxLogLastError(api) wxLogNop()
c801d85f
KB
828#endif //debug/!debug
829
a619fa3f
DE
830// wxCocoa has additiional trace masks
831#if defined(__WXCOCOA__)
832#include "wx/cocoa/log.h"
833#endif
834
82e77a80
VS
835#ifdef WX_WATCOM_ONLY_CODE
836 #undef WX_WATCOM_ONLY_CODE
837#endif
838
34138703 839#endif // _WX_LOG_H_
04662def 840