log.h
来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C头文件 代码 · 共 611 行 · 第 1/2 页
H
611 行
virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t);
virtual void DoLogString(const wxChar *szString, time_t t);
private:
wxString m_str;
DECLARE_NO_COPY_CLASS(wxLogBuffer)
};
#endif // wxABI_VERSION
// log everything to a "FILE *", stderr by default
class WXDLLIMPEXP_BASE wxLogStderr : public wxLog
{
public:
// redirect log output to a FILE
wxLogStderr(FILE *fp = (FILE *) NULL);
protected:
// implement sink function
virtual void DoLogString(const wxChar *szString, time_t t);
FILE *m_fp;
DECLARE_NO_COPY_CLASS(wxLogStderr)
};
#if wxUSE_STD_IOSTREAM
// log everything to an "ostream", cerr by default
class WXDLLIMPEXP_BASE wxLogStream : public wxLog
{
public:
// redirect log output to an ostream
wxLogStream(wxSTD ostream *ostr = (wxSTD ostream *) NULL);
protected:
// implement sink function
virtual void DoLogString(const wxChar *szString, time_t t);
// using ptr here to avoid including <iostream.h> from this file
wxSTD ostream *m_ostr;
};
#endif // wxUSE_STD_IOSTREAM
// ----------------------------------------------------------------------------
// /dev/null log target: suppress logging until this object goes out of scope
// ----------------------------------------------------------------------------
// example of usage:
/*
void Foo()
{
wxFile file;
// wxFile.Open() normally complains if file can't be opened, we don't
// want it
wxLogNull logNo;
if ( !file.Open("bar") )
... process error ourselves ...
// ~wxLogNull called, old log sink restored
}
*/
class WXDLLIMPEXP_BASE wxLogNull
{
public:
wxLogNull() : m_flagOld(wxLog::EnableLogging(false)) { }
~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld); }
private:
bool m_flagOld; // the previous value of the wxLog::ms_doLog
};
// ----------------------------------------------------------------------------
// chaining log target: installs itself as a log target and passes all
// messages to the real log target given to it in the ctor but also forwards
// them to the previously active one
//
// note that you don't have to call SetActiveTarget() with this class, it
// does it itself in its ctor
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxLogChain : public wxLog
{
public:
wxLogChain(wxLog *logger);
virtual ~wxLogChain();
// change the new log target
void SetLog(wxLog *logger);
// this can be used to temporarily disable (and then reenable) passing
// messages to the old logger (by default we do pass them)
void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; }
// are we passing the messages to the previous log target?
bool IsPassingMessages() const { return m_bPassMessages; }
// return the previous log target (may be NULL)
wxLog *GetOldLog() const { return m_logOld; }
// override base class version to flush the old logger as well
virtual void Flush();
protected:
// pass the chain to the old logger if needed
virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t);
private:
// the current log target
wxLog *m_logNew;
// the previous log target
wxLog *m_logOld;
// do we pass the messages to the old logger?
bool m_bPassMessages;
DECLARE_NO_COPY_CLASS(wxLogChain)
};
// a chain log target which uses itself as the new logger
class WXDLLIMPEXP_BASE wxLogPassThrough : public wxLogChain
{
public:
wxLogPassThrough();
private:
DECLARE_NO_COPY_CLASS(wxLogPassThrough)
};
#if wxUSE_GUI
// include GUI log targets:
#include "wx/generic/logg.h"
#endif // wxUSE_GUI
// ============================================================================
// global functions
// ============================================================================
// ----------------------------------------------------------------------------
// Log functions should be used by application instead of stdio, iostream &c
// for log messages for easy redirection
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// get error code/error message from system in a portable way
// ----------------------------------------------------------------------------
// return the last system error code
WXDLLIMPEXP_BASE unsigned long wxSysErrorCode();
// return the error message for given (or last if 0) error code
WXDLLIMPEXP_BASE const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0);
// ----------------------------------------------------------------------------
// define wxLog<level>
// ----------------------------------------------------------------------------
#define DECLARE_LOG_FUNCTION(level) \
extern void WXDLLIMPEXP_BASE wxVLog##level(const wxChar *szFormat, \
va_list argptr); \
extern void WXDLLIMPEXP_BASE wxLog##level(const wxChar *szFormat, \
...) ATTRIBUTE_PRINTF_1
#define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
extern void expdecl wxVLog##level(argclass arg, \
const wxChar *szFormat, \
va_list argptr); \
extern void expdecl wxLog##level(argclass arg, \
const wxChar *szFormat, \
...) ATTRIBUTE_PRINTF_2
#else // !wxUSE_LOG
// log functions do nothing at all
#define DECLARE_LOG_FUNCTION(level) \
inline void wxVLog##level(const wxChar *WXUNUSED(szFormat), \
va_list WXUNUSED(argptr)) { } \
inline void wxLog##level(const wxChar *WXUNUSED(szFormat), \
...) { }
#define DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, expdecl) \
inline void wxVLog##level(argclass WXUNUSED(arg), \
const wxChar *WXUNUSED(szFormat), \
va_list WXUNUSED(argptr)) {} \
inline void wxLog##level(argclass WXUNUSED(arg), \
const wxChar *WXUNUSED(szFormat), \
...) { }
// Empty Class to fake wxLogNull
class WXDLLIMPEXP_BASE wxLogNull
{
public:
wxLogNull() { }
};
// Dummy macros to replace some functions.
#define wxSysErrorCode() (unsigned long)0
#define wxSysErrorMsg( X ) (const wxChar*)NULL
// Fake symbolic trace masks... for those that are used frequently
#define wxTRACE_OleCalls wxEmptyString // OLE interface calls
#endif // wxUSE_LOG/!wxUSE_LOG
#define DECLARE_LOG_FUNCTION2(level, argclass, arg) \
DECLARE_LOG_FUNCTION2_EXP(level, argclass, arg, WXDLLIMPEXP_BASE)
// a generic function for all levels (level is passes as parameter)
DECLARE_LOG_FUNCTION2(Generic, wxLogLevel, level);
// one function per each level
DECLARE_LOG_FUNCTION(FatalError);
DECLARE_LOG_FUNCTION(Error);
DECLARE_LOG_FUNCTION(Warning);
DECLARE_LOG_FUNCTION(Message);
DECLARE_LOG_FUNCTION(Info);
DECLARE_LOG_FUNCTION(Verbose);
// this function sends the log message to the status line of the top level
// application frame, if any
DECLARE_LOG_FUNCTION(Status);
#if wxUSE_GUI
// this one is the same as previous except that it allows to explicitly
class WXDLLEXPORT wxFrame;
// specify the frame to which the output should go
DECLARE_LOG_FUNCTION2_EXP(Status, wxFrame *, pFrame, WXDLLIMPEXP_CORE);
#endif // wxUSE_GUI
// additional one: as wxLogError, but also logs last system call error code
// and the corresponding error message if available
DECLARE_LOG_FUNCTION(SysError);
// and another one which also takes the error code (for those broken APIs
// that don't set the errno (like registry APIs in Win32))
DECLARE_LOG_FUNCTION2(SysError, long, lErrCode);
// debug functions do nothing in release mode
#if wxUSE_LOG_DEBUG
DECLARE_LOG_FUNCTION(Debug);
// there is no more unconditional LogTrace: it is not different from
// LogDebug and it creates overload ambiguities
//DECLARE_LOG_FUNCTION(Trace);
// this version only logs the message if the mask had been added to the
// list of masks with AddTraceMask()
DECLARE_LOG_FUNCTION2(Trace, const wxChar *, mask);
// and this one does nothing if all of level bits are not set in
// wxLog::GetActive()->GetTraceMask() -- it's deprecated in favour of
// string identifiers
DECLARE_LOG_FUNCTION2(Trace, wxTraceMask, mask);
#else //!debug
// these functions do nothing in release builds
inline void wxVLogDebug(const wxChar *, va_list) { }
inline void wxLogDebug(const wxChar *, ...) { }
inline void wxVLogTrace(wxTraceMask, const wxChar *, va_list) { }
inline void wxLogTrace(wxTraceMask, const wxChar *, ...) { }
inline void wxVLogTrace(const wxChar *, const wxChar *, va_list) { }
inline void wxLogTrace(const wxChar *, const wxChar *, ...) { }
#endif // debug/!debug
// wxLogFatalError helper: show the (fatal) error to the user in a safe way,
// i.e. without using wxMessageBox() for example because it could crash
void WXDLLIMPEXP_BASE
wxSafeShowMessage(const wxString& title, const wxString& text);
// ----------------------------------------------------------------------------
// debug only logging functions: use them with API name and error code
// ----------------------------------------------------------------------------
#ifdef __WXDEBUG__
// make life easier for people using VC++ IDE: clicking on the message
// will take us immediately to the place of the failed API
#ifdef __VISUALC__
#define wxLogApiError(api, rc) \
wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
__TFILE__, __LINE__, api, \
(long)rc, wxSysErrorMsg(rc))
#else // !VC++
#define wxLogApiError(api, rc) \
wxLogDebug(wxT("In file %s at line %d: '%s' failed with ") \
wxT("error 0x%08lx (%s)."), \
__TFILE__, __LINE__, api, \
(long)rc, wxSysErrorMsg(rc))
#endif // VC++/!VC++
#define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
#else //!debug
inline void wxLogApiError(const wxChar *, long) { }
inline void wxLogLastError(const wxChar *) { }
#endif //debug/!debug
// wxCocoa has additiional trace masks
#if defined(__WXCOCOA__)
#include "wx/cocoa/log.h"
#endif
#endif // _WX_LOG_H_
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?