1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2001-07-13 13:51:57 +00:00
|
|
|
// Name: wx/log.h
|
1998-05-20 14:01:55 +00:00
|
|
|
// Purpose: Assorted wxLogXXX functions, and wxLog (sink for logs)
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 29/01/98
|
|
|
|
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2003-07-02 01:41:23 +00:00
|
|
|
#ifndef _WX_LOG_H_
|
|
|
|
#define _WX_LOG_H_
|
1998-05-20 14:01:55 +00:00
|
|
|
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 19:52:35 +00:00
|
|
|
#include "wx/defs.h"
|
2013-08-31 17:41:16 +00:00
|
|
|
#include "wx/cpp.h"
|
1999-06-27 10:39:38 +00:00
|
|
|
|
2004-05-30 15:14:41 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2009-03-22 16:00:37 +00:00
|
|
|
// types
|
2004-05-30 15:14:41 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-03-22 16:00:37 +00:00
|
|
|
// NB: this is needed even if wxUSE_LOG == 0
|
|
|
|
typedef unsigned long wxLogLevel;
|
2004-05-30 15:14:41 +00:00
|
|
|
|
2009-03-22 16:00:37 +00:00
|
|
|
// the trace masks have been superseded by symbolic trace constants, they're
|
|
|
|
// for compatibility only and will be removed soon - do NOT use them
|
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
|
|
|
#define wxTraceMemAlloc 0x0001 // trace memory allocation (new/delete)
|
|
|
|
#define wxTraceMessages 0x0002 // trace window messages/X callbacks
|
|
|
|
#define wxTraceResAlloc 0x0004 // trace GDI resource allocation
|
|
|
|
#define wxTraceRefCount 0x0008 // trace various ref counting operations
|
2004-05-30 15:14:41 +00:00
|
|
|
|
2012-03-04 00:29:31 +00:00
|
|
|
#ifdef __WINDOWS__
|
2009-03-22 16:00:37 +00:00
|
|
|
#define wxTraceOleCalls 0x0100 // OLE interface calls
|
|
|
|
#endif
|
1999-06-01 22:46:59 +00:00
|
|
|
|
2009-03-22 16:00:37 +00:00
|
|
|
typedef unsigned long wxTraceMask;
|
|
|
|
#endif // WXWIN_COMPATIBILITY_2_8
|
1999-06-01 22:46:59 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-05-18 12:15:58 +00:00
|
|
|
#include "wx/string.h"
|
2007-03-17 10:26:10 +00:00
|
|
|
#include "wx/strvararg.h"
|
2004-05-18 12:15:58 +00:00
|
|
|
|
2009-08-18 01:22:57 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// forward declarations
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_FWD_BASE wxObject;
|
|
|
|
|
|
|
|
#if wxUSE_GUI
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxFrame;
|
|
|
|
#endif // wxUSE_GUI
|
|
|
|
|
2004-02-10 21:16:58 +00:00
|
|
|
#if wxUSE_LOG
|
|
|
|
|
|
|
|
#include "wx/arrstr.h"
|
|
|
|
|
2002-12-07 15:41:13 +00:00
|
|
|
#ifndef __WXWINCE__
|
2004-02-10 21:16:58 +00:00
|
|
|
#include <time.h> // for time_t
|
2002-12-07 15:41:13 +00:00
|
|
|
#endif
|
1999-03-29 21:18:49 +00:00
|
|
|
|
|
|
|
#include "wx/dynarray.h"
|
2009-07-09 20:26:34 +00:00
|
|
|
#include "wx/hashmap.h"
|
1999-03-29 20:49:05 +00:00
|
|
|
|
2009-07-08 13:47:33 +00:00
|
|
|
#if wxUSE_THREADS
|
|
|
|
#include "wx/thread.h"
|
|
|
|
#endif // wxUSE_THREADS
|
|
|
|
|
2009-03-22 17:18:07 +00:00
|
|
|
// wxUSE_LOG_DEBUG enables the debug log messages
|
2003-01-01 05:16:07 +00:00
|
|
|
#ifndef wxUSE_LOG_DEBUG
|
2009-03-22 15:40:08 +00:00
|
|
|
#if wxDEBUG_LEVEL
|
|
|
|
#define wxUSE_LOG_DEBUG 1
|
|
|
|
#else // !wxDEBUG_LEVEL
|
|
|
|
#define wxUSE_LOG_DEBUG 0
|
|
|
|
#endif
|
2003-01-01 05:16:07 +00:00
|
|
|
#endif
|
|
|
|
|
2009-03-22 17:18:07 +00:00
|
|
|
// wxUSE_LOG_TRACE enables the trace messages, they are disabled by default
|
|
|
|
#ifndef wxUSE_LOG_TRACE
|
2009-03-23 10:42:17 +00:00
|
|
|
#if wxDEBUG_LEVEL
|
2009-03-22 17:18:07 +00:00
|
|
|
#define wxUSE_LOG_TRACE 1
|
2009-03-23 10:42:17 +00:00
|
|
|
#else // !wxDEBUG_LEVEL
|
2009-03-22 17:18:07 +00:00
|
|
|
#define wxUSE_LOG_TRACE 0
|
|
|
|
#endif
|
|
|
|
#endif // wxUSE_LOG_TRACE
|
|
|
|
|
2009-07-12 14:56:23 +00:00
|
|
|
// wxLOG_COMPONENT identifies the component which generated the log record and
|
|
|
|
// can be #define'd to a user-defined value when compiling the user code to use
|
|
|
|
// component-based filtering (see wxLog::SetComponentLevel())
|
|
|
|
#ifndef wxLOG_COMPONENT
|
|
|
|
// this is a variable and not a macro in order to allow the user code to
|
|
|
|
// just #define wxLOG_COMPONENT without #undef'ining it first
|
|
|
|
extern WXDLLIMPEXP_DATA_BASE(const char *) wxLOG_COMPONENT;
|
|
|
|
|
|
|
|
#ifdef WXBUILDING
|
|
|
|
#define wxLOG_COMPONENT "wx"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
1998-05-26 15:11:46 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// different standard log levels (you may also define your own)
|
2007-03-23 09:31:07 +00:00
|
|
|
enum wxLogLevelValues
|
1998-05-26 15:11:46 +00:00
|
|
|
{
|
1999-03-29 20:49:05 +00:00
|
|
|
wxLOG_FatalError, // program can't continue, abort immediately
|
|
|
|
wxLOG_Error, // a serious error, user must be informed about it
|
|
|
|
wxLOG_Warning, // user is normally informed about it but may be ignored
|
|
|
|
wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
|
|
|
|
wxLOG_Status, // informational: might go to the status line of GUI app
|
2003-01-01 05:16:07 +00:00
|
|
|
wxLOG_Info, // informational message (a.k.a. 'Verbose')
|
1999-03-29 20:49:05 +00:00
|
|
|
wxLOG_Debug, // never shown to the user, disabled in release mode
|
|
|
|
wxLOG_Trace, // trace messages are also only enabled in debug mode
|
|
|
|
wxLOG_Progress, // used for progress indicator (not yet)
|
2003-01-01 05:16:07 +00:00
|
|
|
wxLOG_User = 100, // user defined levels start here
|
2003-01-01 22:50:02 +00:00
|
|
|
wxLOG_Max = 10000
|
1998-05-26 15:11:46 +00:00
|
|
|
};
|
|
|
|
|
1999-03-29 20:49:05 +00:00
|
|
|
// symbolic trace masks - wxLogTrace("foo", "some trace message...") will be
|
|
|
|
// discarded unless the string "foo" has been added to the list of allowed
|
|
|
|
// ones with AddTraceMask()
|
|
|
|
|
2000-01-03 18:53:10 +00:00
|
|
|
#define wxTRACE_MemAlloc wxT("memalloc") // trace memory allocation (new/delete)
|
|
|
|
#define wxTRACE_Messages wxT("messages") // trace window messages/X callbacks
|
|
|
|
#define wxTRACE_ResAlloc wxT("resalloc") // trace GDI resource allocation
|
|
|
|
#define wxTRACE_RefCount wxT("refcount") // trace various ref counting operations
|
1999-03-29 20:49:05 +00:00
|
|
|
|
2012-03-04 00:29:31 +00:00
|
|
|
#ifdef __WINDOWS__
|
2000-01-03 18:53:10 +00:00
|
|
|
#define wxTRACE_OleCalls wxT("ole") // OLE interface calls
|
1999-03-29 20:49:05 +00:00
|
|
|
#endif
|
|
|
|
|
2003-01-26 00:12:12 +00:00
|
|
|
#include "wx/iosfwrap.h"
|
1998-08-14 21:49:27 +00:00
|
|
|
|
2009-07-08 13:47:33 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// information about a log record, i.e. unit of log output
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
class wxLogRecordInfo
|
2009-07-08 13:47:33 +00:00
|
|
|
{
|
2009-07-09 20:26:34 +00:00
|
|
|
public:
|
|
|
|
// default ctor creates an uninitialized object
|
2009-07-08 13:47:33 +00:00
|
|
|
wxLogRecordInfo()
|
|
|
|
{
|
2009-07-12 14:56:23 +00:00
|
|
|
memset(this, 0, sizeof(*this));
|
2009-07-09 20:26:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// normal ctor, used by wxLogger specifies the location of the log
|
|
|
|
// statement; its time stamp and thread id are set up here
|
|
|
|
wxLogRecordInfo(const char *filename_,
|
|
|
|
int line_,
|
2009-07-12 14:56:23 +00:00
|
|
|
const char *func_,
|
|
|
|
const char *component_)
|
2009-07-09 20:26:34 +00:00
|
|
|
{
|
|
|
|
filename = filename_;
|
|
|
|
func = func_;
|
|
|
|
line = line_;
|
2009-07-12 14:56:23 +00:00
|
|
|
component = component_;
|
2009-07-09 20:26:34 +00:00
|
|
|
|
|
|
|
timestamp = time(NULL);
|
2009-07-08 13:47:33 +00:00
|
|
|
|
|
|
|
#if wxUSE_THREADS
|
2009-07-09 20:26:34 +00:00
|
|
|
threadId = wxThread::GetCurrentId();
|
2009-07-08 13:47:33 +00:00
|
|
|
#endif // wxUSE_THREADS
|
2009-07-09 20:26:34 +00:00
|
|
|
|
|
|
|
m_data = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we need to define copy ctor and assignment operator because of m_data
|
|
|
|
wxLogRecordInfo(const wxLogRecordInfo& other)
|
|
|
|
{
|
|
|
|
Copy(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxLogRecordInfo& operator=(const wxLogRecordInfo& other)
|
|
|
|
{
|
|
|
|
if ( &other != this )
|
|
|
|
{
|
|
|
|
delete m_data;
|
|
|
|
Copy(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
2009-07-08 13:47:33 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
// dtor is non-virtual, this class is not meant to be derived from
|
|
|
|
~wxLogRecordInfo()
|
|
|
|
{
|
|
|
|
delete m_data;
|
|
|
|
}
|
2009-07-08 13:47:33 +00:00
|
|
|
|
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
// the file name and line number of the file where the log record was
|
|
|
|
// generated, if available or NULL and 0 otherwise
|
|
|
|
const char *filename;
|
|
|
|
int line;
|
|
|
|
|
|
|
|
// the name of the function where the log record was generated (may be NULL
|
|
|
|
// if the compiler doesn't support __FUNCTION__)
|
|
|
|
const char *func;
|
|
|
|
|
2009-07-12 14:56:23 +00:00
|
|
|
// the name of the component which generated this message, may be NULL if
|
|
|
|
// not set (i.e. wxLOG_COMPONENT not defined)
|
|
|
|
const char *component;
|
|
|
|
|
2009-07-08 13:47:33 +00:00
|
|
|
// time of record generation
|
|
|
|
time_t timestamp;
|
|
|
|
|
|
|
|
#if wxUSE_THREADS
|
|
|
|
// id of the thread which logged this record
|
|
|
|
wxThreadIdType threadId;
|
|
|
|
#endif // wxUSE_THREADS
|
2009-07-09 20:26:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
// store an arbitrary value in this record context
|
|
|
|
//
|
|
|
|
// wxWidgets always uses keys starting with "wx.", e.g. "wx.sys_error"
|
|
|
|
void StoreValue(const wxString& key, wxUIntPtr val)
|
|
|
|
{
|
|
|
|
if ( !m_data )
|
|
|
|
m_data = new ExtraData;
|
|
|
|
|
|
|
|
m_data->numValues[key] = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StoreValue(const wxString& key, const wxString& val)
|
|
|
|
{
|
|
|
|
if ( !m_data )
|
|
|
|
m_data = new ExtraData;
|
|
|
|
|
|
|
|
m_data->strValues[key] = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// these functions retrieve the value of either numeric or string key,
|
|
|
|
// return false if not found
|
|
|
|
bool GetNumValue(const wxString& key, wxUIntPtr *val) const
|
|
|
|
{
|
|
|
|
if ( !m_data )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxStringToNumHashMap::const_iterator it = m_data->numValues.find(key);
|
|
|
|
if ( it == m_data->numValues.end() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*val = it->second;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetStrValue(const wxString& key, wxString *val) const
|
|
|
|
{
|
|
|
|
if ( !m_data )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxStringToStringHashMap::const_iterator it = m_data->strValues.find(key);
|
|
|
|
if ( it == m_data->strValues.end() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*val = it->second;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Copy(const wxLogRecordInfo& other)
|
|
|
|
{
|
2009-07-12 14:56:23 +00:00
|
|
|
memcpy(this, &other, sizeof(*this));
|
2009-07-09 20:26:34 +00:00
|
|
|
if ( other.m_data )
|
|
|
|
m_data = new ExtraData(*other.m_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
// extra data associated with the log record: this is completely optional
|
|
|
|
// and can be used to pass information from the log function to the log
|
|
|
|
// sink (e.g. wxLogSysError() uses this to pass the error code)
|
|
|
|
struct ExtraData
|
|
|
|
{
|
|
|
|
wxStringToNumHashMap numValues;
|
|
|
|
wxStringToStringHashMap strValues;
|
|
|
|
};
|
|
|
|
|
|
|
|
// NULL if not used
|
|
|
|
ExtraData *m_data;
|
2009-07-08 13:47:33 +00:00
|
|
|
};
|
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
#define wxLOG_KEY_TRACE_MASK "wx.trace_mask"
|
|
|
|
|
2009-07-12 17:02:30 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// log record: a unit of log output
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
struct wxLogRecord
|
|
|
|
{
|
|
|
|
wxLogRecord(wxLogLevel level_,
|
|
|
|
const wxString& msg_,
|
|
|
|
const wxLogRecordInfo& info_)
|
|
|
|
: level(level_),
|
|
|
|
msg(msg_),
|
|
|
|
info(info_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
wxLogLevel level;
|
|
|
|
wxString msg;
|
|
|
|
wxLogRecordInfo info;
|
|
|
|
};
|
|
|
|
|
2011-12-22 13:35:01 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Derive from this class to customize format of log messages.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxLogFormatter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Default constructor.
|
|
|
|
wxLogFormatter() { }
|
|
|
|
|
|
|
|
// Trivial but virtual destructor for the base class.
|
|
|
|
virtual ~wxLogFormatter() { }
|
|
|
|
|
|
|
|
|
|
|
|
// Override this method to implement custom formatting of the given log
|
|
|
|
// record. The default implementation simply prepends a level-dependent
|
|
|
|
// prefix to the message and optionally adds a time stamp.
|
|
|
|
virtual wxString Format(wxLogLevel level,
|
|
|
|
const wxString& msg,
|
|
|
|
const wxLogRecordInfo& info) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Override this method to change just the time stamp formatting. It is
|
|
|
|
// called by default Format() implementation.
|
|
|
|
virtual wxString FormatTime(time_t t) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// derive from this class to redirect (or suppress, or ...) log messages
|
|
|
|
// normally, only a single instance of this class exists but it's not enforced
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-03-29 20:49:05 +00:00
|
|
|
|
2003-07-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxLog
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
|
|
|
public:
|
1999-03-29 20:49:05 +00:00
|
|
|
// ctor
|
2011-12-22 13:35:01 +00:00
|
|
|
wxLog() : m_formatter(new wxLogFormatter) { }
|
2009-07-08 13:47:33 +00:00
|
|
|
|
|
|
|
// make dtor virtual for all derived classes
|
|
|
|
virtual ~wxLog();
|
|
|
|
|
1999-03-29 20:49:05 +00:00
|
|
|
|
2009-07-12 14:56:23 +00:00
|
|
|
// log messages selection
|
|
|
|
// ----------------------
|
|
|
|
|
|
|
|
// these functions allow to completely disable all log messages or disable
|
2009-07-13 13:21:52 +00:00
|
|
|
// log messages at level less important than specified for the current
|
|
|
|
// thread
|
2004-01-27 22:30:13 +00:00
|
|
|
|
2009-07-08 14:16:55 +00:00
|
|
|
// is logging enabled at all now?
|
2009-07-13 13:21:52 +00:00
|
|
|
static bool IsEnabled()
|
|
|
|
{
|
|
|
|
#if wxUSE_THREADS
|
|
|
|
if ( !wxThread::IsMain() )
|
|
|
|
return IsThreadLoggingEnabled();
|
|
|
|
#endif // wxUSE_THREADS
|
|
|
|
|
|
|
|
return ms_doLog;
|
|
|
|
}
|
2004-01-27 22:30:13 +00:00
|
|
|
|
|
|
|
// change the flag state, return the previous one
|
2009-07-13 13:21:52 +00:00
|
|
|
static bool EnableLogging(bool enable = true)
|
|
|
|
{
|
|
|
|
#if wxUSE_THREADS
|
|
|
|
if ( !wxThread::IsMain() )
|
|
|
|
return EnableThreadLogging(enable);
|
|
|
|
#endif // wxUSE_THREADS
|
1999-03-29 20:49:05 +00:00
|
|
|
|
2009-07-13 13:21:52 +00:00
|
|
|
bool doLogOld = ms_doLog;
|
|
|
|
ms_doLog = enable;
|
|
|
|
return doLogOld;
|
|
|
|
}
|
2009-07-12 14:56:23 +00:00
|
|
|
|
|
|
|
// return the current global log level
|
|
|
|
static wxLogLevel GetLogLevel() { return ms_logLevel; }
|
|
|
|
|
|
|
|
// set global log level: messages with level > logLevel will not be logged
|
|
|
|
static void SetLogLevel(wxLogLevel logLevel) { ms_logLevel = logLevel; }
|
|
|
|
|
|
|
|
// set the log level for the given component
|
|
|
|
static void SetComponentLevel(const wxString& component, wxLogLevel level);
|
|
|
|
|
|
|
|
// return the effective log level for this component, falling back to
|
|
|
|
// parent component and to the default global log level if necessary
|
|
|
|
//
|
|
|
|
// NB: component argument is passed by value and not const reference in an
|
|
|
|
// attempt to encourage compiler to avoid an extra copy: as we modify
|
|
|
|
// the component internally, we'd create one anyhow and like this it
|
|
|
|
// can be avoided if the string is a temporary anyhow
|
|
|
|
static wxLogLevel GetComponentLevel(wxString component);
|
|
|
|
|
|
|
|
|
|
|
|
// is logging of messages from this component enabled at this level?
|
|
|
|
//
|
|
|
|
// usually always called with wxLOG_COMPONENT as second argument
|
|
|
|
static bool IsLevelEnabled(wxLogLevel level, wxString component)
|
|
|
|
{
|
|
|
|
return IsEnabled() && level <= GetComponentLevel(component);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// enable/disable messages at wxLOG_Verbose level (only relevant if the
|
|
|
|
// current log level is greater or equal to it)
|
|
|
|
//
|
|
|
|
// notice that verbose mode can be activated by the standard command-line
|
|
|
|
// '--verbose' option
|
|
|
|
static void SetVerbose(bool bVerbose = true) { ms_bVerbose = bVerbose; }
|
|
|
|
|
|
|
|
// check if verbose messages are enabled
|
|
|
|
static bool GetVerbose() { return ms_bVerbose; }
|
|
|
|
|
|
|
|
|
1999-03-29 20:49:05 +00:00
|
|
|
// message buffering
|
2009-07-12 14:56:23 +00:00
|
|
|
// -----------------
|
2004-01-27 22:30:13 +00:00
|
|
|
|
|
|
|
// flush shows all messages if they're not logged immediately (FILE
|
2009-07-18 11:18:21 +00:00
|
|
|
// and iostream logs don't need it, but wxLogGui does to avoid showing
|
2004-01-27 22:30:13 +00:00
|
|
|
// 17 modal dialogs one after another)
|
1999-03-29 20:49:05 +00:00
|
|
|
virtual void Flush();
|
|
|
|
|
2009-07-13 11:09:26 +00:00
|
|
|
// flush the active target if any and also output any pending messages from
|
|
|
|
// background threads
|
|
|
|
static void FlushActive();
|
2003-01-10 23:47:14 +00:00
|
|
|
|
2009-07-13 11:09:26 +00:00
|
|
|
// only one sink is active at each moment get current log target, will call
|
|
|
|
// wxAppTraits::CreateLogTarget() to create one if none exists
|
1999-03-29 20:49:05 +00:00
|
|
|
static wxLog *GetActiveTarget();
|
2004-01-27 22:30:13 +00:00
|
|
|
|
2009-07-13 11:09:26 +00:00
|
|
|
// change log target, logger may be NULL
|
|
|
|
static wxLog *SetActiveTarget(wxLog *logger);
|
|
|
|
|
|
|
|
#if wxUSE_THREADS
|
|
|
|
// change log target for the current thread only, shouldn't be called from
|
|
|
|
// the main thread as it doesn't use thread-specific log target
|
|
|
|
static wxLog *SetThreadActiveTarget(wxLog *logger);
|
|
|
|
#endif // wxUSE_THREADS
|
1999-03-29 20:49:05 +00:00
|
|
|
|
2004-01-27 22:30:13 +00:00
|
|
|
// suspend the message flushing of the main target until the next call
|
|
|
|
// to Resume() - this is mainly for internal use (to prevent wxYield()
|
|
|
|
// from flashing the messages)
|
2000-02-22 10:00:29 +00:00
|
|
|
static void Suspend() { ms_suspendCount++; }
|
2004-01-27 22:30:13 +00:00
|
|
|
|
|
|
|
// must be called for each Suspend()!
|
2000-02-22 10:00:29 +00:00
|
|
|
static void Resume() { ms_suspendCount--; }
|
|
|
|
|
2004-01-27 22:30:13 +00:00
|
|
|
// should GetActiveTarget() try to create a new log object if the
|
|
|
|
// current is NULL?
|
2001-05-17 10:11:34 +00:00
|
|
|
static void DontCreateOnDemand();
|
1999-03-29 20:49:05 +00:00
|
|
|
|
2007-05-18 21:17:06 +00:00
|
|
|
// Make GetActiveTarget() create a new log object again.
|
|
|
|
static void DoCreateOnDemand();
|
|
|
|
|
2006-07-25 00:04:35 +00:00
|
|
|
// log the count of repeating messages instead of logging the messages
|
|
|
|
// multiple times
|
|
|
|
static void SetRepetitionCounting(bool bRepetCounting = true)
|
2006-08-31 11:31:02 +00:00
|
|
|
{ ms_bRepetCounting = bRepetCounting; }
|
2006-07-25 00:04:35 +00:00
|
|
|
|
|
|
|
// gets duplicate counting status
|
|
|
|
static bool GetRepetitionCounting() { return ms_bRepetCounting; }
|
|
|
|
|
2004-01-27 22:30:13 +00:00
|
|
|
// add string trace mask
|
2008-03-15 03:42:48 +00:00
|
|
|
static void AddTraceMask(const wxString& str);
|
2004-01-27 22:30:13 +00:00
|
|
|
|
|
|
|
// add string trace mask
|
1999-03-29 20:49:05 +00:00
|
|
|
static void RemoveTraceMask(const wxString& str);
|
2004-01-27 22:30:13 +00:00
|
|
|
|
|
|
|
// remove all string trace masks
|
2001-05-17 10:11:34 +00:00
|
|
|
static void ClearTraceMasks();
|
2004-01-27 22:30:13 +00:00
|
|
|
|
2008-03-15 03:42:48 +00:00
|
|
|
// get string trace masks: note that this is MT-unsafe if other threads can
|
|
|
|
// call AddTraceMask() concurrently
|
2010-01-04 12:22:42 +00:00
|
|
|
static const wxArrayString& GetTraceMasks();
|
1999-03-29 20:49:05 +00:00
|
|
|
|
2011-12-22 13:35:01 +00:00
|
|
|
// is this trace mask in the list?
|
|
|
|
static bool IsAllowedTraceMask(const wxString& mask);
|
|
|
|
|
|
|
|
|
|
|
|
// log formatting
|
|
|
|
// -----------------
|
|
|
|
|
|
|
|
// Change wxLogFormatter object used by wxLog to format the log messages.
|
|
|
|
//
|
|
|
|
// wxLog takes ownership of the pointer passed in but the caller is
|
|
|
|
// responsible for deleting the returned pointer.
|
|
|
|
wxLogFormatter* SetFormatter(wxLogFormatter* formatter);
|
|
|
|
|
|
|
|
|
|
|
|
// All the time stamp related functions below only work when the default
|
|
|
|
// wxLogFormatter is being used. Defining a custom formatter overrides them
|
|
|
|
// as it could use its own time stamp format or format messages without
|
|
|
|
// using time stamp at all.
|
|
|
|
|
|
|
|
|
2007-06-27 12:09:55 +00:00
|
|
|
// sets the time stamp string format: this is used as strftime() format
|
|
|
|
// string for the log targets which add time stamps to the messages; set
|
|
|
|
// it to empty string to disable time stamping completely.
|
2007-06-19 14:51:10 +00:00
|
|
|
static void SetTimestamp(const wxString& ts) { ms_timestamp = ts; }
|
1999-07-15 15:45:50 +00:00
|
|
|
|
2007-06-27 12:09:55 +00:00
|
|
|
// disable time stamping of log messages
|
|
|
|
static void DisableTimestamp() { SetTimestamp(wxEmptyString); }
|
|
|
|
|
2003-01-01 05:16:07 +00:00
|
|
|
|
2009-06-01 23:05:37 +00:00
|
|
|
// get the current timestamp format string (maybe empty)
|
2007-06-19 14:51:10 +00:00
|
|
|
static const wxString& GetTimestamp() { return ms_timestamp; }
|
1999-07-15 15:45:50 +00:00
|
|
|
|
2003-01-01 05:16:07 +00:00
|
|
|
|
2009-07-08 13:47:33 +00:00
|
|
|
|
|
|
|
// helpers: all functions in this section are mostly for internal use only,
|
|
|
|
// don't call them from your code even if they are not formally deprecated
|
2004-01-27 22:30:13 +00:00
|
|
|
|
2011-12-22 13:35:01 +00:00
|
|
|
// put the time stamp into the string if ms_timestamp is not empty (don't
|
|
|
|
// change it otherwise); the first overload uses the current time.
|
1999-07-15 15:45:50 +00:00
|
|
|
static void TimeStamp(wxString *str);
|
2011-12-22 13:35:01 +00:00
|
|
|
static void TimeStamp(wxString *str, time_t t);
|
1999-07-15 15:45:50 +00:00
|
|
|
|
2009-07-08 13:47:33 +00:00
|
|
|
// these methods should only be called from derived classes DoLogRecord(),
|
|
|
|
// DoLogTextAtLevel() and DoLogText() implementations respectively and
|
|
|
|
// shouldn't be called directly, use logging functions instead
|
|
|
|
void LogRecord(wxLogLevel level,
|
|
|
|
const wxString& msg,
|
|
|
|
const wxLogRecordInfo& info)
|
2009-02-22 00:46:25 +00:00
|
|
|
{
|
2009-07-08 13:47:33 +00:00
|
|
|
DoLogRecord(level, msg, info);
|
2009-02-22 00:46:25 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 13:47:33 +00:00
|
|
|
void LogTextAtLevel(wxLogLevel level, const wxString& msg)
|
|
|
|
{
|
|
|
|
DoLogTextAtLevel(level, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogText(const wxString& msg)
|
|
|
|
{
|
|
|
|
DoLogText(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is a helper used by wxLogXXX() functions, don't call it directly
|
|
|
|
// and see DoLog() for function to overload in the derived classes
|
|
|
|
static void OnLog(wxLogLevel level,
|
|
|
|
const wxString& msg,
|
|
|
|
const wxLogRecordInfo& info);
|
|
|
|
|
|
|
|
// version called when no information about the location of the log record
|
|
|
|
// generation is available (but the time stamp is), it mainly exists for
|
|
|
|
// backwards compatibility, don't use it in new code
|
|
|
|
static void OnLog(wxLogLevel level, const wxString& msg, time_t t);
|
|
|
|
|
|
|
|
// a helper calling the above overload with current time
|
|
|
|
static void OnLog(wxLogLevel level, const wxString& msg)
|
|
|
|
{
|
|
|
|
OnLog(level, msg, time(NULL));
|
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
|
|
|
|
2003-01-10 23:47:14 +00:00
|
|
|
// this method exists for backwards compatibility only, don't use
|
2004-01-27 22:30:13 +00:00
|
|
|
bool HasPendingMessages() const { return true; }
|
2003-01-10 23:47:14 +00:00
|
|
|
|
2009-03-22 16:00:37 +00:00
|
|
|
// don't use integer masks any more, use string trace masks instead
|
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
2011-02-19 12:32:59 +00:00
|
|
|
static wxDEPRECATED_INLINE( void SetTraceMask(wxTraceMask ulMask),
|
2009-03-22 16:00:37 +00:00
|
|
|
ms_ulTraceMask = ulMask; )
|
2009-07-09 22:00:30 +00:00
|
|
|
|
|
|
|
// this one can't be marked deprecated as it's used in our own wxLogger
|
|
|
|
// below but it still is deprecated and shouldn't be used
|
|
|
|
static wxTraceMask GetTraceMask() { return ms_ulTraceMask; }
|
2009-03-22 16:00:37 +00:00
|
|
|
#endif // WXWIN_COMPATIBILITY_2_8
|
|
|
|
|
2003-01-10 23:47:14 +00:00
|
|
|
protected:
|
2009-07-08 13:47:33 +00:00
|
|
|
// the logging functions that can be overridden: DoLogRecord() is called
|
|
|
|
// for every "record", i.e. a unit of log output, to be logged and by
|
|
|
|
// default formats the message and passes it to DoLogTextAtLevel() which in
|
|
|
|
// turn passes it to DoLogText() by default
|
2009-07-09 20:26:34 +00:00
|
|
|
|
2009-07-08 13:47:33 +00:00
|
|
|
// override this method if you want to change message formatting or do
|
|
|
|
// dynamic filtering
|
|
|
|
virtual void DoLogRecord(wxLogLevel level,
|
|
|
|
const wxString& msg,
|
|
|
|
const wxLogRecordInfo& info);
|
|
|
|
|
|
|
|
// override this method to redirect output to different channels depending
|
|
|
|
// on its level only; if even the level doesn't matter, override
|
|
|
|
// DoLogText() instead
|
|
|
|
virtual void DoLogTextAtLevel(wxLogLevel level, const wxString& msg);
|
|
|
|
|
|
|
|
// this function is not pure virtual as it might not be needed if you do
|
|
|
|
// the logging in overridden DoLogRecord() or DoLogTextAtLevel() directly
|
|
|
|
// but if you do not override them in your derived class you must override
|
|
|
|
// this one as the default implementation of it simply asserts
|
|
|
|
virtual void DoLogText(const wxString& msg);
|
|
|
|
|
|
|
|
|
|
|
|
// the rest of the functions are for backwards compatibility only, don't
|
|
|
|
// use them in new code; if you're updating your existing code you need to
|
|
|
|
// switch to overriding DoLogRecord/Text() above (although as long as these
|
|
|
|
// functions exist, log classes using them will continue to work)
|
2007-06-04 10:04:05 +00:00
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
2007-06-15 15:08:51 +00:00
|
|
|
wxDEPRECATED_BUT_USED_INTERNALLY(
|
|
|
|
virtual void DoLog(wxLogLevel level, const char *szString, time_t t)
|
|
|
|
);
|
|
|
|
|
|
|
|
wxDEPRECATED_BUT_USED_INTERNALLY(
|
|
|
|
virtual void DoLog(wxLogLevel level, const wchar_t *wzString, time_t t)
|
|
|
|
);
|
2004-01-27 22:30:13 +00:00
|
|
|
|
2007-06-04 10:04:05 +00:00
|
|
|
// these shouldn't be used by new code
|
2009-07-08 13:47:33 +00:00
|
|
|
wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
|
|
|
|
virtual void DoLogString(const char *WXUNUSED(szString),
|
|
|
|
time_t WXUNUSED(t)),
|
2009-07-09 15:13:52 +00:00
|
|
|
wxEMPTY_PARAMETER_VALUE
|
2009-07-08 13:47:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
|
|
|
|
virtual void DoLogString(const wchar_t *WXUNUSED(wzString),
|
|
|
|
time_t WXUNUSED(t)),
|
2009-07-09 15:13:52 +00:00
|
|
|
wxEMPTY_PARAMETER_VALUE
|
2009-07-08 13:47:33 +00:00
|
|
|
)
|
2007-06-22 18:09:03 +00:00
|
|
|
#endif // WXWIN_COMPATIBILITY_2_8
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2007-10-24 17:55:29 +00:00
|
|
|
// log a message indicating the number of times the previous message was
|
2009-07-08 13:47:33 +00:00
|
|
|
// repeated if previous repetition counter is strictly positive, does
|
|
|
|
// nothing otherwise; return the old value of repetition counter
|
2008-01-02 21:18:15 +00:00
|
|
|
unsigned LogLastRepeatIfNeeded();
|
2006-07-25 00:04:35 +00:00
|
|
|
|
1999-03-29 20:49:05 +00:00
|
|
|
private:
|
2009-07-13 11:09:26 +00:00
|
|
|
#if wxUSE_THREADS
|
|
|
|
// called from FlushActive() to really log any buffered messages logged
|
|
|
|
// from the other threads
|
|
|
|
void FlushThreadMessages();
|
2009-07-13 13:21:52 +00:00
|
|
|
|
|
|
|
// these functions are called for non-main thread only by IsEnabled() and
|
|
|
|
// EnableLogging() respectively
|
|
|
|
static bool IsThreadLoggingEnabled();
|
|
|
|
static bool EnableThreadLogging(bool enable = true);
|
2009-07-13 11:09:26 +00:00
|
|
|
#endif // wxUSE_THREADS
|
|
|
|
|
2009-07-15 12:36:09 +00:00
|
|
|
// get the active log target for the main thread, auto-creating it if
|
|
|
|
// necessary
|
|
|
|
//
|
|
|
|
// this is called from GetActiveTarget() and OnLog() when they're called
|
|
|
|
// from the main thread
|
|
|
|
static wxLog *GetMainThreadActiveTarget();
|
|
|
|
|
2009-07-13 11:09:26 +00:00
|
|
|
// called from OnLog() if it's called from the main thread or if we have a
|
|
|
|
// (presumably MT-safe) thread-specific logger and by FlushThreadMessages()
|
2009-07-12 17:02:30 +00:00
|
|
|
// when it plays back the buffered messages logged from the other threads
|
2009-07-13 11:09:26 +00:00
|
|
|
void CallDoLogNow(wxLogLevel level,
|
|
|
|
const wxString& msg,
|
|
|
|
const wxLogRecordInfo& info);
|
2009-07-12 17:02:30 +00:00
|
|
|
|
|
|
|
|
2011-12-22 13:35:01 +00:00
|
|
|
// variables
|
|
|
|
// ----------------
|
|
|
|
|
|
|
|
wxLogFormatter *m_formatter; // We own this pointer.
|
|
|
|
|
|
|
|
|
1999-03-29 20:49:05 +00:00
|
|
|
// static variables
|
|
|
|
// ----------------
|
1998-08-04 16:42:34 +00:00
|
|
|
|
2007-10-24 17:55:29 +00:00
|
|
|
// if true, don't log the same message multiple times, only log it once
|
|
|
|
// with the number of times it was repeated
|
2006-07-25 00:04:35 +00:00
|
|
|
static bool ms_bRepetCounting;
|
2007-10-24 17:55:29 +00:00
|
|
|
|
1999-03-29 20:49:05 +00:00
|
|
|
static wxLog *ms_pLogger; // currently active log sink
|
2004-01-27 22:30:13 +00:00
|
|
|
static bool ms_doLog; // false => all logging disabled
|
1999-03-29 20:49:05 +00:00
|
|
|
static bool ms_bAutoCreate; // create new log targets on demand?
|
2004-01-27 22:30:13 +00:00
|
|
|
static bool ms_bVerbose; // false => ignore LogInfo messages
|
1998-08-08 21:38:22 +00:00
|
|
|
|
2003-01-01 05:16:07 +00:00
|
|
|
static wxLogLevel ms_logLevel; // limit logging to levels <= ms_logLevel
|
|
|
|
|
2000-02-22 10:00:29 +00:00
|
|
|
static size_t ms_suspendCount; // if positive, logs are not flushed
|
|
|
|
|
2009-06-01 23:05:37 +00:00
|
|
|
// format string for strftime(), if empty, time stamping log messages is
|
1999-07-15 15:45:50 +00:00
|
|
|
// disabled
|
2007-06-19 14:51:10 +00:00
|
|
|
static wxString ms_timestamp;
|
1999-07-15 15:45:50 +00:00
|
|
|
|
2009-03-22 16:00:37 +00:00
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
1999-03-29 20:49:05 +00:00
|
|
|
static wxTraceMask ms_ulTraceMask; // controls wxLogTrace behaviour
|
2009-03-22 16:00:37 +00:00
|
|
|
#endif // WXWIN_COMPATIBILITY_2_8
|
1998-05-20 14:01:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// "trivial" derivations of wxLog
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-03-22 17:18:07 +00:00
|
|
|
// log everything except for the debug/trace messages (which are passed to
|
|
|
|
// wxMessageOutputDebug) to a buffer
|
2005-06-06 23:35:40 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxLogBuffer : public wxLog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxLogBuffer() { }
|
|
|
|
|
|
|
|
// get the string contents with all messages logged
|
|
|
|
const wxString& GetBuffer() const { return m_str; }
|
|
|
|
|
|
|
|
// show the buffer contents to the user in the best possible way (this uses
|
|
|
|
// wxMessageOutputMessageBox) and clear it
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void Flush() wxOVERRIDE;
|
2005-06-06 23:35:40 +00:00
|
|
|
|
|
|
|
protected:
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoLogTextAtLevel(wxLogLevel level, const wxString& msg) wxOVERRIDE;
|
2007-06-22 18:09:03 +00:00
|
|
|
|
2005-06-06 23:35:40 +00:00
|
|
|
private:
|
|
|
|
wxString m_str;
|
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxLogBuffer);
|
2005-06-06 23:35:40 +00:00
|
|
|
};
|
|
|
|
|
2005-07-17 13:00:11 +00:00
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
// log everything to a "FILE *", stderr by default
|
2003-07-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxLogStderr : public wxLog
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
|
|
|
public:
|
1999-03-29 20:49:05 +00:00
|
|
|
// redirect log output to a FILE
|
2009-01-19 13:55:27 +00:00
|
|
|
wxLogStderr(FILE *fp = NULL);
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2001-07-11 09:43:40 +00:00
|
|
|
protected:
|
1999-03-29 20:49:05 +00:00
|
|
|
// implement sink function
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoLogText(const wxString& msg) wxOVERRIDE;
|
2007-06-22 18:09:03 +00:00
|
|
|
|
1999-03-29 20:49:05 +00:00
|
|
|
FILE *m_fp;
|
2005-06-06 23:35:40 +00:00
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxLogStderr);
|
1998-05-20 14:01:55 +00:00
|
|
|
};
|
|
|
|
|
1999-01-04 21:51:15 +00:00
|
|
|
#if wxUSE_STD_IOSTREAM
|
2001-07-11 09:43:40 +00:00
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
// log everything to an "ostream", cerr by default
|
2003-07-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxLogStream : public wxLog
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
|
|
|
public:
|
1999-03-29 20:49:05 +00:00
|
|
|
// redirect log output to an ostream
|
2001-06-06 16:51:53 +00:00
|
|
|
wxLogStream(wxSTD ostream *ostr = (wxSTD ostream *) NULL);
|
1998-05-20 14:01:55 +00:00
|
|
|
|
|
|
|
protected:
|
1999-03-29 20:49:05 +00:00
|
|
|
// implement sink function
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoLogText(const wxString& msg) wxOVERRIDE;
|
2007-06-22 18:09:03 +00:00
|
|
|
|
1999-03-29 20:49:05 +00:00
|
|
|
// using ptr here to avoid including <iostream.h> from this file
|
2001-06-06 16:51:53 +00:00
|
|
|
wxSTD ostream *m_ostr;
|
1998-05-20 14:01:55 +00:00
|
|
|
};
|
2001-07-11 09:43:40 +00:00
|
|
|
|
|
|
|
#endif // wxUSE_STD_IOSTREAM
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2001-07-11 09:43:40 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// /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
|
|
|
|
}
|
|
|
|
*/
|
2003-07-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxLogNull
|
2001-07-11 09:43:40 +00:00
|
|
|
{
|
|
|
|
public:
|
2004-01-27 22:30:13 +00:00
|
|
|
wxLogNull() : m_flagOld(wxLog::EnableLogging(false)) { }
|
2002-05-08 13:30:26 +00:00
|
|
|
~wxLogNull() { (void)wxLog::EnableLogging(m_flagOld); }
|
2001-07-11 09:43:40 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2003-07-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxLogChain : public wxLog
|
2001-07-11 09:43:40 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxLogChain(wxLog *logger);
|
2002-04-27 22:14:49 +00:00
|
|
|
virtual ~wxLogChain();
|
2001-07-11 09:43:40 +00:00
|
|
|
|
|
|
|
// 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
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void Flush() wxOVERRIDE;
|
2001-07-11 09:43:40 +00:00
|
|
|
|
2007-06-21 12:44:38 +00:00
|
|
|
// call to avoid destroying the old log target
|
|
|
|
void DetachOldLog() { m_logOld = NULL; }
|
|
|
|
|
2001-07-11 09:43:40 +00:00
|
|
|
protected:
|
2009-07-08 13:47:33 +00:00
|
|
|
// pass the record to the old logger if needed
|
|
|
|
virtual void DoLogRecord(wxLogLevel level,
|
|
|
|
const wxString& msg,
|
2014-03-30 00:02:23 +00:00
|
|
|
const wxLogRecordInfo& info) wxOVERRIDE;
|
2007-06-22 18:09:03 +00:00
|
|
|
|
2001-07-11 09:43:40 +00:00
|
|
|
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;
|
2003-01-02 23:38:11 +00:00
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxLogChain);
|
2001-07-11 09:43:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// a chain log target which uses itself as the new logger
|
2007-06-21 12:44:38 +00:00
|
|
|
|
|
|
|
#define wxLogPassThrough wxLogInterposer
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxLogInterposer : public wxLogChain
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxLogInterposer();
|
|
|
|
|
|
|
|
private:
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxLogInterposer);
|
2007-06-21 12:44:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// a temporary interposer which doesn't destroy the old log target
|
|
|
|
// (calls DetachOldLog)
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxLogInterposerTemp : public wxLogChain
|
2001-07-11 09:43:40 +00:00
|
|
|
{
|
|
|
|
public:
|
2007-06-21 12:44:38 +00:00
|
|
|
wxLogInterposerTemp();
|
2003-07-22 00:24:07 +00:00
|
|
|
|
|
|
|
private:
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxLogInterposerTemp);
|
2001-07-11 09:43:40 +00:00
|
|
|
};
|
|
|
|
|
2001-07-13 13:51:57 +00:00
|
|
|
#if wxUSE_GUI
|
2003-06-25 16:28:47 +00:00
|
|
|
// include GUI log targets:
|
|
|
|
#include "wx/generic/logg.h"
|
1999-10-04 20:15:38 +00:00
|
|
|
#endif // wxUSE_GUI
|
1998-10-12 13:09:15 +00:00
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxLogger
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// wxLogger is a helper class used by wxLogXXX() functions implementation,
|
|
|
|
// don't use it directly as it's experimental and subject to change (OTOH it
|
|
|
|
// might become public in the future if it's deemed to be useful enough)
|
|
|
|
|
|
|
|
// contains information about the context from which a log message originates
|
|
|
|
// and provides Log() vararg method which forwards to wxLog::OnLog() and passes
|
|
|
|
// this context to it
|
|
|
|
class wxLogger
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctor takes the basic information about the log record
|
|
|
|
wxLogger(wxLogLevel level,
|
|
|
|
const char *filename,
|
|
|
|
int line,
|
2009-07-12 14:56:23 +00:00
|
|
|
const char *func,
|
|
|
|
const char *component)
|
2009-07-09 20:26:34 +00:00
|
|
|
: m_level(level),
|
2009-07-12 14:56:23 +00:00
|
|
|
m_info(filename, line, func, component)
|
2009-07-09 20:26:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// store extra data in our log record and return this object itself (so
|
|
|
|
// that further calls to its functions could be chained)
|
|
|
|
template <typename T>
|
|
|
|
wxLogger& Store(const wxString& key, T val)
|
|
|
|
{
|
|
|
|
m_info.StoreValue(key, val);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// hack for "overloaded" wxLogXXX() functions: calling this method
|
|
|
|
// indicates that we may have an extra first argument preceding the format
|
|
|
|
// string and that if we do have it, we should store it in m_info using the
|
|
|
|
// given key (while by default 0 value will be used)
|
2009-08-18 01:22:48 +00:00
|
|
|
wxLogger& MaybeStore(const wxString& key, wxUIntPtr value = 0)
|
2009-07-09 20:26:34 +00:00
|
|
|
{
|
|
|
|
wxASSERT_MSG( m_optKey.empty(), "can only have one optional value" );
|
|
|
|
m_optKey = key;
|
|
|
|
|
2009-08-18 01:22:48 +00:00
|
|
|
m_info.StoreValue(key, value);
|
2009-07-09 20:26:34 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// non-vararg function used by wxVLogXXX():
|
|
|
|
|
|
|
|
// log the message at the level specified in the ctor if this log message
|
|
|
|
// is enabled
|
|
|
|
void LogV(const wxString& format, va_list argptr)
|
|
|
|
{
|
|
|
|
// remember that fatal errors can't be disabled
|
2009-07-12 14:56:23 +00:00
|
|
|
if ( m_level == wxLOG_FatalError ||
|
|
|
|
wxLog::IsLevelEnabled(m_level, m_info.component) )
|
2009-07-09 20:26:34 +00:00
|
|
|
DoCallOnLog(format, argptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// overloads used by functions with optional leading arguments (whose
|
|
|
|
// values are stored in the key passed to MaybeStore())
|
|
|
|
void LogV(long num, const wxString& format, va_list argptr)
|
|
|
|
{
|
|
|
|
Store(m_optKey, num);
|
|
|
|
|
|
|
|
LogV(format, argptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogV(void *ptr, const wxString& format, va_list argptr)
|
|
|
|
{
|
|
|
|
Store(m_optKey, wxPtrToUInt(ptr));
|
|
|
|
|
|
|
|
LogV(format, argptr);
|
|
|
|
}
|
|
|
|
|
2009-07-23 13:40:44 +00:00
|
|
|
void LogVTrace(const wxString& mask, const wxString& format, va_list argptr)
|
|
|
|
{
|
|
|
|
if ( !wxLog::IsAllowedTraceMask(mask) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Store(wxLOG_KEY_TRACE_MASK, mask);
|
|
|
|
|
|
|
|
LogV(format, argptr);
|
|
|
|
}
|
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
|
|
|
|
// vararg functions used by wxLogXXX():
|
|
|
|
|
|
|
|
// will log the message at the level specified in the ctor
|
|
|
|
//
|
|
|
|
// notice that this function supposes that the caller already checked that
|
|
|
|
// the level was enabled and does no checks itself
|
|
|
|
WX_DEFINE_VARARG_FUNC_VOID
|
|
|
|
(
|
|
|
|
Log,
|
|
|
|
1, (const wxFormatString&),
|
|
|
|
DoLog, DoLogUtf8
|
|
|
|
)
|
|
|
|
|
|
|
|
// same as Log() but with an extra numeric or pointer parameters: this is
|
|
|
|
// used to pass an optional value by storing it in m_info under the name
|
|
|
|
// passed to MaybeStore() and is required to support "overloaded" versions
|
|
|
|
// of wxLogStatus() and wxLogSysError()
|
|
|
|
WX_DEFINE_VARARG_FUNC_VOID
|
|
|
|
(
|
|
|
|
Log,
|
|
|
|
2, (long, const wxFormatString&),
|
|
|
|
DoLogWithNum, DoLogWithNumUtf8
|
|
|
|
)
|
|
|
|
|
2009-07-09 21:39:29 +00:00
|
|
|
// unfortunately we can't use "void *" here as we get overload ambiguities
|
|
|
|
// with Log(wxFormatString, ...) when the first argument is a "char *" or
|
|
|
|
// "wchar_t *" then -- so we only allow passing wxObject here, which is
|
|
|
|
// ugly but fine in practice as this overload is only used by wxLogStatus()
|
|
|
|
// whose first argument is a wxFrame
|
2009-07-09 20:26:34 +00:00
|
|
|
WX_DEFINE_VARARG_FUNC_VOID
|
|
|
|
(
|
|
|
|
Log,
|
2009-07-09 21:39:29 +00:00
|
|
|
2, (wxObject *, const wxFormatString&),
|
2009-07-09 20:26:34 +00:00
|
|
|
DoLogWithPtr, DoLogWithPtrUtf8
|
|
|
|
)
|
|
|
|
|
|
|
|
// log the message at the level specified as its first argument
|
|
|
|
//
|
|
|
|
// as the macros don't have access to the level argument in this case, this
|
|
|
|
// function does check that the level is enabled itself
|
|
|
|
WX_DEFINE_VARARG_FUNC_VOID
|
|
|
|
(
|
|
|
|
LogAtLevel,
|
|
|
|
2, (wxLogLevel, const wxFormatString&),
|
|
|
|
DoLogAtLevel, DoLogAtLevelUtf8
|
|
|
|
)
|
|
|
|
|
|
|
|
// special versions for wxLogTrace() which is passed either string or
|
2009-07-09 20:30:27 +00:00
|
|
|
// integer mask as first argument determining whether the message should be
|
|
|
|
// logged or not
|
2009-07-09 20:26:34 +00:00
|
|
|
WX_DEFINE_VARARG_FUNC_VOID
|
|
|
|
(
|
|
|
|
LogTrace,
|
|
|
|
2, (const wxString&, const wxFormatString&),
|
|
|
|
DoLogTrace, DoLogTraceUtf8
|
|
|
|
)
|
|
|
|
|
2009-07-09 20:30:27 +00:00
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
|
|
|
WX_DEFINE_VARARG_FUNC_VOID
|
|
|
|
(
|
|
|
|
LogTrace,
|
|
|
|
2, (wxTraceMask, const wxFormatString&),
|
|
|
|
DoLogTraceMask, DoLogTraceMaskUtf8
|
|
|
|
)
|
|
|
|
#endif // WXWIN_COMPATIBILITY_2_8
|
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
private:
|
|
|
|
#if !wxUSE_UTF8_LOCALE_ONLY
|
|
|
|
void DoLog(const wxChar *format, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, format);
|
|
|
|
DoCallOnLog(format, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoLogWithNum(long num, const wxChar *format, ...)
|
|
|
|
{
|
|
|
|
Store(m_optKey, num);
|
|
|
|
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, format);
|
|
|
|
DoCallOnLog(format, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoLogWithPtr(void *ptr, const wxChar *format, ...)
|
|
|
|
{
|
|
|
|
Store(m_optKey, wxPtrToUInt(ptr));
|
|
|
|
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, format);
|
|
|
|
DoCallOnLog(format, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoLogAtLevel(wxLogLevel level, const wxChar *format, ...)
|
|
|
|
{
|
2009-07-12 14:56:23 +00:00
|
|
|
if ( !wxLog::IsLevelEnabled(level, m_info.component) )
|
2009-07-09 20:26:34 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, format);
|
|
|
|
DoCallOnLog(level, format, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoLogTrace(const wxString& mask, const wxChar *format, ...)
|
|
|
|
{
|
|
|
|
if ( !wxLog::IsAllowedTraceMask(mask) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Store(wxLOG_KEY_TRACE_MASK, mask);
|
|
|
|
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, format);
|
|
|
|
DoCallOnLog(format, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
}
|
2009-07-09 20:30:27 +00:00
|
|
|
|
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
|
|
|
void DoLogTraceMask(wxTraceMask mask, const wxChar *format, ...)
|
|
|
|
{
|
|
|
|
if ( (wxLog::GetTraceMask() & mask) != mask )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Store(wxLOG_KEY_TRACE_MASK, mask);
|
|
|
|
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, format);
|
|
|
|
DoCallOnLog(format, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
}
|
|
|
|
#endif // WXWIN_COMPATIBILITY_2_8
|
2009-07-09 20:26:34 +00:00
|
|
|
#endif // !wxUSE_UTF8_LOCALE_ONLY
|
|
|
|
|
|
|
|
#if wxUSE_UNICODE_UTF8
|
|
|
|
void DoLogUtf8(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, format);
|
|
|
|
DoCallOnLog(format, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoLogWithNumUtf8(long num, const char *format, ...)
|
|
|
|
{
|
|
|
|
Store(m_optKey, num);
|
|
|
|
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, format);
|
|
|
|
DoCallOnLog(format, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoLogWithPtrUtf8(void *ptr, const char *format, ...)
|
|
|
|
{
|
|
|
|
Store(m_optKey, wxPtrToUInt(ptr));
|
|
|
|
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, format);
|
|
|
|
DoCallOnLog(format, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoLogAtLevelUtf8(wxLogLevel level, const char *format, ...)
|
|
|
|
{
|
2009-07-12 14:56:23 +00:00
|
|
|
if ( !wxLog::IsLevelEnabled(level, m_info.component) )
|
2009-07-09 20:26:34 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, format);
|
|
|
|
DoCallOnLog(level, format, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoLogTraceUtf8(const wxString& mask, const char *format, ...)
|
|
|
|
{
|
|
|
|
if ( !wxLog::IsAllowedTraceMask(mask) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Store(wxLOG_KEY_TRACE_MASK, mask);
|
|
|
|
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, format);
|
|
|
|
DoCallOnLog(format, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
}
|
2009-07-09 20:30:27 +00:00
|
|
|
|
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
|
|
|
void DoLogTraceMaskUtf8(wxTraceMask mask, const char *format, ...)
|
|
|
|
{
|
|
|
|
if ( (wxLog::GetTraceMask() & mask) != mask )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Store(wxLOG_KEY_TRACE_MASK, mask);
|
|
|
|
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, format);
|
|
|
|
DoCallOnLog(format, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
}
|
|
|
|
#endif // WXWIN_COMPATIBILITY_2_8
|
2009-07-09 20:26:34 +00:00
|
|
|
#endif // wxUSE_UNICODE_UTF8
|
|
|
|
|
|
|
|
void DoCallOnLog(wxLogLevel level, const wxString& format, va_list argptr)
|
|
|
|
{
|
|
|
|
wxLog::OnLog(level, wxString::FormatV(format, argptr), m_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoCallOnLog(const wxString& format, va_list argptr)
|
|
|
|
{
|
2009-08-18 01:22:48 +00:00
|
|
|
DoCallOnLog(m_level, format, argptr);
|
2009-07-09 20:26:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxLogLevel m_level;
|
|
|
|
wxLogRecordInfo m_info;
|
|
|
|
|
|
|
|
wxString m_optKey;
|
|
|
|
|
|
|
|
wxDECLARE_NO_COPY_CLASS(wxLogger);
|
|
|
|
};
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
// ============================================================================
|
|
|
|
// global functions
|
|
|
|
// ============================================================================
|
|
|
|
|
1999-06-01 15:32:12 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// get error code/error message from system in a portable way
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// return the last system error code
|
2003-07-02 01:59:24 +00:00
|
|
|
WXDLLIMPEXP_BASE unsigned long wxSysErrorCode();
|
2002-05-09 15:59:42 +00:00
|
|
|
|
1999-06-01 15:32:12 +00:00
|
|
|
// return the error message for given (or last if 0) error code
|
2003-07-02 01:59:24 +00:00
|
|
|
WXDLLIMPEXP_BASE const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0);
|
1999-06-01 15:32:12 +00:00
|
|
|
|
2002-05-09 15:59:42 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2009-07-09 20:26:34 +00:00
|
|
|
// define wxLog<level>() functions which can be used by application instead of
|
|
|
|
// stdio, iostream &c for log messages for easy redirection
|
2002-05-09 15:59:42 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
/*
|
|
|
|
The code below is unreadable because it (unfortunately unavoidably)
|
|
|
|
contains a lot of macro magic but all it does is to define wxLogXXX() such
|
|
|
|
that you can call them as vararg functions to log a message at the
|
|
|
|
corresponding level.
|
|
|
|
|
|
|
|
More precisely, it defines:
|
|
|
|
|
|
|
|
- wxLog{FatalError,Error,Warning,Message,Verbose,Debug}() functions
|
|
|
|
taking the format string and additional vararg arguments if needed.
|
|
|
|
- wxLogGeneric(wxLogLevel level, const wxString& format, ...) which
|
|
|
|
takes the log level explicitly.
|
|
|
|
- wxLogSysError(const wxString& format, ...) and wxLogSysError(long
|
|
|
|
err, const wxString& format, ...) which log a wxLOG_Error severity
|
|
|
|
message with the error message corresponding to the system error code
|
|
|
|
err or the last error.
|
|
|
|
- wxLogStatus(const wxString& format, ...) which logs the message into
|
|
|
|
the status bar of the main application window and its overload
|
|
|
|
wxLogStatus(wxFrame *frame, const wxString& format, ...) which logs it
|
|
|
|
into the status bar of the specified frame.
|
|
|
|
- wxLogTrace(Mask mask, const wxString& format, ...) which only logs
|
|
|
|
the message is the specified mask is enabled. This comes in two kinds:
|
|
|
|
Mask can be a wxString or a long. Both are deprecated.
|
|
|
|
|
|
|
|
In addition, wxVLogXXX() versions of all the functions above are also
|
|
|
|
defined. They take a va_list argument instead of "...".
|
|
|
|
*/
|
2007-04-26 11:40:04 +00:00
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
// creates wxLogger object for the current location
|
|
|
|
#define wxMAKE_LOGGER(level) \
|
2009-07-12 14:56:23 +00:00
|
|
|
wxLogger(wxLOG_##level, __FILE__, __LINE__, __WXFUNCTION__, wxLOG_COMPONENT)
|
2007-04-26 11:40:04 +00:00
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
// this macro generates the expression which logs whatever follows it in
|
|
|
|
// parentheses at the level specified as argument
|
|
|
|
#define wxDO_LOG(level) wxMAKE_LOGGER(level).Log
|
2007-03-17 10:26:10 +00:00
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
// this is the non-vararg equivalent
|
|
|
|
#define wxDO_LOGV(level, format, argptr) \
|
|
|
|
wxMAKE_LOGGER(level).LogV(format, argptr)
|
2007-04-26 11:40:04 +00:00
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
// this macro declares wxLog<level>() macro which logs whatever follows it if
|
|
|
|
// logging at specified level is enabled (notice that if it is false, the
|
|
|
|
// following arguments are not even evaluated which is good as it avoids
|
|
|
|
// unnecessary overhead)
|
|
|
|
//
|
2013-08-31 17:41:16 +00:00
|
|
|
// Note: the strange (because executing at most once) for() loop because we
|
|
|
|
// must arrange for wxDO_LOG() to be at the end of the macro and using a
|
|
|
|
// more natural "if (IsLevelEnabled()) wxDO_LOG()" would result in wrong
|
|
|
|
// behaviour for the following code ("else" would bind to the wrong "if"):
|
2009-07-09 20:26:34 +00:00
|
|
|
//
|
|
|
|
// if ( cond )
|
|
|
|
// wxLogError("!!!");
|
|
|
|
// else
|
|
|
|
// ...
|
|
|
|
//
|
2013-08-31 17:41:16 +00:00
|
|
|
// See also #11829 for the problems with other simpler approaches,
|
|
|
|
// notably the need for two macros due to buggy __LINE__ in MSVC.
|
|
|
|
#define wxDO_LOG_IF_ENABLED_HELPER(level, loopvar) \
|
|
|
|
for ( bool loopvar = false; \
|
|
|
|
!loopvar && wxLog::IsLevelEnabled(wxLOG_##level, wxLOG_COMPONENT); \
|
|
|
|
loopvar = true ) \
|
2009-07-09 20:26:34 +00:00
|
|
|
wxDO_LOG(level)
|
|
|
|
|
2013-08-31 17:41:16 +00:00
|
|
|
#define wxDO_LOG_IF_ENABLED(level) \
|
|
|
|
wxDO_LOG_IF_ENABLED_HELPER(level, wxMAKE_UNIQUE_NAME(wxlogcheck))
|
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
// wxLogFatalError() is special as it can't be disabled
|
2009-08-21 10:41:26 +00:00
|
|
|
#define wxLogFatalError wxDO_LOG(FatalError)
|
2009-07-09 20:26:34 +00:00
|
|
|
#define wxVLogFatalError(format, argptr) wxDO_LOGV(FatalError, format, argptr)
|
|
|
|
|
|
|
|
#define wxLogError wxDO_LOG_IF_ENABLED(Error)
|
|
|
|
#define wxVLogError(format, argptr) wxDO_LOGV(Error, format, argptr)
|
|
|
|
|
|
|
|
#define wxLogWarning wxDO_LOG_IF_ENABLED(Warning)
|
|
|
|
#define wxVLogWarning(format, argptr) wxDO_LOGV(Warning, format, argptr)
|
|
|
|
|
|
|
|
#define wxLogMessage wxDO_LOG_IF_ENABLED(Message)
|
|
|
|
#define wxVLogMessage(format, argptr) wxDO_LOGV(Message, format, argptr)
|
|
|
|
|
|
|
|
// this one is special as it only logs if we're in verbose mode
|
|
|
|
#define wxLogVerbose \
|
2009-07-12 14:56:23 +00:00
|
|
|
if ( !(wxLog::IsLevelEnabled(wxLOG_Info, wxLOG_COMPONENT) && \
|
|
|
|
wxLog::GetVerbose()) ) \
|
2009-07-09 20:26:34 +00:00
|
|
|
{} \
|
|
|
|
else \
|
|
|
|
wxDO_LOG(Info)
|
|
|
|
#define wxVLogVerbose(format, argptr) \
|
2009-07-12 14:56:23 +00:00
|
|
|
if ( !(wxLog::IsLevelEnabled(wxLOG_Info, wxLOG_COMPONENT) && \
|
|
|
|
wxLog::GetVerbose()) ) \
|
2009-07-09 20:26:34 +00:00
|
|
|
{} \
|
|
|
|
else \
|
|
|
|
wxDO_LOGV(Info, format, argptr)
|
|
|
|
|
|
|
|
// deprecated synonyms for wxLogVerbose() and wxVLogVerbose()
|
|
|
|
#define wxLogInfo wxLogVerbose
|
|
|
|
#define wxVLogInfo wxVLogVerbose
|
|
|
|
|
|
|
|
|
|
|
|
// another special case: the level is passed as first argument of the function
|
|
|
|
// and so is not available to the macro
|
|
|
|
//
|
|
|
|
// notice that because of this, arguments of wxLogGeneric() are currently
|
|
|
|
// always evaluated, unlike for the other log functions
|
|
|
|
#define wxLogGeneric wxMAKE_LOGGER(Max).LogAtLevel
|
|
|
|
#define wxVLogGeneric(level, format, argptr) \
|
2009-07-12 14:56:23 +00:00
|
|
|
if ( !wxLog::IsLevelEnabled(wxLOG_##level, wxLOG_COMPONENT) ) \
|
2009-07-09 20:26:34 +00:00
|
|
|
{} \
|
|
|
|
else \
|
|
|
|
wxDO_LOGV(level, format, argptr)
|
|
|
|
|
|
|
|
|
|
|
|
// wxLogSysError() needs to stash the error code value in the log record info
|
|
|
|
// so it needs special handling too; additional complications arise because the
|
|
|
|
// error code may or not be present as the first argument
|
2009-08-18 01:22:48 +00:00
|
|
|
//
|
|
|
|
// notice that we unfortunately can't avoid the call to wxSysErrorCode() even
|
|
|
|
// though it may be unneeded if an explicit error code is passed to us because
|
|
|
|
// the message might not be logged immediately (e.g. it could be queued for
|
|
|
|
// logging from the main thread later) and so we can't to wait until it is
|
|
|
|
// logged to determine whether we have last error or not as it will be too late
|
|
|
|
// and it will have changed already by then (in fact it even changes when
|
|
|
|
// wxString::Format() is called because of vsnprintf() inside it so it can
|
|
|
|
// change even much sooner)
|
2009-07-09 20:26:34 +00:00
|
|
|
#define wxLOG_KEY_SYS_ERROR_CODE "wx.sys_error"
|
|
|
|
|
|
|
|
#define wxLogSysError \
|
2009-07-12 14:56:23 +00:00
|
|
|
if ( !wxLog::IsLevelEnabled(wxLOG_Error, wxLOG_COMPONENT) ) \
|
2009-07-09 20:26:34 +00:00
|
|
|
{} \
|
|
|
|
else \
|
2009-08-18 01:22:48 +00:00
|
|
|
wxMAKE_LOGGER(Error).MaybeStore(wxLOG_KEY_SYS_ERROR_CODE, \
|
|
|
|
wxSysErrorCode()).Log
|
2009-07-09 20:26:34 +00:00
|
|
|
|
|
|
|
// unfortunately we can't have overloaded macros so we can't define versions
|
|
|
|
// both with and without error code argument and have to rely on LogV()
|
|
|
|
// overloads in wxLogger to select between them
|
|
|
|
#define wxVLogSysError \
|
2009-08-18 01:22:48 +00:00
|
|
|
wxMAKE_LOGGER(Error).MaybeStore(wxLOG_KEY_SYS_ERROR_CODE, \
|
|
|
|
wxSysErrorCode()).LogV
|
2009-07-09 20:26:34 +00:00
|
|
|
|
|
|
|
#if wxUSE_GUI
|
|
|
|
// wxLogStatus() is similar to wxLogSysError() as it allows to optionally
|
|
|
|
// specify the frame to which the message should go
|
|
|
|
#define wxLOG_KEY_FRAME "wx.frame"
|
|
|
|
|
|
|
|
#define wxLogStatus \
|
2009-07-12 14:56:23 +00:00
|
|
|
if ( !wxLog::IsLevelEnabled(wxLOG_Status, wxLOG_COMPONENT) ) \
|
2009-07-09 20:26:34 +00:00
|
|
|
{} \
|
|
|
|
else \
|
|
|
|
wxMAKE_LOGGER(Status).MaybeStore(wxLOG_KEY_FRAME).Log
|
|
|
|
|
2012-09-01 22:38:40 +00:00
|
|
|
#define wxVLogStatus \
|
2009-07-09 20:26:34 +00:00
|
|
|
wxMAKE_LOGGER(Status).MaybeStore(wxLOG_KEY_FRAME).LogV
|
|
|
|
#endif // wxUSE_GUI
|
2007-04-26 11:40:04 +00:00
|
|
|
|
2007-03-17 10:26:10 +00:00
|
|
|
|
1999-06-01 15:32:12 +00:00
|
|
|
#else // !wxUSE_LOG
|
|
|
|
|
2009-03-22 17:18:07 +00:00
|
|
|
#undef wxUSE_LOG_DEBUG
|
|
|
|
#define wxUSE_LOG_DEBUG 0
|
|
|
|
|
|
|
|
#undef wxUSE_LOG_TRACE
|
|
|
|
#define wxUSE_LOG_TRACE 0
|
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
// define macros for defining log functions which do nothing at all
|
|
|
|
#define wxDEFINE_EMPTY_LOG_FUNCTION(level) \
|
2009-08-18 01:22:57 +00:00
|
|
|
WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 1, (const wxFormatString&)) \
|
|
|
|
inline void wxVLog##level(const wxFormatString& WXUNUSED(format), \
|
2007-05-06 14:11:14 +00:00
|
|
|
va_list WXUNUSED(argptr)) { } \
|
2007-03-17 10:26:10 +00:00
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
#define wxDEFINE_EMPTY_LOG_FUNCTION2(level, argclass) \
|
2009-08-18 01:22:57 +00:00
|
|
|
WX_DEFINE_VARARG_FUNC_NOP(wxLog##level, 2, (argclass, const wxFormatString&)) \
|
2007-03-17 10:26:10 +00:00
|
|
|
inline void wxVLog##level(argclass WXUNUSED(arg), \
|
2009-08-18 01:22:57 +00:00
|
|
|
const wxFormatString& WXUNUSED(format), \
|
2007-05-06 14:11:14 +00:00
|
|
|
va_list WXUNUSED(argptr)) {}
|
2007-04-26 11:40:04 +00:00
|
|
|
|
2009-07-09 20:26:34 +00:00
|
|
|
wxDEFINE_EMPTY_LOG_FUNCTION(FatalError);
|
|
|
|
wxDEFINE_EMPTY_LOG_FUNCTION(Error);
|
|
|
|
wxDEFINE_EMPTY_LOG_FUNCTION(SysError);
|
|
|
|
wxDEFINE_EMPTY_LOG_FUNCTION2(SysError, long);
|
|
|
|
wxDEFINE_EMPTY_LOG_FUNCTION(Warning);
|
|
|
|
wxDEFINE_EMPTY_LOG_FUNCTION(Message);
|
|
|
|
wxDEFINE_EMPTY_LOG_FUNCTION(Info);
|
|
|
|
wxDEFINE_EMPTY_LOG_FUNCTION(Verbose);
|
|
|
|
|
|
|
|
wxDEFINE_EMPTY_LOG_FUNCTION2(Generic, wxLogLevel);
|
|
|
|
|
|
|
|
#if wxUSE_GUI
|
|
|
|
wxDEFINE_EMPTY_LOG_FUNCTION(Status);
|
|
|
|
wxDEFINE_EMPTY_LOG_FUNCTION2(Status, wxFrame *);
|
|
|
|
#endif // wxUSE_GUI
|
|
|
|
|
2003-01-12 22:20:46 +00:00
|
|
|
// Empty Class to fake wxLogNull
|
2003-07-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxLogNull
|
2003-01-12 22:20:46 +00:00
|
|
|
{
|
|
|
|
public:
|
2003-07-02 01:41:23 +00:00
|
|
|
wxLogNull() { }
|
2003-01-12 22:20:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// 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
|
2003-07-10 08:36:14 +00:00
|
|
|
#define wxTRACE_OleCalls wxEmptyString // OLE interface calls
|
2003-01-12 22:20:46 +00:00
|
|
|
|
1999-06-01 15:32:12 +00:00
|
|
|
#endif // wxUSE_LOG/!wxUSE_LOG
|
2006-07-31 16:56:51 +00:00
|
|
|
|
2009-03-22 17:18:07 +00:00
|
|
|
|
|
|
|
// debug functions can be completely disabled in optimized builds
|
|
|
|
|
|
|
|
// if these log functions are disabled, we prefer to define them as (empty)
|
|
|
|
// variadic macros as this completely removes them and their argument
|
|
|
|
// evaluation from the object code but if this is not supported by compiler we
|
|
|
|
// use empty inline functions instead (defining them as nothing would result in
|
|
|
|
// compiler warnings)
|
|
|
|
//
|
|
|
|
// note that making wxVLogDebug/Trace() themselves (empty inline) functions is
|
|
|
|
// a bad idea as some compilers are stupid enough to not inline even empty
|
|
|
|
// functions if their parameters are complicated enough, but by defining them
|
|
|
|
// as an empty inline function we ensure that even dumbest compilers optimise
|
|
|
|
// them away
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
// but Borland gives "W8019: Code has no effect" for wxLogNop() so we need
|
|
|
|
// to define it differently for it to avoid these warnings (same problem as
|
|
|
|
// with wxUnusedVar())
|
|
|
|
#define wxLogNop() { }
|
|
|
|
#else
|
|
|
|
inline void wxLogNop() { }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if wxUSE_LOG_DEBUG
|
2009-07-09 20:26:34 +00:00
|
|
|
#define wxLogDebug wxDO_LOG_IF_ENABLED(Debug)
|
|
|
|
#define wxVLogDebug(format, argptr) wxDO_LOGV(Debug, format, argptr)
|
2009-03-22 17:18:07 +00:00
|
|
|
#else // !wxUSE_LOG_DEBUG
|
|
|
|
#define wxVLogDebug(fmt, valist) wxLogNop()
|
1999-03-29 20:49:05 +00:00
|
|
|
|
2009-03-22 17:18:07 +00:00
|
|
|
#ifdef HAVE_VARIADIC_MACROS
|
|
|
|
#define wxLogDebug(fmt, ...) wxLogNop()
|
|
|
|
#else // !HAVE_VARIADIC_MACROS
|
2009-08-18 01:22:57 +00:00
|
|
|
WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug, 1, (const wxFormatString&))
|
2009-03-22 17:18:07 +00:00
|
|
|
#endif
|
|
|
|
#endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
|
1999-03-29 20:49:05 +00:00
|
|
|
|
2009-03-22 17:18:07 +00:00
|
|
|
#if wxUSE_LOG_TRACE
|
2009-07-09 20:26:34 +00:00
|
|
|
#define wxLogTrace \
|
2009-07-12 14:56:23 +00:00
|
|
|
if ( !wxLog::IsLevelEnabled(wxLOG_Trace, wxLOG_COMPONENT) ) \
|
2009-07-09 20:26:34 +00:00
|
|
|
{} \
|
|
|
|
else \
|
|
|
|
wxMAKE_LOGGER(Trace).LogTrace
|
2009-07-23 13:40:44 +00:00
|
|
|
#define wxVLogTrace \
|
|
|
|
if ( !wxLog::IsLevelEnabled(wxLOG_Trace, wxLOG_COMPONENT) ) \
|
|
|
|
{} \
|
|
|
|
else \
|
|
|
|
wxMAKE_LOGGER(Trace).LogVTrace
|
2009-03-22 17:18:07 +00:00
|
|
|
#else // !wxUSE_LOG_TRACE
|
2006-09-09 13:45:06 +00:00
|
|
|
#define wxVLogTrace(mask, fmt, valist) wxLogNop()
|
2006-09-05 14:21:08 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_VARIADIC_MACROS
|
2006-09-09 13:45:06 +00:00
|
|
|
#define wxLogTrace(mask, fmt, ...) wxLogNop()
|
2006-09-05 14:21:08 +00:00
|
|
|
#else // !HAVE_VARIADIC_MACROS
|
2009-03-22 20:51:21 +00:00
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
2009-08-18 01:22:57 +00:00
|
|
|
WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (wxTraceMask, const wxFormatString&))
|
2009-03-22 20:51:21 +00:00
|
|
|
#endif
|
2009-08-18 01:22:57 +00:00
|
|
|
WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (const wxString&, const wxFormatString&))
|
2006-09-05 14:21:08 +00:00
|
|
|
#endif // HAVE_VARIADIC_MACROS/!HAVE_VARIADIC_MACROS
|
2009-03-22 17:18:07 +00:00
|
|
|
#endif // wxUSE_LOG_TRACE/!wxUSE_LOG_TRACE
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2002-05-09 15:59:42 +00:00
|
|
|
// wxLogFatalError helper: show the (fatal) error to the user in a safe way,
|
|
|
|
// i.e. without using wxMessageBox() for example because it could crash
|
2003-07-02 01:59:24 +00:00
|
|
|
void WXDLLIMPEXP_BASE
|
2003-07-02 01:41:23 +00:00
|
|
|
wxSafeShowMessage(const wxString& title, const wxString& text);
|
2002-05-09 15:59:42 +00:00
|
|
|
|
1999-06-01 15:32:12 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// debug only logging functions: use them with API name and error code
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2009-03-22 15:40:08 +00:00
|
|
|
#if wxUSE_LOG_DEBUG
|
1999-05-19 00:53:27 +00:00
|
|
|
// 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__
|
2000-01-21 21:38:51 +00:00
|
|
|
#define wxLogApiError(api, rc) \
|
|
|
|
wxLogDebug(wxT("%s(%d): '%s' failed with error 0x%08lx (%s)."), \
|
2007-05-21 18:02:57 +00:00
|
|
|
__FILE__, __LINE__, api, \
|
2002-06-26 16:27:29 +00:00
|
|
|
(long)rc, wxSysErrorMsg(rc))
|
1999-05-19 00:53:27 +00:00
|
|
|
#else // !VC++
|
2000-01-21 21:38:51 +00:00
|
|
|
#define wxLogApiError(api, rc) \
|
2003-09-30 12:41:46 +00:00
|
|
|
wxLogDebug(wxT("In file %s at line %d: '%s' failed with ") \
|
|
|
|
wxT("error 0x%08lx (%s)."), \
|
2007-05-21 18:02:57 +00:00
|
|
|
__FILE__, __LINE__, api, \
|
2002-06-26 16:27:29 +00:00
|
|
|
(long)rc, wxSysErrorMsg(rc))
|
1999-05-19 00:53:27 +00:00
|
|
|
#endif // VC++/!VC++
|
|
|
|
|
|
|
|
#define wxLogLastError(api) wxLogApiError(api, wxSysErrorCode())
|
|
|
|
|
2009-03-22 15:40:08 +00:00
|
|
|
#else // !wxUSE_LOG_DEBUG
|
2006-09-09 13:45:06 +00:00
|
|
|
#define wxLogApiError(api, err) wxLogNop()
|
|
|
|
#define wxLogLastError(api) wxLogNop()
|
2009-03-22 15:40:08 +00:00
|
|
|
#endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2009-09-12 11:28:52 +00:00
|
|
|
// macro which disables debug logging in release builds: this is done by
|
2010-06-09 13:23:13 +00:00
|
|
|
// default by wxIMPLEMENT_APP() so usually it doesn't need to be used explicitly
|
2010-05-18 10:29:52 +00:00
|
|
|
#if defined(NDEBUG) && wxUSE_LOG_DEBUG
|
2009-09-12 11:28:52 +00:00
|
|
|
#define wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD() \
|
|
|
|
wxLog::SetLogLevel(wxLOG_Info)
|
|
|
|
#else // !NDEBUG
|
|
|
|
#define wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD()
|
|
|
|
#endif // NDEBUG/!NDEBUG
|
|
|
|
|
1998-08-15 00:23:28 +00:00
|
|
|
#endif // _WX_LOG_H_
|
2002-03-08 20:01:38 +00:00
|
|
|
|