- enum Level
- {
- FatalError, // program can't continue, abort immediately
- Error, // a serious error, user must be informed about it
- Warning, // warning: user is normally informed about but may ignore it
- Message, // normal message (i.e. normal output of a non GUI app)
- Info, // informational message (a.k.a. 'Verbose')
- Status, // informational: might go to the status line of GUI app
- Debug, // never shown to the user, disabled in release mode
- Trace, // trace messages are also only enabled in debug mode
- Progress, // used for progress indicator (not yet)
- User1, // user defined levels (use with wxLogGeneric(wxLog::User1,...)
- User2, //
- User3, //
- };
-
- // ctor
- wxLog();
-
- // sink function
- static void OnLog(Level level, const char *szString)
- { if ( ms_pLogger != 0 ) ms_pLogger->DoLog(level, szString); }
-
- // message buffering
- // flush shows all messages if they're not logged immediately
- // (FILE and iostream logs don't need it, but wxGuiLog does to avoid
- // showing 17 modal dialogs one after another)
- virtual void Flush();
- // call Flush() only if this function returns true
- bool HasPendingMessages() const { return m_bHasMessages; }
-
- // only one sink is active at each moment
- // get current log target
- static wxLog *GetActiveTarget();
- // change log target, pLogger = NULL disables logging,
- // returns the previous log target
- static wxLog *SetActiveTarget(wxLog *pLogger);
-
- // functions controlling the default wxLog behaviour
- // verbose mode is activated by standard command-line '-verbose' option
- static void SetVerbose(bool bVerbose = TRUE) { ms_bVerbose = bVerbose; }
- // sets the format for timestamp prepended by wxLog::DoLog(): it's
- // passed to strftime() function, see it's documentation for details.
- // the string is not copied!
- static void SetTimeStampFormat(const char *szTimeFormat)
- { ms_szTimeFormat = szTimeFormat; }
-
- // accessors
- // gets the verbose status
- static bool GetVerbose() { return ms_bVerbose; }
-
- // make dtor virtual for all derived classes
- virtual ~wxLog() { }
+ // ctor
+ wxLog();
+
+ // these functions allow to completely disable all log messages
+ // is logging disabled now?
+ static bool IsEnabled() { return ms_doLog; }
+ // change the flag state, return the previous one
+ static bool EnableLogging(bool doIt = TRUE)
+ { bool doLogOld = ms_doLog; ms_doLog = doIt; return doLogOld; }
+
+ // static sink function - see DoLog() for function to overload in the
+ // derived classes
+ static void OnLog(wxLogLevel level, const wxChar *szString, time_t t)
+ {
+ if ( IsEnabled() ) {
+ wxLog *pLogger = GetActiveTarget();
+ if ( pLogger )
+ pLogger->DoLog(level, szString, t);
+ }
+ }
+
+ // message buffering
+ // flush shows all messages if they're not logged immediately (FILE
+ // and iostream logs don't need it, but wxGuiLog does to avoid showing
+ // 17 modal dialogs one after another)
+ virtual void Flush();
+ // call to Flush() may be optimized: call it only if this function
+ // returns true (although Flush() also returns immediately if there is
+ // no messages, this functions is more efficient because inline)
+ bool HasPendingMessages() const { return m_bHasMessages; }
+
+ // only one sink is active at each moment
+ // flush the active target if any
+ static void FlushActive()
+ {
+ wxLog *log = GetActiveTarget();
+ if ( log )
+ log->Flush();
+ }
+ // get current log target, will call wxApp::CreateLogTarget() to
+ // create one if none exists
+ static wxLog *GetActiveTarget();
+ // change log target, pLogger may be NULL
+ static wxLog *SetActiveTarget(wxLog *pLogger);
+
+ // functions controlling the default wxLog behaviour
+ // verbose mode is activated by standard command-line '-verbose'
+ // option
+ void SetVerbose(bool bVerbose = TRUE) { m_bVerbose = bVerbose; }
+ // should GetActiveTarget() try to create a new log object if the
+ // current is NULL?
+ static void DontCreateOnDemand() { ms_bAutoCreate = FALSE; }
+
+ // trace mask (see wxTraceXXX constants for details)
+ static void SetTraceMask(wxTraceMask ulMask) { ms_ulTraceMask = ulMask; }
+ // add string trace mask
+ static void AddTraceMask(const wxString& str) { ms_aTraceMasks.Add(str); }
+ // add string trace mask
+ static void RemoveTraceMask(const wxString& str);
+
+ // sets the timestamp string: this is used as strftime() format string
+ // for the log targets which add time stamps to the messages - set it
+ // to NULL to disable time stamping completely.
+ static void SetTimestamp(const wxChar *ts) { ms_timestamp = ts; }
+
+ // accessors
+ // gets the verbose status
+ bool GetVerbose() const { return m_bVerbose; }
+ // get trace mask
+ static wxTraceMask GetTraceMask() { return ms_ulTraceMask; }
+ // is this trace mask in the list?
+ static bool IsAllowedTraceMask(const wxChar *mask)
+ { return ms_aTraceMasks.Index(mask) != wxNOT_FOUND; }
+
+ // get the current timestamp format string (may be NULL)
+ static const wxChar *GetTimestamp() { return ms_timestamp; }
+
+ // helpers
+ // put the time stamp into the string if ms_timestamp != NULL (don't
+ // change it otherwise)
+ static void TimeStamp(wxString *str);
+
+ // make dtor virtual for all derived classes
+ virtual ~wxLog() { }