]> git.saurik.com Git - wxWidgets.git/blame - include/wx/log.h
The exact version it was included doesn't appear to be documented
[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>
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_LOG_H_
13#define _WX_LOG_H_
c801d85f 14
af49c4b8 15#if defined(__GNUG__) && !defined(__APPLE__)
d6b9496a 16 #pragma interface "log.h"
0d3820b3 17#endif
c801d85f 18
38830220 19#include "wx/setup.h"
d1af991f 20#include "wx/string.h"
38830220 21
546db2a8
VZ
22// ----------------------------------------------------------------------------
23// forward declarations
24// ----------------------------------------------------------------------------
25
26class WXDLLEXPORT wxTextCtrl;
27class WXDLLEXPORT wxLogFrame;
28class WXDLLEXPORT wxFrame;
29
30// ----------------------------------------------------------------------------
31// types
32// ----------------------------------------------------------------------------
33
34typedef unsigned long wxTraceMask;
35typedef unsigned long wxLogLevel;
36
37// ----------------------------------------------------------------------------
38// headers
39// ----------------------------------------------------------------------------
40
88ac883a
VZ
41#if wxUSE_LOG
42
0e0126c2 43#ifndef __WXWINCE__
c30aaf75 44#include <time.h> // for time_t
0e0126c2 45#endif
c30aaf75
VZ
46
47#include "wx/dynarray.h"
d6b9496a 48
edc73852
RD
49#ifndef wxUSE_LOG_DEBUG
50# ifdef __WXDEBUG__
51# define wxUSE_LOG_DEBUG 1
52# else // !__WXDEBUG__
53# define wxUSE_LOG_DEBUG 0
54# endif
55#endif
56
9ef3052c
VZ
57// ----------------------------------------------------------------------------
58// constants
59// ----------------------------------------------------------------------------
60
61// different standard log levels (you may also define your own)
62enum
63{
d6b9496a
VZ
64 wxLOG_FatalError, // program can't continue, abort immediately
65 wxLOG_Error, // a serious error, user must be informed about it
66 wxLOG_Warning, // user is normally informed about it but may be ignored
67 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
d6b9496a 68 wxLOG_Status, // informational: might go to the status line of GUI app
edc73852 69 wxLOG_Info, // informational message (a.k.a. 'Verbose')
d6b9496a
VZ
70 wxLOG_Debug, // never shown to the user, disabled in release mode
71 wxLOG_Trace, // trace messages are also only enabled in debug mode
72 wxLOG_Progress, // used for progress indicator (not yet)
edc73852 73 wxLOG_User = 100, // user defined levels start here
65ca8c0b 74 wxLOG_Max = 10000
9ef3052c
VZ
75};
76
d6b9496a
VZ
77// symbolic trace masks - wxLogTrace("foo", "some trace message...") will be
78// discarded unless the string "foo" has been added to the list of allowed
79// ones with AddTraceMask()
80
08298395
OK
81#define wxTRACE_MemAlloc wxT("memalloc") // trace memory allocation (new/delete)
82#define wxTRACE_Messages wxT("messages") // trace window messages/X callbacks
83#define wxTRACE_ResAlloc wxT("resalloc") // trace GDI resource allocation
84#define wxTRACE_RefCount wxT("refcount") // trace various ref counting operations
d6b9496a
VZ
85
86#ifdef __WXMSW__
08298395 87 #define wxTRACE_OleCalls wxT("ole") // OLE interface calls
d6b9496a
VZ
88#endif
89
90// the trace masks have been superceded by symbolic trace constants, they're
91// for compatibility only andwill be removed soon - do NOT use them
92
9ef3052c
VZ
93// meaning of different bits of the trace mask (which allows selectively
94// enable/disable some trace messages)
95#define wxTraceMemAlloc 0x0001 // trace memory allocation (new/delete)
96#define wxTraceMessages 0x0002 // trace window messages/X callbacks
97#define wxTraceResAlloc 0x0004 // trace GDI resource allocation
98#define wxTraceRefCount 0x0008 // trace various ref counting operations
99
2049ba38 100#ifdef __WXMSW__
d6b9496a 101 #define wxTraceOleCalls 0x0100 // OLE interface calls
9ef3052c
VZ
102#endif
103
38830220 104#include "wx/ioswrap.h"
470b7da3 105
c801d85f
KB
106// ----------------------------------------------------------------------------
107// derive from this class to redirect (or suppress, or ...) log messages
108// normally, only a single instance of this class exists but it's not enforced
c801d85f 109// ----------------------------------------------------------------------------
d6b9496a 110
c801d85f
KB
111class WXDLLEXPORT wxLog
112{
113public:
d6b9496a
VZ
114 // ctor
115 wxLog();
116
04662def
RL
117 // Internal buffer.
118 // Allow replacement of the fixed size static buffer with
119 // a user allocated one. Pass in NULL to restore the
120 // built in static buffer.
121 static wxChar *SetLogBuffer( wxChar *buf, size_t size = 0 );
122
d6b9496a
VZ
123 // these functions allow to completely disable all log messages
124 // is logging disabled now?
125 static bool IsEnabled() { return ms_doLog; }
126 // change the flag state, return the previous one
127 static bool EnableLogging(bool doIt = TRUE)
128 { bool doLogOld = ms_doLog; ms_doLog = doIt; return doLogOld; }
129
130 // static sink function - see DoLog() for function to overload in the
131 // derived classes
9e3d3318 132 static void OnLog(wxLogLevel level, const wxChar *szString, time_t t)
d6b9496a 133 {
edc73852 134 if ( IsEnabled() && ms_logLevel >= level ) {
d6b9496a
VZ
135 wxLog *pLogger = GetActiveTarget();
136 if ( pLogger )
137 pLogger->DoLog(level, szString, t);
138 }
803bf1c5 139 }
d6b9496a
VZ
140
141 // message buffering
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)
145 virtual void Flush();
146 // call to Flush() may be optimized: call it only if this function
147 // returns true (although Flush() also returns immediately if there is
148 // no messages, this functions is more efficient because inline)
149 bool HasPendingMessages() const { return m_bHasMessages; }
150
151 // only one sink is active at each moment
bbfa0322
VZ
152 // flush the active target if any
153 static void FlushActive()
154 {
2ed3265e
VZ
155 if ( !ms_suspendCount )
156 {
157 wxLog *log = GetActiveTarget();
158 if ( log && log->HasPendingMessages() )
159 log->Flush();
160 }
bbfa0322 161 }
d6b9496a
VZ
162 // get current log target, will call wxApp::CreateLogTarget() to
163 // create one if none exists
164 static wxLog *GetActiveTarget();
165 // change log target, pLogger may be NULL
166 static wxLog *SetActiveTarget(wxLog *pLogger);
167
2ed3265e
VZ
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)
171 static void Suspend() { ms_suspendCount++; }
172 // must be called for each Suspend()!
173 static void Resume() { ms_suspendCount--; }
174
d6b9496a
VZ
175 // functions controlling the default wxLog behaviour
176 // verbose mode is activated by standard command-line '-verbose'
177 // option
fd7718b2 178 static void SetVerbose(bool bVerbose = TRUE) { ms_bVerbose = bVerbose; }
edc73852
RD
179
180 // Set log level. Log messages with level > logLevel will not be logged.
181 static void SetLogLevel(wxLogLevel logLevel) { ms_logLevel = logLevel; }
182
d6b9496a
VZ
183 // should GetActiveTarget() try to create a new log object if the
184 // current is NULL?
36bd6902 185 static void DontCreateOnDemand();
d6b9496a
VZ
186
187 // trace mask (see wxTraceXXX constants for details)
188 static void SetTraceMask(wxTraceMask ulMask) { ms_ulTraceMask = ulMask; }
189 // add string trace mask
190 static void AddTraceMask(const wxString& str) { ms_aTraceMasks.Add(str); }
191 // add string trace mask
192 static void RemoveTraceMask(const wxString& str);
36bd6902
VZ
193 // remove all string trace masks
194 static void ClearTraceMasks();
0e080be6
RL
195 // get string trace masks
196 static const wxArrayString &GetTraceMasks() { return ms_aTraceMasks; }
d6b9496a 197
d2e1ef19
VZ
198 // sets the timestamp string: this is used as strftime() format string
199 // for the log targets which add time stamps to the messages - set it
200 // to NULL to disable time stamping completely.
201 static void SetTimestamp(const wxChar *ts) { ms_timestamp = ts; }
202
edc73852 203
d6b9496a
VZ
204 // accessors
205 // gets the verbose status
fd7718b2 206 static bool GetVerbose() { return ms_bVerbose; }
d6b9496a
VZ
207 // get trace mask
208 static wxTraceMask GetTraceMask() { return ms_ulTraceMask; }
209 // is this trace mask in the list?
9e3d3318 210 static bool IsAllowedTraceMask(const wxChar *mask)
d6b9496a 211 { return ms_aTraceMasks.Index(mask) != wxNOT_FOUND; }
edc73852
RD
212 // return the current loglevel limit
213 static wxLogLevel GetLogLevel() { return ms_logLevel; }
d6b9496a 214
d2e1ef19
VZ
215 // get the current timestamp format string (may be NULL)
216 static const wxChar *GetTimestamp() { return ms_timestamp; }
217
edc73852 218
d2e1ef19
VZ
219 // helpers
220 // put the time stamp into the string if ms_timestamp != NULL (don't
221 // change it otherwise)
222 static void TimeStamp(wxString *str);
223
d6b9496a
VZ
224 // make dtor virtual for all derived classes
225 virtual ~wxLog() { }
c801d85f
KB
226
227protected:
d6b9496a 228 bool m_bHasMessages; // any messages in the queue?
c801d85f 229
d6b9496a
VZ
230 // the logging functions that can be overriden
231 // default DoLog() prepends the time stamp and a prefix corresponding
232 // to the message to szString and then passes it to DoLogString()
9e3d3318 233 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t);
d6b9496a
VZ
234 // default DoLogString does nothing but is not pure virtual because if
235 // you override DoLog() you might not need it at all
9e3d3318 236 virtual void DoLogString(const wxChar *szString, time_t t);
c801d85f 237
d6b9496a
VZ
238private:
239 // static variables
240 // ----------------
06db8ebd 241
d6b9496a
VZ
242 static wxLog *ms_pLogger; // currently active log sink
243 static bool ms_doLog; // FALSE => all logging disabled
244 static bool ms_bAutoCreate; // create new log targets on demand?
fd7718b2 245 static bool ms_bVerbose; // FALSE => ignore LogInfo messages
fe7b1156 246
edc73852
RD
247 static wxLogLevel ms_logLevel; // limit logging to levels <= ms_logLevel
248
2ed3265e
VZ
249 static size_t ms_suspendCount; // if positive, logs are not flushed
250
d2e1ef19
VZ
251 // format string for strftime(), if NULL, time stamping log messages is
252 // disabled
253 static const wxChar *ms_timestamp;
254
d6b9496a
VZ
255 static wxTraceMask ms_ulTraceMask; // controls wxLogTrace behaviour
256 static wxArrayString ms_aTraceMasks; // more powerful filter for wxLogTrace
c801d85f
KB
257};
258
259// ----------------------------------------------------------------------------
260// "trivial" derivations of wxLog
261// ----------------------------------------------------------------------------
262
263// log everything to a "FILE *", stderr by default
264class WXDLLEXPORT wxLogStderr : public wxLog
265{
be52b341 266 DECLARE_NO_COPY_CLASS(wxLogStderr)
64bea2bf 267
c801d85f 268public:
d6b9496a
VZ
269 // redirect log output to a FILE
270 wxLogStderr(FILE *fp = (FILE *) NULL);
c801d85f 271
03147cd0 272protected:
d6b9496a 273 // implement sink function
9e3d3318 274 virtual void DoLogString(const wxChar *szString, time_t t);
c801d85f 275
d6b9496a 276 FILE *m_fp;
c801d85f
KB
277};
278
4bf78aae 279#if wxUSE_STD_IOSTREAM
03147cd0 280
c801d85f
KB
281// log everything to an "ostream", cerr by default
282class WXDLLEXPORT wxLogStream : public wxLog
283{
284public:
d6b9496a 285 // redirect log output to an ostream
dd107c50 286 wxLogStream(wxSTD ostream *ostr = (wxSTD ostream *) NULL);
c801d85f
KB
287
288protected:
d6b9496a 289 // implement sink function
9e3d3318 290 virtual void DoLogString(const wxChar *szString, time_t t);
c801d85f 291
d6b9496a 292 // using ptr here to avoid including <iostream.h> from this file
dd107c50 293 wxSTD ostream *m_ostr;
c801d85f 294};
03147cd0
VZ
295
296#endif // wxUSE_STD_IOSTREAM
c801d85f 297
03147cd0
VZ
298// ----------------------------------------------------------------------------
299// /dev/null log target: suppress logging until this object goes out of scope
300// ----------------------------------------------------------------------------
301
302// example of usage:
303/*
304 void Foo()
305 {
306 wxFile file;
307
308 // wxFile.Open() normally complains if file can't be opened, we don't
309 // want it
310 wxLogNull logNo;
311
312 if ( !file.Open("bar") )
313 ... process error ourselves ...
314
315 // ~wxLogNull called, old log sink restored
316 }
317 */
318class WXDLLEXPORT wxLogNull
319{
320public:
be52b341
GD
321 wxLogNull() : m_flagOld(wxLog::EnableLogging(FALSE)) { }
322 ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld); }
03147cd0
VZ
323
324private:
325 bool m_flagOld; // the previous value of the wxLog::ms_doLog
326};
327
328// ----------------------------------------------------------------------------
329// chaining log target: installs itself as a log target and passes all
330// messages to the real log target given to it in the ctor but also forwards
331// them to the previously active one
332//
333// note that you don't have to call SetActiveTarget() with this class, it
334// does it itself in its ctor
335// ----------------------------------------------------------------------------
336
337class WXDLLEXPORT wxLogChain : public wxLog
338{
339public:
340 wxLogChain(wxLog *logger);
8b30a4e4 341 virtual ~wxLogChain();
03147cd0
VZ
342
343 // change the new log target
344 void SetLog(wxLog *logger);
345
346 // this can be used to temporarily disable (and then reenable) passing
347 // messages to the old logger (by default we do pass them)
348 void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; }
349
350 // are we passing the messages to the previous log target?
351 bool IsPassingMessages() const { return m_bPassMessages; }
352
353 // return the previous log target (may be NULL)
354 wxLog *GetOldLog() const { return m_logOld; }
355
356 // override base class version to flush the old logger as well
357 virtual void Flush();
358
359protected:
360 // pass the chain to the old logger if needed
361 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t);
362
363private:
364 // the current log target
365 wxLog *m_logNew;
366
367 // the previous log target
368 wxLog *m_logOld;
369
370 // do we pass the messages to the old logger?
371 bool m_bPassMessages;
22f3361e
VZ
372
373 DECLARE_NO_COPY_CLASS(wxLogChain)
03147cd0
VZ
374};
375
376// a chain log target which uses itself as the new logger
377class WXDLLEXPORT wxLogPassThrough : public wxLogChain
378{
379public:
93d4c1d0 380 wxLogPassThrough();
03147cd0
VZ
381};
382
8ca28fb7
VZ
383// ----------------------------------------------------------------------------
384// the following log targets are only compiled in if the we're compiling the
385// GUI part (andnot just the base one) of the library, they're implemented in
386// src/generic/logg.cpp *and not src/common/log.cpp unlike all the rest)
387// ----------------------------------------------------------------------------
388
389#if wxUSE_GUI
390
391#if wxUSE_TEXTCTRL
392
393// log everything to a text window (GUI only of course)
394class WXDLLEXPORT wxLogTextCtrl : public wxLog
395{
396public:
397 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
398
399private:
400 // implement sink function
401 virtual void DoLogString(const wxChar *szString, time_t t);
402
403 // the control we use
404 wxTextCtrl *m_pTextCtrl;
22f3361e
VZ
405
406 DECLARE_NO_COPY_CLASS(wxLogTextCtrl)
8ca28fb7
VZ
407};
408
409#endif // wxUSE_TEXTCTRL
410
c801d85f
KB
411// ----------------------------------------------------------------------------
412// GUI log target, the default one for wxWindows programs
413// ----------------------------------------------------------------------------
1e6feb95
VZ
414
415#if wxUSE_LOGGUI
416
c801d85f
KB
417class WXDLLEXPORT wxLogGui : public wxLog
418{
419public:
d6b9496a
VZ
420 // ctor
421 wxLogGui();
c801d85f 422
d6b9496a
VZ
423 // show all messages that were logged since the last Flush()
424 virtual void Flush();
c801d85f
KB
425
426protected:
9e3d3318 427 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t);
d6b9496a
VZ
428
429 // empty everything
430 void Clear();
c801d85f 431
f1df0927
VZ
432 wxArrayString m_aMessages; // the log message texts
433 wxArrayInt m_aSeverity; // one of wxLOG_XXX values
434 wxArrayLong m_aTimes; // the time of each message
d6b9496a
VZ
435 bool m_bErrors, // do we have any errors?
436 m_bWarnings; // any warnings?
c801d85f
KB
437};
438
1e6feb95
VZ
439#endif // wxUSE_LOGGUI
440
9ef3052c
VZ
441// ----------------------------------------------------------------------------
442// (background) log window: this class forwards all log messages to the log
443// target which was active when it was instantiated, but also collects them
444// to the log window. This window has it's own menu which allows the user to
445// close it, clear the log contents or save it to the file.
446// ----------------------------------------------------------------------------
1e6feb95
VZ
447
448#if wxUSE_LOGWINDOW
449
03147cd0 450class WXDLLEXPORT wxLogWindow : public wxLogPassThrough
9ef3052c
VZ
451{
452public:
d6b9496a 453 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
03147cd0
VZ
454 const wxChar *szTitle, // the title of the frame
455 bool bShow = TRUE, // show window immediately?
456 bool bPassToOld = TRUE); // pass messages to the old target?
457
d6b9496a 458 ~wxLogWindow();
06db8ebd 459
d6b9496a 460 // window operations
f6bcfd97 461 // show/hide the log window
d6b9496a 462 void Show(bool bShow = TRUE);
f6bcfd97 463 // retrieve the pointer to the frame
d6b9496a 464 wxFrame *GetFrame() const;
9ef3052c 465
d6b9496a 466 // overridables
f6bcfd97
BP
467 // called immediately after the log frame creation allowing for
468 // any extra initializations
d6b9496a 469 virtual void OnFrameCreate(wxFrame *frame);
f6bcfd97
BP
470 // called if the user closes the window interactively, will not be
471 // called if it is destroyed for another reason (such as when program
472 // exits) - return TRUE from here to allow the frame to close, FALSE
473 // to prevent this from happening
474 virtual bool OnFrameClose(wxFrame *frame);
475 // called right before the log frame is going to be deleted: will
476 // always be called unlike OnFrameClose()
d6b9496a 477 virtual void OnFrameDelete(wxFrame *frame);
fe7b1156 478
9ef3052c 479protected:
9e3d3318
OK
480 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t);
481 virtual void DoLogString(const wxChar *szString, time_t t);
06db8ebd 482
9ef3052c 483private:
d6b9496a 484 wxLogFrame *m_pLogFrame; // the log frame
22f3361e
VZ
485
486 DECLARE_NO_COPY_CLASS(wxLogWindow)
9ef3052c
VZ
487};
488
1e6feb95
VZ
489#endif // wxUSE_LOGWINDOW
490
e90c1d2a 491#endif // wxUSE_GUI
03f38c58 492
c801d85f
KB
493// ============================================================================
494// global functions
495// ============================================================================
496
497// ----------------------------------------------------------------------------
498// Log functions should be used by application instead of stdio, iostream &c
499// for log messages for easy redirection
500// ----------------------------------------------------------------------------
501
88ac883a
VZ
502// ----------------------------------------------------------------------------
503// get error code/error message from system in a portable way
504// ----------------------------------------------------------------------------
505
506// return the last system error code
507WXDLLEXPORT unsigned long wxSysErrorCode();
c11d62a6 508
88ac883a
VZ
509// return the error message for given (or last if 0) error code
510WXDLLEXPORT const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0);
511
c11d62a6 512// ----------------------------------------------------------------------------
c801d85f 513// define wxLog<level>
c11d62a6 514// ----------------------------------------------------------------------------
c801d85f 515
c801d85f 516#define DECLARE_LOG_FUNCTION(level) \
1d63fd6b 517extern void WXDLLEXPORT wxVLog##level(const wxChar *szFormat, \
ea44a631 518 va_list argptr); \
7357f981
GD
519extern void WXDLLEXPORT wxLog##level(const wxChar *szFormat, \
520 ...) ATTRIBUTE_PRINTF_1
a1530845 521#define DECLARE_LOG_FUNCTION2(level, arg1) \
1d63fd6b 522extern void WXDLLEXPORT wxVLog##level(arg1, const wxChar *szFormat, \
ea44a631 523 va_list argptr); \
7357f981
GD
524extern void WXDLLEXPORT wxLog##level(arg1, const wxChar *szFormat, \
525 ...) ATTRIBUTE_PRINTF_2
a1530845 526
88ac883a
VZ
527#else // !wxUSE_LOG
528
529// log functions do nothing at all
530#define DECLARE_LOG_FUNCTION(level) \
1d63fd6b 531inline void WXDLLEXPORT wxVLog##level(const wxChar *szFormat, \
ea44a631 532 va_list argptr) {} \
546db2a8 533inline void WXDLLEXPORT wxLog##level(const wxChar *szFormat, ...) {}
88ac883a 534#define DECLARE_LOG_FUNCTION2(level, arg1) \
1d63fd6b 535inline void WXDLLEXPORT wxVLog##level(arg1, const wxChar *szFormat, \
ea44a631 536 va_list argptr) {} \
546db2a8 537inline void WXDLLEXPORT wxLog##level(arg1, const wxChar *szFormat, ...) {}
88ac883a
VZ
538
539#endif // wxUSE_LOG/!wxUSE_LOG
c801d85f 540
88ac883a
VZ
541// a generic function for all levels (level is passes as parameter)
542DECLARE_LOG_FUNCTION2(Generic, wxLogLevel level);
c801d85f 543
88ac883a
VZ
544// one function per each level
545DECLARE_LOG_FUNCTION(FatalError);
546DECLARE_LOG_FUNCTION(Error);
547DECLARE_LOG_FUNCTION(Warning);
548DECLARE_LOG_FUNCTION(Message);
549DECLARE_LOG_FUNCTION(Info);
550DECLARE_LOG_FUNCTION(Verbose);
470b7da3 551
88ac883a
VZ
552// this function sends the log message to the status line of the top level
553// application frame, if any
554DECLARE_LOG_FUNCTION(Status);
470b7da3 555
88ac883a
VZ
556// this one is the same as previous except that it allows to explicitly
557// specify the frame to which the output should go
558DECLARE_LOG_FUNCTION2(Status, wxFrame *pFrame);
c801d85f 559
88ac883a
VZ
560// additional one: as wxLogError, but also logs last system call error code
561// and the corresponding error message if available
562DECLARE_LOG_FUNCTION(SysError);
c801d85f 563
88ac883a
VZ
564// and another one which also takes the error code (for those broken APIs
565// that don't set the errno (like registry APIs in Win32))
566DECLARE_LOG_FUNCTION2(SysError, long lErrCode);
567
568// debug functions do nothing in release mode
edc73852 569#if wxUSE_LOG_DEBUG
d6b9496a
VZ
570 DECLARE_LOG_FUNCTION(Debug);
571
ea44a631 572 // first kind of LogTrace is unconditional: it doesn't check the level,
d6b9496a
VZ
573 DECLARE_LOG_FUNCTION(Trace);
574
575 // this second version will only log the message if the mask had been
576 // added to the list of masks with AddTraceMask()
f6bcfd97 577 DECLARE_LOG_FUNCTION2(Trace, const wxChar *mask);
9ef3052c 578
d6b9496a
VZ
579 // the last one does nothing if all of level bits are not set
580 // in wxLog::GetActive()->GetTraceMask() - it's deprecated in favour of
581 // string identifiers
582 DECLARE_LOG_FUNCTION2(Trace, wxTraceMask mask);
9ef3052c 583#else //!debug
d6b9496a 584 // these functions do nothing in release builds
1d63fd6b 585 inline void wxVLogDebug(const wxChar *, va_list) { }
9e3d3318 586 inline void wxLogDebug(const wxChar *, ...) { }
1d63fd6b 587 inline void wxVLogTrace(const wxChar *, va_list) { }
9e3d3318 588 inline void wxLogTrace(const wxChar *, ...) { }
1d63fd6b 589 inline void wxVLogTrace(wxTraceMask, const wxChar *, va_list) { }
9e3d3318 590 inline void wxLogTrace(wxTraceMask, const wxChar *, ...) { }
1d63fd6b 591 inline void wxVLogTrace(const wxChar *, const wxChar *, va_list) { }
9e3d3318 592 inline void wxLogTrace(const wxChar *, const wxChar *, ...) { }
88ac883a 593#endif // debug/!debug
c801d85f 594
c11d62a6
VZ
595// wxLogFatalError helper: show the (fatal) error to the user in a safe way,
596// i.e. without using wxMessageBox() for example because it could crash
64bea2bf 597void WXDLLEXPORT wxSafeShowMessage(const wxString& title, const wxString& text);
c11d62a6 598
88ac883a
VZ
599// ----------------------------------------------------------------------------
600// debug only logging functions: use them with API name and error code
601// ----------------------------------------------------------------------------
c801d85f 602
e90babdf 603#ifdef __WXDEBUG__
42e69d6b
VZ
604 // make life easier for people using VC++ IDE: clicking on the message
605 // will take us immediately to the place of the failed API
606#ifdef __VISUALC__
4b7f2165
VZ
607 #define wxLogApiError(api, rc) \
608 wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
8b94d999
VZ
609 __TFILE__, __LINE__, api, \
610 (long)rc, wxSysErrorMsg(rc))
42e69d6b 611#else // !VC++
4b7f2165
VZ
612 #define wxLogApiError(api, rc) \
613 wxLogDebug(wxT("In file %s at line %d: '%s' failed with " \
8b94d999
VZ
614 "error 0x%08lx (%s)."), \
615 __TFILE__, __LINE__, api, \
616 (long)rc, wxSysErrorMsg(rc))
42e69d6b
VZ
617#endif // VC++/!VC++
618
619 #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
620
c801d85f 621#else //!debug
9e3d3318
OK
622 inline void wxLogApiError(const wxChar *, long) { }
623 inline void wxLogLastError(const wxChar *) { }
c801d85f
KB
624#endif //debug/!debug
625
34138703 626#endif // _WX_LOG_H_
04662def 627
0e080be6 628// vi:sts=4:sw=4:et