1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface stuff for wxLog
7 // Created: 18-June-1999
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
20 typedef unsigned long wxTraceMask;
21 typedef unsigned long wxLogLevel;
26 wxLOG_FatalError, // program can't continue, abort immediately
27 wxLOG_Error, // a serious error, user must be informed about it
28 wxLOG_Warning, // user is normally informed about it but may be ignored
29 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
30 wxLOG_Status, // informational: might go to the status line of GUI app
31 wxLOG_Info, // informational message (a.k.a. 'Verbose')
32 wxLOG_Debug, // never shown to the user, disabled in release mode
33 wxLOG_Trace, // trace messages are also only enabled in debug mode
34 wxLOG_Progress, // used for progress indicator (not yet)
35 wxLOG_User = 100, // user defined levels start here
39 #define wxTRACE_MemAlloc "memalloc" // trace memory allocation (new/delete)
40 #define wxTRACE_Messages "messages" // trace window messages/X callbacks
41 #define wxTRACE_ResAlloc "resalloc" // trace GDI resource allocation
42 #define wxTRACE_RefCount "refcount" // trace various ref counting operations
43 #define wxTRACE_OleCalls "ole" // OLE interface calls
45 #define wxTraceMemAlloc 0x0001 // trace memory allocation (new/delete)
46 #define wxTraceMessages 0x0002 // trace window messages/X callbacks
47 #define wxTraceResAlloc 0x0004 // trace GDI resource allocation
48 #define wxTraceRefCount 0x0008 // trace various ref counting operations
49 #define wxTraceOleCalls 0x0100 // OLE interface calls
51 //---------------------------------------------------------------------------
59 // these functions allow to completely disable all log messages
60 // is logging disabled now?
61 static bool IsEnabled();
63 // change the flag state, return the previous one
64 static bool EnableLogging(bool doIt = true);
66 // static sink function
67 static void OnLog(wxLogLevel level, const wxChar *szString, time_t t);
70 // flush shows all messages if they're not logged immediately (FILE
71 // and iostream logs don't need it, but wxGuiLog does to avoid showing
72 // 17 modal dialogs one after another)
75 // flush the active target if any
76 static void FlushActive();
78 // only one sink is active at each moment
79 // get current log target, will call wxApp::CreateLogTarget() to
80 // create one if none exists
81 static wxLog *GetActiveTarget();
83 %disownarg( wxLog* pLogger );
84 %newobject SetActiveTarget;
85 // change log target, pLogger may be NULL
86 static wxLog *SetActiveTarget(wxLog *pLogger);
87 %cleardisown( wxLog* pLogger );
89 // suspend the message flushing of the main target until the next call
90 // to Resume() - this is mainly for internal use (to prevent wxYield()
91 // from flashing the messages)
92 static void Suspend();
94 // must be called for each Suspend()!
98 // verbose mode is activated by standard command-line '-verbose'
100 static void SetVerbose(bool bVerbose = true);
102 // Set log level. Log messages with level > logLevel will not be logged.
103 static void SetLogLevel(wxLogLevel logLevel);
105 // should GetActiveTarget() try to create a new log object if the
107 static void DontCreateOnDemand();
109 // log the count of repeating messages instead of logging the messages
111 static void SetRepetitionCounting(bool bRepetCounting = true);
113 // gets duplicate counting status
114 static bool GetRepetitionCounting();
116 // trace mask (see wxTraceXXX constants for details)
117 static void SetTraceMask(wxTraceMask ulMask);
119 // add string trace mask
120 static void AddTraceMask(const wxString& str);
122 // remove string trace mask
123 static void RemoveTraceMask(const wxString& str);
125 // remove all string trace masks
126 static void ClearTraceMasks();
128 // get string trace masks
129 static const wxArrayString &GetTraceMasks();
131 // sets the timestamp string: this is used as strftime() format string
132 // for the log targets which add time stamps to the messages - set it
133 // to NULL to disable time stamping completely.
134 static void SetTimestamp(const wxChar *ts);
137 // gets the verbose status
138 static bool GetVerbose();
141 static wxTraceMask GetTraceMask();
143 // is this trace mask in the list?
144 static bool IsAllowedTraceMask(const wxChar *mask);
146 // return the current loglevel limit
147 static wxLogLevel GetLogLevel();
150 // get the current timestamp format string (may be NULL)
151 static const wxChar *GetTimestamp();
155 static wxString TimeStamp() {
157 wxLog::TimeStamp(&msg);
162 %pythonPrepend Destroy "args[0].this.own(False)";
163 %extend { void Destroy() { delete self; } }
167 //---------------------------------------------------------------------------
170 class wxLogStderr : public wxLog
173 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
177 class wxLogTextCtrl : public wxLog
180 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
184 class wxLogGui : public wxLog
190 class wxLogWindow : public wxLog
193 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
194 const wxString& szTitle, // the title of the frame
195 bool bShow = true, // show window immediately?
196 bool bPassToOld = true); // pass log messages to the old target?
198 void Show(bool bShow = true);
199 wxFrame *GetFrame() const;
200 wxLog *GetOldLog() const;
201 bool IsPassingMessages() const;
202 void PassMessages(bool bDoPass);
204 %property(Frame, GetFrame, doc="See `GetFrame`");
205 %property(OldLog, GetOldLog, doc="See `GetOldLog`");
209 class wxLogChain : public wxLog
212 wxLogChain(wxLog *logger);
213 void SetLog(wxLog *logger);
214 void PassMessages(bool bDoPass);
215 bool IsPassingMessages();
218 %property(OldLog, GetOldLog, doc="See `GetOldLog`");
221 // log everything to a buffer
222 class wxLogBuffer : public wxLog
227 // get the string contents with all messages logged
228 const wxString& GetBuffer() const;
230 // show the buffer contents to the user in the best possible way (this uses
231 // wxMessageOutputMessageBox) and clear it
232 virtual void Flush();
234 %property(Buffer, GetBuffer, doc="See `GetBuffer`");
238 //---------------------------------------------------------------------------
240 unsigned long wxSysErrorCode();
241 const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
243 %{// Make some wrappers that double any % signs so they are 'escaped'
244 void wxPyLogFatalError(const wxString& msg)
247 m.Replace(wxT("%"), wxT("%%"));
251 void wxPyLogError(const wxString& msg)
254 m.Replace(wxT("%"), wxT("%%"));
258 void wxPyLogWarning(const wxString& msg)
261 m.Replace(wxT("%"), wxT("%%"));
265 void wxPyLogMessage(const wxString& msg)
268 m.Replace(wxT("%"), wxT("%%"));
272 void wxPyLogInfo(const wxString& msg)
275 m.Replace(wxT("%"), wxT("%%"));
279 void wxPyLogDebug(const wxString& msg)
282 m.Replace(wxT("%"), wxT("%%"));
286 void wxPyLogVerbose(const wxString& msg)
289 m.Replace(wxT("%"), wxT("%%"));
293 void wxPyLogStatus(const wxString& msg)
296 m.Replace(wxT("%"), wxT("%%"));
300 void wxPyLogStatusFrame(wxFrame *pFrame, const wxString& msg)
303 m.Replace(wxT("%"), wxT("%%"));
304 wxLogStatus(pFrame, m);
307 void wxPyLogSysError(const wxString& msg)
310 m.Replace(wxT("%"), wxT("%%"));
314 void wxPyLogGeneric(unsigned long level, const wxString& msg)
317 m.Replace(wxT("%"), wxT("%%"));
318 wxLogGeneric(level, m);
321 void wxPyLogTrace(unsigned long mask, const wxString& msg)
324 m.Replace(wxT("%"), wxT("%%"));
328 void wxPyLogTrace(const wxString& mask, const wxString& msg)
331 m.Replace(wxT("%"), wxT("%%"));
337 %Rename(LogFatalError, void, wxPyLogFatalError(const wxString& msg));
338 %Rename(LogError, void, wxPyLogError(const wxString& msg));
339 %Rename(LogWarning, void, wxPyLogWarning(const wxString& msg));
340 %Rename(LogMessage, void, wxPyLogMessage(const wxString& msg));
341 %Rename(LogInfo, void, wxPyLogInfo(const wxString& msg));
342 %Rename(LogDebug, void, wxPyLogDebug(const wxString& msg));
343 %Rename(LogVerbose, void, wxPyLogVerbose(const wxString& msg));
344 %Rename(LogStatus, void, wxPyLogStatus(const wxString& msg));
345 %Rename(LogStatusFrame, void, wxPyLogStatusFrame(wxFrame *pFrame, const wxString& msg));
346 %Rename(LogSysError, void, wxPyLogSysError(const wxString& msg));
348 %Rename(LogGeneric, void, wxPyLogGeneric(unsigned long level, const wxString& msg));
350 %nokwargs wxPyLogTrace;
351 %Rename(LogTrace, void, wxPyLogTrace(unsigned long mask, const wxString& msg));
352 %Rename(LogTrace, void, wxPyLogTrace(const wxString& mask, const wxString& msg));
355 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
356 // i.e. without using wxMessageBox() for example because it could crash
357 void wxSafeShowMessage(const wxString& title, const wxString& text);
361 // Suspress logging while an instance of this class exists
371 //---------------------------------------------------------------------------
374 // A wxLog class that can be derived from in wxPython
375 class wxPyLog : public wxLog {
377 wxPyLog() : wxLog() {}
379 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
381 wxPyBlock_t blocked = wxPyBeginBlockThreads();
382 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog"))) {
383 PyObject* s = wx2PyString(szString);
384 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level, s, t));
387 wxPyEndBlockThreads(blocked);
389 wxLog::DoLog(level, szString, t);
392 virtual void DoLogString(const wxChar *szString, time_t t) {
394 wxPyBlock_t blocked = wxPyBeginBlockThreads();
395 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString"))) {
396 PyObject* s = wx2PyString(szString);
397 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", s, t));
400 wxPyEndBlockThreads(blocked);
402 wxLog::DoLogString(szString, t);
405 DEC_PYCALLBACK_VOID_(Flush);
408 IMP_PYCALLBACK_VOID_(wxPyLog, wxLog, Flush);
411 // Now tell SWIG about it
412 class wxPyLog : public wxLog {
414 %pythonAppend wxPyLog "self._setCallbackInfo(self, PyLog)"
418 void _setCallbackInfo(PyObject* self, PyObject* _class);
421 //---------------------------------------------------------------------------