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     // change log target, pLogger may be NULL
 
  84     static wxLog *SetActiveTarget(wxLog *pLogger);
 
  86     // suspend the message flushing of the main target until the next call
 
  87     // to Resume() - this is mainly for internal use (to prevent wxYield()
 
  88     // from flashing the messages)
 
  89     static void Suspend();
 
  91     // must be called for each Suspend()!
 
  95     // verbose mode is activated by standard command-line '-verbose'
 
  97     static void SetVerbose(bool bVerbose = true);
 
  99     // Set log level.  Log messages with level > logLevel will not be logged.
 
 100     static void SetLogLevel(wxLogLevel logLevel);
 
 102     // should GetActiveTarget() try to create a new log object if the
 
 104     static void DontCreateOnDemand();
 
 106     // trace mask (see wxTraceXXX constants for details)
 
 107     static void SetTraceMask(wxTraceMask ulMask);
 
 109     // add string trace mask
 
 110     static void AddTraceMask(const wxString& str);
 
 112     // remove string trace mask
 
 113     static void RemoveTraceMask(const wxString& str);
 
 115     // remove all string trace masks
 
 116     static void ClearTraceMasks();
 
 118     // get string trace masks
 
 119     static const wxArrayString &GetTraceMasks();
 
 121     // sets the timestamp string: this is used as strftime() format string
 
 122     // for the log targets which add time stamps to the messages - set it
 
 123     // to NULL to disable time stamping completely.
 
 124     static void SetTimestamp(const wxChar *ts);
 
 127     // gets the verbose status
 
 128     static bool GetVerbose();
 
 131     static wxTraceMask GetTraceMask();
 
 133     // is this trace mask in the list?
 
 134     static bool IsAllowedTraceMask(const wxChar *mask);
 
 136     // return the current loglevel limit
 
 137     static wxLogLevel GetLogLevel();
 
 140     // get the current timestamp format string (may be NULL)
 
 141     static const wxChar *GetTimestamp();
 
 145         static wxString TimeStamp() {
 
 147             wxLog::TimeStamp(&msg);
 
 152     %extend { void Destroy() { delete self; } }
 
 156 //---------------------------------------------------------------------------
 
 159 class wxLogStderr : public wxLog
 
 162     wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
 
 166 class wxLogTextCtrl : public wxLog
 
 169     wxLogTextCtrl(wxTextCtrl *pTextCtrl);
 
 173 class wxLogGui : public wxLog
 
 179 class wxLogWindow : public wxLog
 
 182     wxLogWindow(wxFrame *pParent,         // the parent frame (can be NULL)
 
 183             const wxString& szTitle,      // the title of the frame
 
 184             bool bShow = true,            // show window immediately?
 
 185             bool bPassToOld = true);      // pass log messages to the old target?
 
 187     void Show(bool bShow = true);
 
 188     wxFrame *GetFrame() const;
 
 189     wxLog *GetOldLog() const;
 
 190     bool IsPassingMessages() const;
 
 191     void PassMessages(bool bDoPass);
 
 195 class wxLogChain : public wxLog
 
 198     wxLogChain(wxLog *logger);
 
 199     void SetLog(wxLog *logger);
 
 200     void PassMessages(bool bDoPass);
 
 201     bool IsPassingMessages();
 
 206 //---------------------------------------------------------------------------
 
 208 unsigned long wxSysErrorCode();
 
 209 const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
 
 210 void wxLogFatalError(const wxString& msg);
 
 211 void wxLogError(const wxString& msg);
 
 212 void wxLogWarning(const wxString& msg);
 
 213 void wxLogMessage(const wxString& msg);
 
 214 void wxLogInfo(const wxString& msg);
 
 215 void wxLogDebug(const wxString& msg);
 
 216 void wxLogVerbose(const wxString& msg);
 
 217 void wxLogStatus(const wxString& msg);
 
 218 %name(LogStatusFrame)void wxLogStatus(wxFrame *pFrame, const wxString& msg);
 
 219 void wxLogSysError(const wxString& msg);
 
 221 %nokwargs wxLogTrace;
 
 222 void wxLogTrace(unsigned long mask, const wxString& msg);
 
 223 void wxLogTrace(const wxString& mask, const wxString& msg);
 
 225 void wxLogGeneric(unsigned long level, const wxString& msg);
 
 227 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
 
 228 // i.e. without using wxMessageBox() for example because it could crash
 
 229 void wxSafeShowMessage(const wxString& title, const wxString& text);
 
 233 // Suspress logging while an instance of this class exists
 
 243 //---------------------------------------------------------------------------
 
 246 // A wxLog class that can be derived from in wxPython
 
 247 class wxPyLog : public wxLog {
 
 249     wxPyLog() : wxLog() {}
 
 251     virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
 
 253         bool blocked = wxPyBeginBlockThreads();
 
 254         if ((found = wxPyCBH_findCallback(m_myInst, "DoLog"))) {
 
 255             PyObject* s = wx2PyString(szString);
 
 256             wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level, s, t));
 
 259         wxPyEndBlockThreads(blocked);
 
 261             wxLog::DoLog(level, szString, t);
 
 264     virtual void DoLogString(const wxChar *szString, time_t t) {
 
 266         bool blocked = wxPyBeginBlockThreads();
 
 267         if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString"))) {
 
 268             PyObject* s = wx2PyString(szString);
 
 269             wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", s, t));
 
 272         wxPyEndBlockThreads(blocked);
 
 274             wxLog::DoLogString(szString, t);
 
 281 // Now tell SWIG about it
 
 282 class wxPyLog : public wxLog {
 
 284     %pythonAppend wxPyLog   "self._setCallbackInfo(self, PyLog)"
 
 288     void _setCallbackInfo(PyObject* self, PyObject* _class);
 
 291 //---------------------------------------------------------------------------