]> git.saurik.com Git - wxWidgets.git/blame - include/wx/log.h
Added helper functions for string -> XmString conversion.
[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
65f19af1 104#include "wx/iosfwrap.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();
d6b9496a 146
bbfa0322
VZ
147 // flush the active target if any
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
d6b9496a
VZ
159 // get current log target, will call wxApp::CreateLogTarget() to
160 // create one if none exists
161 static wxLog *GetActiveTarget();
162 // change log target, pLogger may be NULL
163 static wxLog *SetActiveTarget(wxLog *pLogger);
164
2ed3265e
VZ
165 // suspend the message flushing of the main target until the next call
166 // to Resume() - this is mainly for internal use (to prevent wxYield()
167 // from flashing the messages)
168 static void Suspend() { ms_suspendCount++; }
169 // must be called for each Suspend()!
170 static void Resume() { ms_suspendCount--; }
171
d6b9496a
VZ
172 // functions controlling the default wxLog behaviour
173 // verbose mode is activated by standard command-line '-verbose'
174 // option
fd7718b2 175 static void SetVerbose(bool bVerbose = TRUE) { ms_bVerbose = bVerbose; }
edc73852
RD
176
177 // Set log level. Log messages with level > logLevel will not be logged.
178 static void SetLogLevel(wxLogLevel logLevel) { ms_logLevel = logLevel; }
179
d6b9496a
VZ
180 // should GetActiveTarget() try to create a new log object if the
181 // current is NULL?
36bd6902 182 static void DontCreateOnDemand();
d6b9496a
VZ
183
184 // trace mask (see wxTraceXXX constants for details)
185 static void SetTraceMask(wxTraceMask ulMask) { ms_ulTraceMask = ulMask; }
186 // add string trace mask
187 static void AddTraceMask(const wxString& str) { ms_aTraceMasks.Add(str); }
188 // add string trace mask
189 static void RemoveTraceMask(const wxString& str);
36bd6902
VZ
190 // remove all string trace masks
191 static void ClearTraceMasks();
0e080be6
RL
192 // get string trace masks
193 static const wxArrayString &GetTraceMasks() { return ms_aTraceMasks; }
d6b9496a 194
d2e1ef19
VZ
195 // sets the timestamp string: this is used as strftime() format string
196 // for the log targets which add time stamps to the messages - set it
197 // to NULL to disable time stamping completely.
198 static void SetTimestamp(const wxChar *ts) { ms_timestamp = ts; }
199
edc73852 200
d6b9496a
VZ
201 // accessors
202 // gets the verbose status
fd7718b2 203 static bool GetVerbose() { return ms_bVerbose; }
d6b9496a
VZ
204 // get trace mask
205 static wxTraceMask GetTraceMask() { return ms_ulTraceMask; }
206 // is this trace mask in the list?
9e3d3318 207 static bool IsAllowedTraceMask(const wxChar *mask)
d6b9496a 208 { return ms_aTraceMasks.Index(mask) != wxNOT_FOUND; }
edc73852
RD
209 // return the current loglevel limit
210 static wxLogLevel GetLogLevel() { return ms_logLevel; }
d6b9496a 211
d2e1ef19
VZ
212 // get the current timestamp format string (may be NULL)
213 static const wxChar *GetTimestamp() { return ms_timestamp; }
214
edc73852 215
d2e1ef19
VZ
216 // helpers
217 // put the time stamp into the string if ms_timestamp != NULL (don't
218 // change it otherwise)
219 static void TimeStamp(wxString *str);
220
d6b9496a
VZ
221 // make dtor virtual for all derived classes
222 virtual ~wxLog() { }
c801d85f 223
c801d85f 224
1ec5cbf3 225 // this method exists for backwards compatibility only, don't use
dc259b79 226 bool HasPendingMessages() const { return TRUE; }
1ec5cbf3
VZ
227
228protected:
d6b9496a
VZ
229 // the logging functions that can be overriden
230 // default DoLog() prepends the time stamp and a prefix corresponding
231 // to the message to szString and then passes it to DoLogString()
9e3d3318 232 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t);
d6b9496a
VZ
233 // default DoLogString does nothing but is not pure virtual because if
234 // you override DoLog() you might not need it at all
9e3d3318 235 virtual void DoLogString(const wxChar *szString, time_t t);
c801d85f 236
d6b9496a
VZ
237private:
238 // static variables
239 // ----------------
06db8ebd 240
d6b9496a
VZ
241 static wxLog *ms_pLogger; // currently active log sink
242 static bool ms_doLog; // FALSE => all logging disabled
243 static bool ms_bAutoCreate; // create new log targets on demand?
fd7718b2 244 static bool ms_bVerbose; // FALSE => ignore LogInfo messages
fe7b1156 245
edc73852
RD
246 static wxLogLevel ms_logLevel; // limit logging to levels <= ms_logLevel
247
2ed3265e
VZ
248 static size_t ms_suspendCount; // if positive, logs are not flushed
249
d2e1ef19
VZ
250 // format string for strftime(), if NULL, time stamping log messages is
251 // disabled
252 static const wxChar *ms_timestamp;
253
d6b9496a
VZ
254 static wxTraceMask ms_ulTraceMask; // controls wxLogTrace behaviour
255 static wxArrayString ms_aTraceMasks; // more powerful filter for wxLogTrace
c801d85f
KB
256};
257
258// ----------------------------------------------------------------------------
259// "trivial" derivations of wxLog
260// ----------------------------------------------------------------------------
261
262// log everything to a "FILE *", stderr by default
263class WXDLLEXPORT wxLogStderr : public wxLog
264{
be52b341 265 DECLARE_NO_COPY_CLASS(wxLogStderr)
64bea2bf 266
c801d85f 267public:
d6b9496a
VZ
268 // redirect log output to a FILE
269 wxLogStderr(FILE *fp = (FILE *) NULL);
c801d85f 270
03147cd0 271protected:
d6b9496a 272 // implement sink function
9e3d3318 273 virtual void DoLogString(const wxChar *szString, time_t t);
c801d85f 274
d6b9496a 275 FILE *m_fp;
c801d85f
KB
276};
277
4bf78aae 278#if wxUSE_STD_IOSTREAM
03147cd0 279
c801d85f
KB
280// log everything to an "ostream", cerr by default
281class WXDLLEXPORT wxLogStream : public wxLog
282{
283public:
d6b9496a 284 // redirect log output to an ostream
dd107c50 285 wxLogStream(wxSTD ostream *ostr = (wxSTD ostream *) NULL);
c801d85f
KB
286
287protected:
d6b9496a 288 // implement sink function
9e3d3318 289 virtual void DoLogString(const wxChar *szString, time_t t);
c801d85f 290
d6b9496a 291 // using ptr here to avoid including <iostream.h> from this file
dd107c50 292 wxSTD ostream *m_ostr;
c801d85f 293};
03147cd0
VZ
294
295#endif // wxUSE_STD_IOSTREAM
c801d85f 296
03147cd0
VZ
297// ----------------------------------------------------------------------------
298// /dev/null log target: suppress logging until this object goes out of scope
299// ----------------------------------------------------------------------------
300
301// example of usage:
302/*
303 void Foo()
304 {
305 wxFile file;
306
307 // wxFile.Open() normally complains if file can't be opened, we don't
308 // want it
309 wxLogNull logNo;
310
311 if ( !file.Open("bar") )
312 ... process error ourselves ...
313
314 // ~wxLogNull called, old log sink restored
315 }
316 */
317class WXDLLEXPORT wxLogNull
318{
319public:
be52b341
GD
320 wxLogNull() : m_flagOld(wxLog::EnableLogging(FALSE)) { }
321 ~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld); }
03147cd0
VZ
322
323private:
324 bool m_flagOld; // the previous value of the wxLog::ms_doLog
325};
326
327// ----------------------------------------------------------------------------
328// chaining log target: installs itself as a log target and passes all
329// messages to the real log target given to it in the ctor but also forwards
330// them to the previously active one
331//
332// note that you don't have to call SetActiveTarget() with this class, it
333// does it itself in its ctor
334// ----------------------------------------------------------------------------
335
336class WXDLLEXPORT wxLogChain : public wxLog
337{
338public:
339 wxLogChain(wxLog *logger);
8b30a4e4 340 virtual ~wxLogChain();
03147cd0
VZ
341
342 // change the new log target
343 void SetLog(wxLog *logger);
344
345 // this can be used to temporarily disable (and then reenable) passing
346 // messages to the old logger (by default we do pass them)
347 void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; }
348
349 // are we passing the messages to the previous log target?
350 bool IsPassingMessages() const { return m_bPassMessages; }
351
352 // return the previous log target (may be NULL)
353 wxLog *GetOldLog() const { return m_logOld; }
354
355 // override base class version to flush the old logger as well
356 virtual void Flush();
357
358protected:
359 // pass the chain to the old logger if needed
360 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t);
361
362private:
363 // the current log target
364 wxLog *m_logNew;
365
366 // the previous log target
367 wxLog *m_logOld;
368
369 // do we pass the messages to the old logger?
370 bool m_bPassMessages;
22f3361e
VZ
371
372 DECLARE_NO_COPY_CLASS(wxLogChain)
03147cd0
VZ
373};
374
375// a chain log target which uses itself as the new logger
376class WXDLLEXPORT wxLogPassThrough : public wxLogChain
377{
378public:
93d4c1d0 379 wxLogPassThrough();
03147cd0
VZ
380};
381
8ca28fb7
VZ
382// ----------------------------------------------------------------------------
383// the following log targets are only compiled in if the we're compiling the
384// GUI part (andnot just the base one) of the library, they're implemented in
385// src/generic/logg.cpp *and not src/common/log.cpp unlike all the rest)
386// ----------------------------------------------------------------------------
387
388#if wxUSE_GUI
389
390#if wxUSE_TEXTCTRL
391
392// log everything to a text window (GUI only of course)
393class WXDLLEXPORT wxLogTextCtrl : public wxLog
394{
395public:
396 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
397
398private:
399 // implement sink function
400 virtual void DoLogString(const wxChar *szString, time_t t);
401
402 // the control we use
403 wxTextCtrl *m_pTextCtrl;
22f3361e
VZ
404
405 DECLARE_NO_COPY_CLASS(wxLogTextCtrl)
8ca28fb7
VZ
406};
407
408#endif // wxUSE_TEXTCTRL
409
c801d85f
KB
410// ----------------------------------------------------------------------------
411// GUI log target, the default one for wxWindows programs
412// ----------------------------------------------------------------------------
1e6feb95
VZ
413
414#if wxUSE_LOGGUI
415
c801d85f
KB
416class WXDLLEXPORT wxLogGui : public wxLog
417{
418public:
d6b9496a
VZ
419 // ctor
420 wxLogGui();
c801d85f 421
d6b9496a
VZ
422 // show all messages that were logged since the last Flush()
423 virtual void Flush();
c801d85f
KB
424
425protected:
9e3d3318 426 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t);
d6b9496a
VZ
427
428 // empty everything
429 void Clear();
c801d85f 430
f1df0927
VZ
431 wxArrayString m_aMessages; // the log message texts
432 wxArrayInt m_aSeverity; // one of wxLOG_XXX values
433 wxArrayLong m_aTimes; // the time of each message
d6b9496a 434 bool m_bErrors, // do we have any errors?
1ec5cbf3
VZ
435 m_bWarnings, // any warnings?
436 m_bHasMessages; // any messages at all?
437
c801d85f
KB
438};
439
1e6feb95
VZ
440#endif // wxUSE_LOGGUI
441
9ef3052c
VZ
442// ----------------------------------------------------------------------------
443// (background) log window: this class forwards all log messages to the log
444// target which was active when it was instantiated, but also collects them
445// to the log window. This window has it's own menu which allows the user to
446// close it, clear the log contents or save it to the file.
447// ----------------------------------------------------------------------------
1e6feb95
VZ
448
449#if wxUSE_LOGWINDOW
450
03147cd0 451class WXDLLEXPORT wxLogWindow : public wxLogPassThrough
9ef3052c
VZ
452{
453public:
d6b9496a 454 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
03147cd0
VZ
455 const wxChar *szTitle, // the title of the frame
456 bool bShow = TRUE, // show window immediately?
457 bool bPassToOld = TRUE); // pass messages to the old target?
458
d6b9496a 459 ~wxLogWindow();
06db8ebd 460
d6b9496a 461 // window operations
f6bcfd97 462 // show/hide the log window
d6b9496a 463 void Show(bool bShow = TRUE);
f6bcfd97 464 // retrieve the pointer to the frame
d6b9496a 465 wxFrame *GetFrame() const;
9ef3052c 466
d6b9496a 467 // overridables
f6bcfd97
BP
468 // called immediately after the log frame creation allowing for
469 // any extra initializations
d6b9496a 470 virtual void OnFrameCreate(wxFrame *frame);
f6bcfd97
BP
471 // called if the user closes the window interactively, will not be
472 // called if it is destroyed for another reason (such as when program
473 // exits) - return TRUE from here to allow the frame to close, FALSE
474 // to prevent this from happening
475 virtual bool OnFrameClose(wxFrame *frame);
476 // called right before the log frame is going to be deleted: will
477 // always be called unlike OnFrameClose()
d6b9496a 478 virtual void OnFrameDelete(wxFrame *frame);
fe7b1156 479
9ef3052c 480protected:
9e3d3318
OK
481 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t);
482 virtual void DoLogString(const wxChar *szString, time_t t);
06db8ebd 483
9ef3052c 484private:
d6b9496a 485 wxLogFrame *m_pLogFrame; // the log frame
22f3361e
VZ
486
487 DECLARE_NO_COPY_CLASS(wxLogWindow)
9ef3052c
VZ
488};
489
1e6feb95
VZ
490#endif // wxUSE_LOGWINDOW
491
e90c1d2a 492#endif // wxUSE_GUI
03f38c58 493
c801d85f
KB
494// ============================================================================
495// global functions
496// ============================================================================
497
498// ----------------------------------------------------------------------------
499// Log functions should be used by application instead of stdio, iostream &c
500// for log messages for easy redirection
501// ----------------------------------------------------------------------------
502
88ac883a
VZ
503// ----------------------------------------------------------------------------
504// get error code/error message from system in a portable way
505// ----------------------------------------------------------------------------
506
507// return the last system error code
508WXDLLEXPORT unsigned long wxSysErrorCode();
c11d62a6 509
88ac883a
VZ
510// return the error message for given (or last if 0) error code
511WXDLLEXPORT const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0);
512
c11d62a6 513// ----------------------------------------------------------------------------
c801d85f 514// define wxLog<level>
c11d62a6 515// ----------------------------------------------------------------------------
c801d85f 516
c801d85f 517#define DECLARE_LOG_FUNCTION(level) \
1d63fd6b 518extern void WXDLLEXPORT wxVLog##level(const wxChar *szFormat, \
ea44a631 519 va_list argptr); \
7357f981
GD
520extern void WXDLLEXPORT wxLog##level(const wxChar *szFormat, \
521 ...) ATTRIBUTE_PRINTF_1
a1530845 522#define DECLARE_LOG_FUNCTION2(level, arg1) \
1d63fd6b 523extern void WXDLLEXPORT wxVLog##level(arg1, const wxChar *szFormat, \
ea44a631 524 va_list argptr); \
7357f981
GD
525extern void WXDLLEXPORT wxLog##level(arg1, const wxChar *szFormat, \
526 ...) ATTRIBUTE_PRINTF_2
a1530845 527
88ac883a
VZ
528#else // !wxUSE_LOG
529
530// log functions do nothing at all
531#define DECLARE_LOG_FUNCTION(level) \
1d63fd6b 532inline void WXDLLEXPORT wxVLog##level(const wxChar *szFormat, \
ea44a631 533 va_list argptr) {} \
546db2a8 534inline void WXDLLEXPORT wxLog##level(const wxChar *szFormat, ...) {}
88ac883a 535#define DECLARE_LOG_FUNCTION2(level, arg1) \
1d63fd6b 536inline void WXDLLEXPORT wxVLog##level(arg1, const wxChar *szFormat, \
ea44a631 537 va_list argptr) {} \
546db2a8 538inline void WXDLLEXPORT wxLog##level(arg1, const wxChar *szFormat, ...) {}
88ac883a 539
e30285ab
VZ
540// Empty Class to fake wxLogNull
541class WXDLLEXPORT wxLogNull
542{
543public:
544 wxLogNull() {}
545};
546
547// Dummy macros to replace some functions.
548#define wxSysErrorCode() (unsigned long)0
549#define wxSysErrorMsg( X ) (const wxChar*)NULL
550
551// Fake symbolic trace masks... for those that are used frequently
552#define wxTRACE_OleCalls wxT("") // OLE interface calls
553
88ac883a 554#endif // wxUSE_LOG/!wxUSE_LOG
c801d85f 555
88ac883a
VZ
556// a generic function for all levels (level is passes as parameter)
557DECLARE_LOG_FUNCTION2(Generic, wxLogLevel level);
c801d85f 558
88ac883a
VZ
559// one function per each level
560DECLARE_LOG_FUNCTION(FatalError);
561DECLARE_LOG_FUNCTION(Error);
562DECLARE_LOG_FUNCTION(Warning);
563DECLARE_LOG_FUNCTION(Message);
564DECLARE_LOG_FUNCTION(Info);
565DECLARE_LOG_FUNCTION(Verbose);
470b7da3 566
88ac883a
VZ
567// this function sends the log message to the status line of the top level
568// application frame, if any
569DECLARE_LOG_FUNCTION(Status);
470b7da3 570
88ac883a
VZ
571// this one is the same as previous except that it allows to explicitly
572// specify the frame to which the output should go
573DECLARE_LOG_FUNCTION2(Status, wxFrame *pFrame);
c801d85f 574
88ac883a
VZ
575// additional one: as wxLogError, but also logs last system call error code
576// and the corresponding error message if available
577DECLARE_LOG_FUNCTION(SysError);
c801d85f 578
88ac883a
VZ
579// and another one which also takes the error code (for those broken APIs
580// that don't set the errno (like registry APIs in Win32))
581DECLARE_LOG_FUNCTION2(SysError, long lErrCode);
582
583// debug functions do nothing in release mode
edc73852 584#if wxUSE_LOG_DEBUG
d6b9496a
VZ
585 DECLARE_LOG_FUNCTION(Debug);
586
ea44a631 587 // first kind of LogTrace is unconditional: it doesn't check the level,
d6b9496a
VZ
588 DECLARE_LOG_FUNCTION(Trace);
589
590 // this second version will only log the message if the mask had been
591 // added to the list of masks with AddTraceMask()
f6bcfd97 592 DECLARE_LOG_FUNCTION2(Trace, const wxChar *mask);
9ef3052c 593
d6b9496a
VZ
594 // the last one does nothing if all of level bits are not set
595 // in wxLog::GetActive()->GetTraceMask() - it's deprecated in favour of
596 // string identifiers
597 DECLARE_LOG_FUNCTION2(Trace, wxTraceMask mask);
9ef3052c 598#else //!debug
d6b9496a 599 // these functions do nothing in release builds
1d63fd6b 600 inline void wxVLogDebug(const wxChar *, va_list) { }
9e3d3318 601 inline void wxLogDebug(const wxChar *, ...) { }
1d63fd6b 602 inline void wxVLogTrace(const wxChar *, va_list) { }
9e3d3318 603 inline void wxLogTrace(const wxChar *, ...) { }
1d63fd6b 604 inline void wxVLogTrace(wxTraceMask, const wxChar *, va_list) { }
9e3d3318 605 inline void wxLogTrace(wxTraceMask, const wxChar *, ...) { }
1d63fd6b 606 inline void wxVLogTrace(const wxChar *, const wxChar *, va_list) { }
9e3d3318 607 inline void wxLogTrace(const wxChar *, const wxChar *, ...) { }
88ac883a 608#endif // debug/!debug
c801d85f 609
c11d62a6
VZ
610// wxLogFatalError helper: show the (fatal) error to the user in a safe way,
611// i.e. without using wxMessageBox() for example because it could crash
64bea2bf 612void WXDLLEXPORT wxSafeShowMessage(const wxString& title, const wxString& text);
c11d62a6 613
88ac883a
VZ
614// ----------------------------------------------------------------------------
615// debug only logging functions: use them with API name and error code
616// ----------------------------------------------------------------------------
c801d85f 617
e90babdf 618#ifdef __WXDEBUG__
42e69d6b
VZ
619 // make life easier for people using VC++ IDE: clicking on the message
620 // will take us immediately to the place of the failed API
621#ifdef __VISUALC__
4b7f2165
VZ
622 #define wxLogApiError(api, rc) \
623 wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
8b94d999
VZ
624 __TFILE__, __LINE__, api, \
625 (long)rc, wxSysErrorMsg(rc))
42e69d6b 626#else // !VC++
4b7f2165
VZ
627 #define wxLogApiError(api, rc) \
628 wxLogDebug(wxT("In file %s at line %d: '%s' failed with " \
8b94d999
VZ
629 "error 0x%08lx (%s)."), \
630 __TFILE__, __LINE__, api, \
631 (long)rc, wxSysErrorMsg(rc))
42e69d6b
VZ
632#endif // VC++/!VC++
633
634 #define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
635
c801d85f 636#else //!debug
9e3d3318
OK
637 inline void wxLogApiError(const wxChar *, long) { }
638 inline void wxLogLastError(const wxChar *) { }
c801d85f
KB
639#endif //debug/!debug
640
34138703 641#endif // _WX_LOG_H_
04662def 642