]> git.saurik.com Git - wxWidgets.git/blame - include/wx/log.h
moved vararg handling code in wxMessageOutput to single method and added simple Outpu...
[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
0e0126c2 54#ifndef __WXWINCE__
1782be31 55 #include <time.h> // for time_t
0e0126c2 56#endif
c30aaf75
VZ
57
58#include "wx/dynarray.h"
d6b9496a 59
edc73852
RD
60#ifndef wxUSE_LOG_DEBUG
61# ifdef __WXDEBUG__
62# define wxUSE_LOG_DEBUG 1
63# else // !__WXDEBUG__
64# define wxUSE_LOG_DEBUG 0
65# endif
66#endif
67
1782be31
VZ
68// ----------------------------------------------------------------------------
69// forward declarations
70// ----------------------------------------------------------------------------
71
72#if wxUSE_GUI
73 class WXDLLIMPEXP_CORE wxTextCtrl;
74 class WXDLLIMPEXP_CORE wxLogFrame;
75 class WXDLLIMPEXP_CORE wxFrame;
55c9a186 76 class WXDLLIMPEXP_CORE wxWindow;
1782be31
VZ
77#endif // wxUSE_GUI
78
9ef3052c
VZ
79// ----------------------------------------------------------------------------
80// constants
81// ----------------------------------------------------------------------------
82
83// different standard log levels (you may also define your own)
90adbcca 84enum wxLogLevelValues
9ef3052c 85{
d6b9496a
VZ
86 wxLOG_FatalError, // program can't continue, abort immediately
87 wxLOG_Error, // a serious error, user must be informed about it
88 wxLOG_Warning, // user is normally informed about it but may be ignored
89 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
d6b9496a 90 wxLOG_Status, // informational: might go to the status line of GUI app
edc73852 91 wxLOG_Info, // informational message (a.k.a. 'Verbose')
d6b9496a
VZ
92 wxLOG_Debug, // never shown to the user, disabled in release mode
93 wxLOG_Trace, // trace messages are also only enabled in debug mode
94 wxLOG_Progress, // used for progress indicator (not yet)
edc73852 95 wxLOG_User = 100, // user defined levels start here
65ca8c0b 96 wxLOG_Max = 10000
9ef3052c
VZ
97};
98
d6b9496a
VZ
99// symbolic trace masks - wxLogTrace("foo", "some trace message...") will be
100// discarded unless the string "foo" has been added to the list of allowed
101// ones with AddTraceMask()
102
08298395
OK
103#define wxTRACE_MemAlloc wxT("memalloc") // trace memory allocation (new/delete)
104#define wxTRACE_Messages wxT("messages") // trace window messages/X callbacks
105#define wxTRACE_ResAlloc wxT("resalloc") // trace GDI resource allocation
106#define wxTRACE_RefCount wxT("refcount") // trace various ref counting operations
d6b9496a
VZ
107
108#ifdef __WXMSW__
08298395 109 #define wxTRACE_OleCalls wxT("ole") // OLE interface calls
d6b9496a
VZ
110#endif
111
65f19af1 112#include "wx/iosfwrap.h"
470b7da3 113
c801d85f
KB
114// ----------------------------------------------------------------------------
115// derive from this class to redirect (or suppress, or ...) log messages
116// normally, only a single instance of this class exists but it's not enforced
c801d85f 117// ----------------------------------------------------------------------------
d6b9496a 118
bddd7a8d 119class WXDLLIMPEXP_BASE wxLog
c801d85f
KB
120{
121public:
d6b9496a 122 // ctor
6fb99eb3 123 wxLog(){}
d6b9496a
VZ
124
125 // these functions allow to completely disable all log messages
d1b20379
DS
126
127 // is logging disabled now?
d6b9496a 128 static bool IsEnabled() { return ms_doLog; }
d1b20379
DS
129
130 // change the flag state, return the previous one
131 static bool EnableLogging(bool doIt = true)
2e7f3845 132 { bool doLogOld = ms_doLog; ms_doLog = doIt; return doLogOld; }
d6b9496a
VZ
133
134 // static sink function - see DoLog() for function to overload in the
135 // derived classes
f9837791 136 static void OnLog(wxLogLevel level, const wxChar *szString, time_t t);
d6b9496a
VZ
137
138 // message buffering
d1b20379
DS
139
140 // flush shows all messages if they're not logged immediately (FILE
141 // and iostream logs don't need it, but wxGuiLog does to avoid showing
142 // 17 modal dialogs one after another)
d6b9496a 143 virtual void Flush();
d6b9496a 144
d1b20379 145 // flush the active target if any
bbfa0322
VZ
146 static void FlushActive()
147 {
2ed3265e
VZ
148 if ( !ms_suspendCount )
149 {
150 wxLog *log = GetActiveTarget();
1ec5cbf3 151 if ( log )
2ed3265e
VZ
152 log->Flush();
153 }
bbfa0322 154 }
1ec5cbf3
VZ
155
156 // only one sink is active at each moment
d1b20379
DS
157 // get current log target, will call wxApp::CreateLogTarget() to
158 // create one if none exists
d6b9496a 159 static wxLog *GetActiveTarget();
d1b20379
DS
160
161 // change log target, pLogger may be NULL
d6b9496a
VZ
162 static wxLog *SetActiveTarget(wxLog *pLogger);
163
d1b20379
DS
164 // suspend the message flushing of the main target until the next call
165 // to Resume() - this is mainly for internal use (to prevent wxYield()
166 // from flashing the messages)
2ed3265e 167 static void Suspend() { ms_suspendCount++; }
d1b20379
DS
168
169 // must be called for each Suspend()!
2ed3265e
VZ
170 static void Resume() { ms_suspendCount--; }
171
d6b9496a 172 // functions controlling the default wxLog behaviour
d1b20379
DS
173 // verbose mode is activated by standard command-line '-verbose'
174 // option
175 static void SetVerbose(bool bVerbose = true) { ms_bVerbose = bVerbose; }
edc73852 176
d1b20379 177 // Set log level. Log messages with level > logLevel will not be logged.
edc73852
RD
178 static void SetLogLevel(wxLogLevel logLevel) { ms_logLevel = logLevel; }
179
d1b20379
DS
180 // should GetActiveTarget() try to create a new log object if the
181 // current is NULL?
36bd6902 182 static void DontCreateOnDemand();
d6b9496a 183
f9837791
VZ
184 // log the count of repeating messages instead of logging the messages
185 // multiple times
186 static void SetRepetitionCounting(bool bRepetCounting = true)
2e7f3845 187 { ms_bRepetCounting = bRepetCounting; }
f9837791
VZ
188
189 // gets duplicate counting status
190 static bool GetRepetitionCounting() { return ms_bRepetCounting; }
191
d1b20379 192 // trace mask (see wxTraceXXX constants for details)
d6b9496a 193 static void SetTraceMask(wxTraceMask ulMask) { ms_ulTraceMask = ulMask; }
d1b20379
DS
194
195 // add string trace mask
df5168c4 196 static void AddTraceMask(const wxString& str)
2e7f3845 197 { ms_aTraceMasks.push_back(str); }
d1b20379
DS
198
199 // add string trace mask
d6b9496a 200 static void RemoveTraceMask(const wxString& str);
d1b20379
DS
201
202 // remove all string trace masks
36bd6902 203 static void ClearTraceMasks();
d1b20379
DS
204
205 // get string trace masks
0e080be6 206 static const wxArrayString &GetTraceMasks() { return ms_aTraceMasks; }
d6b9496a 207
d1b20379
DS
208 // sets the timestamp string: this is used as strftime() format string
209 // for the log targets which add time stamps to the messages - set it
210 // to NULL to disable time stamping completely.
d2e1ef19
VZ
211 static void SetTimestamp(const wxChar *ts) { ms_timestamp = ts; }
212
edc73852 213
d6b9496a 214 // accessors
d1b20379
DS
215
216 // gets the verbose status
fd7718b2 217 static bool GetVerbose() { return ms_bVerbose; }
d1b20379
DS
218
219 // get trace mask
d6b9496a 220 static wxTraceMask GetTraceMask() { return ms_ulTraceMask; }
d1b20379
DS
221
222 // is this trace mask in the list?
df5168c4 223 static bool IsAllowedTraceMask(const wxChar *mask);
d1b20379
DS
224
225 // return the current loglevel limit
edc73852 226 static wxLogLevel GetLogLevel() { return ms_logLevel; }
d6b9496a 227
d1b20379 228 // get the current timestamp format string (may be NULL)
d2e1ef19
VZ
229 static const wxChar *GetTimestamp() { return ms_timestamp; }
230
edc73852 231
d2e1ef19 232 // helpers
d1b20379
DS
233
234 // put the time stamp into the string if ms_timestamp != NULL (don't
235 // change it otherwise)
d2e1ef19
VZ
236 static void TimeStamp(wxString *str);
237
d6b9496a 238 // make dtor virtual for all derived classes
f9837791 239 virtual ~wxLog();
c801d85f 240
c801d85f 241
1ec5cbf3 242 // this method exists for backwards compatibility only, don't use
d1b20379 243 bool HasPendingMessages() const { return true; }
1ec5cbf3 244
2e7f3845
VZ
245#if WXWIN_COMPATIBILITY_2_6
246 // this function doesn't do anything any more, don't call it
247 wxDEPRECATED( static wxChar *SetLogBuffer(wxChar *buf, size_t size = 0) );
248#endif
249
1ec5cbf3 250protected:
d6b9496a 251 // the logging functions that can be overriden
d1b20379
DS
252
253 // default DoLog() prepends the time stamp and a prefix corresponding
254 // to the message to szString and then passes it to DoLogString()
9e3d3318 255 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t);
d1b20379
DS
256
257 // default DoLogString does nothing but is not pure virtual because if
258 // you override DoLog() you might not need it at all
9e3d3318 259 virtual void DoLogString(const wxChar *szString, time_t t);
c801d85f 260
f9837791
VZ
261 // log a line containing the number of times the previous message was
262 // repeated
263 // returns: the number
264 static unsigned DoLogNumberOfRepeats();
265
d6b9496a
VZ
266private:
267 // static variables
268 // ----------------
06db8ebd 269
f9837791
VZ
270 // traditional behaviour or counting repetitions
271 static bool ms_bRepetCounting;
272 static wxString ms_prevString; // previous message that was logged
273 // how many times the previous message was logged
274 static unsigned ms_prevCounter;
275 static time_t ms_prevTimeStamp;// timestamp of the previous message
276 static wxLogLevel ms_prevLevel; // level of the previous message
277
d6b9496a 278 static wxLog *ms_pLogger; // currently active log sink
d1b20379 279 static bool ms_doLog; // false => all logging disabled
d6b9496a 280 static bool ms_bAutoCreate; // create new log targets on demand?
d1b20379 281 static bool ms_bVerbose; // false => ignore LogInfo messages
fe7b1156 282
edc73852
RD
283 static wxLogLevel ms_logLevel; // limit logging to levels <= ms_logLevel
284
2ed3265e
VZ
285 static size_t ms_suspendCount; // if positive, logs are not flushed
286
d2e1ef19
VZ
287 // format string for strftime(), if NULL, time stamping log messages is
288 // disabled
289 static const wxChar *ms_timestamp;
290
d6b9496a
VZ
291 static wxTraceMask ms_ulTraceMask; // controls wxLogTrace behaviour
292 static wxArrayString ms_aTraceMasks; // more powerful filter for wxLogTrace
c801d85f
KB
293};
294
295// ----------------------------------------------------------------------------
296// "trivial" derivations of wxLog
297// ----------------------------------------------------------------------------
298
d3fc1755
VZ
299// log everything to a buffer
300class WXDLLIMPEXP_BASE wxLogBuffer : public wxLog
301{
302public:
303 wxLogBuffer() { }
304
305 // get the string contents with all messages logged
306 const wxString& GetBuffer() const { return m_str; }
307
308 // show the buffer contents to the user in the best possible way (this uses
309 // wxMessageOutputMessageBox) and clear it
310 virtual void Flush();
311
312protected:
83250f1a 313 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t);
d3fc1755
VZ
314 virtual void DoLogString(const wxChar *szString, time_t t);
315
316private:
317 wxString m_str;
318
319 DECLARE_NO_COPY_CLASS(wxLogBuffer)
320};
321
0f8218d7 322
c801d85f 323// log everything to a "FILE *", stderr by default
bddd7a8d 324class WXDLLIMPEXP_BASE wxLogStderr : public wxLog
c801d85f
KB
325{
326public:
d6b9496a
VZ
327 // redirect log output to a FILE
328 wxLogStderr(FILE *fp = (FILE *) NULL);
c801d85f 329
03147cd0 330protected:
d6b9496a 331 // implement sink function
9e3d3318 332 virtual void DoLogString(const wxChar *szString, time_t t);
c801d85f 333
d6b9496a 334 FILE *m_fp;
d3fc1755
VZ
335
336 DECLARE_NO_COPY_CLASS(wxLogStderr)
c801d85f
KB
337};
338
4bf78aae 339#if wxUSE_STD_IOSTREAM
03147cd0 340
c801d85f 341// log everything to an "ostream", cerr by default
bddd7a8d 342class WXDLLIMPEXP_BASE wxLogStream : public wxLog
c801d85f
KB
343{
344public:
d6b9496a 345 // redirect log output to an ostream
dd107c50 346 wxLogStream(wxSTD ostream *ostr = (wxSTD ostream *) NULL);
c801d85f
KB
347
348protected:
d6b9496a 349 // implement sink function
9e3d3318 350 virtual void DoLogString(const wxChar *szString, time_t t);
c801d85f 351
d6b9496a 352 // using ptr here to avoid including <iostream.h> from this file
dd107c50 353 wxSTD ostream *m_ostr;
c801d85f 354};
03147cd0
VZ
355
356#endif // wxUSE_STD_IOSTREAM
c801d85f 357
03147cd0
VZ
358// ----------------------------------------------------------------------------
359// /dev/null log target: suppress logging until this object goes out of scope
360// ----------------------------------------------------------------------------
361
362// example of usage:
363/*
364 void Foo()
365 {
366 wxFile file;
367
368 // wxFile.Open() normally complains if file can't be opened, we don't
369 // want it
370 wxLogNull logNo;
371
372 if ( !file.Open("bar") )
373 ... process error ourselves ...
374
375 // ~wxLogNull called, old log sink restored
376 }
377 */
bddd7a8d 378class WXDLLIMPEXP_BASE wxLogNull
03147cd0
VZ
379{
380public:
d1b20379 381 wxLogNull() : m_flagOld(wxLog::EnableLogging(false)) { }
be52b341 382 ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld); }
03147cd0
VZ
383
384private:
385 bool m_flagOld; // the previous value of the wxLog::ms_doLog
386};
387
388// ----------------------------------------------------------------------------
389// chaining log target: installs itself as a log target and passes all
390// messages to the real log target given to it in the ctor but also forwards
391// them to the previously active one
392//
393// note that you don't have to call SetActiveTarget() with this class, it
394// does it itself in its ctor
395// ----------------------------------------------------------------------------
396
bddd7a8d 397class WXDLLIMPEXP_BASE wxLogChain : public wxLog
03147cd0
VZ
398{
399public:
400 wxLogChain(wxLog *logger);
8b30a4e4 401 virtual ~wxLogChain();
03147cd0
VZ
402
403 // change the new log target
404 void SetLog(wxLog *logger);
405
406 // this can be used to temporarily disable (and then reenable) passing
407 // messages to the old logger (by default we do pass them)
408 void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; }
409
410 // are we passing the messages to the previous log target?
411 bool IsPassingMessages() const { return m_bPassMessages; }
412
413 // return the previous log target (may be NULL)
414 wxLog *GetOldLog() const { return m_logOld; }
415
416 // override base class version to flush the old logger as well
417 virtual void Flush();
418
419protected:
420 // pass the chain to the old logger if needed
421 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t);
422
423private:
424 // the current log target
425 wxLog *m_logNew;
426
427 // the previous log target
428 wxLog *m_logOld;
429
430 // do we pass the messages to the old logger?
431 bool m_bPassMessages;
22f3361e
VZ
432
433 DECLARE_NO_COPY_CLASS(wxLogChain)
03147cd0
VZ
434};
435
436// a chain log target which uses itself as the new logger
bddd7a8d 437class WXDLLIMPEXP_BASE wxLogPassThrough : public wxLogChain
03147cd0
VZ
438{
439public:
93d4c1d0 440 wxLogPassThrough();
fc7a2a60
VZ
441
442private:
443 DECLARE_NO_COPY_CLASS(wxLogPassThrough)
03147cd0
VZ
444};
445
8ca28fb7 446#if wxUSE_GUI
7e8c564c
VS
447 // include GUI log targets:
448 #include "wx/generic/logg.h"
e90c1d2a 449#endif // wxUSE_GUI
03f38c58 450
c801d85f
KB
451// ============================================================================
452// global functions
453// ============================================================================
454
455// ----------------------------------------------------------------------------
456// Log functions should be used by application instead of stdio, iostream &c
457// for log messages for easy redirection
458// ----------------------------------------------------------------------------
459
88ac883a
VZ
460// ----------------------------------------------------------------------------
461// get error code/error message from system in a portable way
462// ----------------------------------------------------------------------------
463
464// return the last system error code
bddd7a8d 465WXDLLIMPEXP_BASE unsigned long wxSysErrorCode();
c11d62a6 466
88ac883a 467// return the error message for given (or last if 0) error code
bddd7a8d 468WXDLLIMPEXP_BASE const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0);
88ac883a 469
c11d62a6 470// ----------------------------------------------------------------------------
c801d85f 471// define wxLog<level>
c11d62a6 472// ----------------------------------------------------------------------------
c801d85f 473
c9f78968
VS
474#define DECLARE_LOG_FUNCTION_PUBLIC(level) \
475 /* void wxLog##level(const wxChar *szFormat, ...); */ \
476 WX_DEFINE_VARARG_FUNC_VOID(wxLog##level, wxDoLog##level)
477
478#define DECLARE_LOG_FUNCTION_IMPL(level) \
479 extern void WXDLLIMPEXP_BASE wxVLog##level(const wxChar *szFormat, \
480 va_list argptr); \
481 extern void WXDLLIMPEXP_BASE wxDoLog##level(const wxChar *szFormat, \
482 ...) ATTRIBUTE_PRINTF_1
483
484#define DECLARE_LOG_FUNCTION2_EXP_IMPL(level, argclass, arg, expdecl) \
485 extern void expdecl wxVLog##level(argclass arg, \
486 const wxChar *szFormat, \
487 va_list argptr); \
488 extern void expdecl wxDoLog##level(argclass arg, \
489 const wxChar *szFormat, \
490 ...) ATTRIBUTE_PRINTF_2
491
88ac883a
VZ
492#else // !wxUSE_LOG
493
494// log functions do nothing at all
c9f78968
VS
495#define DECLARE_LOG_FUNCTION_PUBLIC(level) \
496 /* void wxLog##level(const wxChar *szFormat, ...) {} */ \
497 WX_DEFINE_VARARG_FUNC_NOP(wxLog##level)
498
499#define DECLARE_LOG_FUNCTION_IMPL(level) \
500 inline void wxVLog##level(const wxChar *WXUNUSED(szFormat), \
501 va_list WXUNUSED(argptr)) { } \
502
503#define DECLARE_LOG_FUNCTION2_EXP_IMPL(level, argclass, arg, expdecl) \
504 inline void wxVLog##level(argclass WXUNUSED(arg), \
505 const wxChar *WXUNUSED(szFormat), \
506 va_list WXUNUSED(argptr)) {}
88ac883a 507
e30285ab 508// Empty Class to fake wxLogNull
bddd7a8d 509class WXDLLIMPEXP_BASE wxLogNull
e30285ab
VZ
510{
511public:
886dd7d2 512 wxLogNull() { }
e30285ab
VZ
513};
514
515// Dummy macros to replace some functions.
516#define wxSysErrorCode() (unsigned long)0
517#define wxSysErrorMsg( X ) (const wxChar*)NULL
518
519// Fake symbolic trace masks... for those that are used frequently
fda7962d 520#define wxTRACE_OleCalls wxEmptyString // OLE interface calls
e30285ab 521
88ac883a 522#endif // wxUSE_LOG/!wxUSE_LOG
bdeb1f0d 523
c9f78968
VS
524#define DECLARE_LOG_FUNCTION(level) \
525 DECLARE_LOG_FUNCTION_PUBLIC(level) \
526 DECLARE_LOG_FUNCTION_IMPL(level)
527
528#define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
529 DECLARE_LOG_FUNCTION_PUBLIC(level) \
530 DECLARE_LOG_FUNCTION2_EXP_IMPL(level, argclass, arg, expdecl)
531
532#define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
533 DECLARE_LOG_FUNCTION_PUBLIC(level) \
534 DECLARE_LOG_FUNCTION2_EXP_IMPL(level, argclass, arg, expdecl)
535
536#define DECLARE_LOG_FUNCTION2_IMPL(level, argclass, arg) \
537 DECLARE_LOG_FUNCTION2_EXP_IMPL(level, argclass, arg, WXDLLIMPEXP_BASE)
538
33936026
WS
539#define DECLARE_LOG_FUNCTION2(level, argclass, arg) \
540 DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, WXDLLIMPEXP_BASE)
0b4f47a3 541
463c2e5b
VS
542// VC6 produces a warning if we a macro expanding to nothing to
543// DECLARE_LOG_FUNCTION2_IMPL:
544#if defined(__VISUALC__) && __VISUALC__ < 1300
545 // "not enough actual parameters for macro 'DECLARE_LOG_FUNCTION2_EXP_IMPL'"
546 #pragma warning(disable:4003)
547#endif
c801d85f 548
88ac883a 549// a generic function for all levels (level is passes as parameter)
33936026 550DECLARE_LOG_FUNCTION2(Generic, wxLogLevel, level);
c801d85f 551
88ac883a
VZ
552// one function per each level
553DECLARE_LOG_FUNCTION(FatalError);
554DECLARE_LOG_FUNCTION(Error);
555DECLARE_LOG_FUNCTION(Warning);
556DECLARE_LOG_FUNCTION(Message);
557DECLARE_LOG_FUNCTION(Info);
558DECLARE_LOG_FUNCTION(Verbose);
470b7da3 559
88ac883a
VZ
560// this function sends the log message to the status line of the top level
561// application frame, if any
c9f78968 562DECLARE_LOG_FUNCTION_IMPL(Status);
470b7da3 563
886dd7d2
VZ
564#if wxUSE_GUI
565 // this one is the same as previous except that it allows to explicitly
b76069e2 566 class WXDLLEXPORT wxFrame;
886dd7d2 567 // specify the frame to which the output should go
c9f78968 568 DECLARE_LOG_FUNCTION2_EXP_IMPL(Status, wxFrame *, pFrame, WXDLLIMPEXP_CORE);
886dd7d2 569#endif // wxUSE_GUI
c801d85f 570
a7f8eb6d 571DECLARE_LOG_FUNCTION_PUBLIC(Status)
c9f78968 572
88ac883a
VZ
573// additional one: as wxLogError, but also logs last system call error code
574// and the corresponding error message if available
c9f78968 575DECLARE_LOG_FUNCTION_IMPL(SysError);
c801d85f 576
88ac883a
VZ
577// and another one which also takes the error code (for those broken APIs
578// that don't set the errno (like registry APIs in Win32))
c9f78968
VS
579DECLARE_LOG_FUNCTION2_IMPL(SysError, long, lErrCode);
580
a7f8eb6d 581DECLARE_LOG_FUNCTION_PUBLIC(SysError)
88ac883a
VZ
582
583// debug functions do nothing in release mode
bdeb1f0d 584#if wxUSE_LOG && wxUSE_LOG_DEBUG
d6b9496a
VZ
585 DECLARE_LOG_FUNCTION(Debug);
586
b103e4f3
VZ
587 // there is no more unconditional LogTrace: it is not different from
588 // LogDebug and it creates overload ambiguities
589 //DECLARE_LOG_FUNCTION(Trace);
d6b9496a 590
b103e4f3
VZ
591 // this version only logs the message if the mask had been added to the
592 // list of masks with AddTraceMask()
c9f78968 593 DECLARE_LOG_FUNCTION2_IMPL(Trace, const wxChar*, mask);
b103e4f3
VZ
594 // and this one does nothing if all of level bits are not set in
595 // wxLog::GetActive()->GetTraceMask() -- it's deprecated in favour of
d6b9496a 596 // string identifiers
c9f78968 597 DECLARE_LOG_FUNCTION2_IMPL(Trace, wxTraceMask, mask);
a7f8eb6d 598 DECLARE_LOG_FUNCTION_PUBLIC(Trace)
bdeb1f0d 599#else //!debug || !wxUSE_LOG
388a1f66
VZ
600 // these functions do nothing in release builds, but don't define them as
601 // nothing as it could result in different code structure in debug and
602 // release and this could result in trouble when these macros are used
603 // inside if/else
604 //
605 // note that making wxVLogDebug/Trace() themselves (empty inline) functions
606 // is a bad idea as some compilers are stupid enough to not inline even
607 // empty functions if their parameters are complicated enough, but by
608 // defining them as an empty inline function we ensure that even dumbest
609 // compilers optimise them away
610 inline void wxLogNop() { }
611
612 #define wxVLogDebug(fmt, valist) wxLogNop()
613 #define wxVLogTrace(mask, fmt, valist) wxLogNop()
ca766534
VS
614
615 #ifdef HAVE_VARIADIC_MACROS
388a1f66
VZ
616 // unlike the inline functions below, this completely removes the
617 // wxLogXXX calls from the object file:
618 #define wxLogDebug(fmt, ...) wxLogNop()
619 #define wxLogTrace(mask, fmt, ...) wxLogNop()
ca766534 620 #else // !HAVE_VARIADIC_MACROS
c9f78968 621 //inline void wxLogDebug(const wxString& fmt, ...) {}
67393add 622 WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug)
c9f78968
VS
623 //inline void wxLogTrace(wxTraceMask, const wxString& fmt, ...) {}
624 //inline void wxLogTrace(const wxString&, const wxString& fmt, ...) {}
67393add 625 WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace)
ca766534 626 #endif // HAVE_VARIADIC_MACROS/!HAVE_VARIADIC_MACROS
88ac883a 627#endif // debug/!debug
c801d85f 628
463c2e5b
VS
629#if defined(__VISUALC__) && __VISUALC__ < 1300
630 #pragma warning(default:4003)
631#endif
632
c11d62a6
VZ
633// wxLogFatalError helper: show the (fatal) error to the user in a safe way,
634// i.e. without using wxMessageBox() for example because it could crash
bddd7a8d 635void WXDLLIMPEXP_BASE
886dd7d2 636wxSafeShowMessage(const wxString& title, const wxString& text);
c11d62a6 637
88ac883a
VZ
638// ----------------------------------------------------------------------------
639// debug only logging functions: use them with API name and error code
640// ----------------------------------------------------------------------------
c801d85f 641
e90babdf 642#ifdef __WXDEBUG__
42e69d6b
VZ
643 // make life easier for people using VC++ IDE: clicking on the message
644 // will take us immediately to the place of the failed API
645#ifdef __VISUALC__
4b7f2165
VZ
646 #define wxLogApiError(api, rc) \
647 wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
8b94d999
VZ
648 __TFILE__, __LINE__, api, \
649 (long)rc, wxSysErrorMsg(rc))
42e69d6b 650#else // !VC++
4b7f2165 651 #define wxLogApiError(api, rc) \
18da7cf2
VZ
652 wxLogDebug(wxT("In file %s at line %d: '%s' failed with ") \
653 wxT("error 0x%08lx (%s)."), \
8b94d999
VZ
654 __TFILE__, __LINE__, api, \
655 (long)rc, wxSysErrorMsg(rc))
42e69d6b
VZ
656#endif // VC++/!VC++
657
658 #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
659
c801d85f 660#else //!debug
388a1f66
VZ
661 #define wxLogApiError(api, err) wxLogNop()
662 #define wxLogLastError(api) wxLogNop()
c801d85f
KB
663#endif //debug/!debug
664
a619fa3f
DE
665// wxCocoa has additiional trace masks
666#if defined(__WXCOCOA__)
667#include "wx/cocoa/log.h"
668#endif
669
34138703 670#endif // _WX_LOG_H_
04662def 671