Version: 3.1.0
wxLogChain Class Reference

#include <wx/log.h>

+ Inheritance diagram for wxLogChain:

Detailed Description

This simple class allows you to chain log sinks, that is to install a new sink but keep passing log messages to the old one instead of replacing it completely as wxLog::SetActiveTarget does.

It is especially useful when you want to divert the logs somewhere (for example to a file or a log window) but also keep showing the error messages using the standard dialogs as wxLogGui does by default.

Example of usage:

wxLogChain *logChain = new wxLogChain(new wxLogStderr);
// all the log messages are sent to stderr and also processed as usually
...
// don't delete logChain directly as this would leave a dangling
// pointer as active log target, use SetActiveTarget() instead
delete wxLog::SetActiveTarget(...something else or NULL...);

Library:  wxBase
Category:  Logging

Public Member Functions

 wxLogChain (wxLog *logger)
 Sets the specified logger (which may be NULL) as the default log target but the log messages are also passed to the previous log target if any.
 
virtual ~wxLogChain ()
 Destroys the previous log target.
 
void DetachOldLog ()
 Detaches the old log target so it won't be destroyed when the wxLogChain object is destroyed.
 
wxLogGetOldLog () const
 Returns the pointer to the previously active log target (which may be NULL).
 
bool IsPassingMessages () const
 Returns true if the messages are passed to the previously active log target (default) or false if PassMessages() had been called.
 
void PassMessages (bool passMessages)
 By default, the log messages are passed to the previously active log target.
 
void SetLog (wxLog *logger)
 Sets another log target to use (may be NULL).
 
- Public Member Functions inherited from wxLog
wxLogFormatterSetFormatter (wxLogFormatter *formatter)
 Sets the specified formatter as the active one.
 
virtual void Flush ()
 Some of wxLog implementations, most notably the standard wxLogGui class, buffer the messages (for example, to avoid showing the user a zillion of modal message boxes one after another – which would be really annoying).
 
void LogRecord (wxLogLevel level, const wxString &msg, const wxLogRecordInfo &info)
 Log the given record.
 

Additional Inherited Members

- Static Public Member Functions inherited from wxLog
static void AddTraceMask (const wxString &mask)
 Add the mask to the list of allowed masks for wxLogTrace().
 
static void ClearTraceMasks ()
 Removes all trace masks previously set with AddTraceMask().
 
static const wxArrayStringGetTraceMasks ()
 Returns the currently allowed list of string trace masks.
 
static bool IsAllowedTraceMask (const wxString &mask)
 Returns true if the mask is one of allowed masks for wxLogTrace().
 
static void RemoveTraceMask (const wxString &mask)
 Remove the mask from the list of allowed masks for wxLogTrace().
 
static void DontCreateOnDemand ()
 Instructs wxLog to not create new log targets on the fly if there is none currently (see GetActiveTarget()).
 
static wxLogGetActiveTarget ()
 Returns the pointer to the active log target (may be NULL).
 
static wxLogSetActiveTarget (wxLog *logtarget)
 Sets the specified log target as the active one.
 
static wxLogSetThreadActiveTarget (wxLog *logger)
 Sets a thread-specific log target.
 
static void FlushActive ()
 Flushes the current log target if any, does nothing if there is none.
 
static void Resume ()
 Resumes logging previously suspended by a call to Suspend().
 
static void Suspend ()
 Suspends the logging until Resume() is called.
 
static wxLogLevel GetLogLevel ()
 Returns the current log level limit.
 
static bool IsLevelEnabled (wxLogLevel level, wxString component)
 Returns true if logging at this level is enabled for the current thread.
 
static void SetComponentLevel (const wxString &component, wxLogLevel level)
 Sets the log level for the given component.
 
static void SetLogLevel (wxLogLevel logLevel)
 Specifies that log messages with level greater (numerically) than logLevel should be ignored and not sent to the active log target.
 
static bool EnableLogging (bool enable=true)
 Globally enable or disable logging.
 
static bool IsEnabled ()
 Returns true if logging is enabled at all now.
 
static bool GetRepetitionCounting ()
 Returns whether the repetition counting mode is enabled.
 
static void SetRepetitionCounting (bool repetCounting=true)
 Enables logging mode in which a log message is logged once, and in case exactly the same message successively repeats one or more times, only the number of repetitions is logged.
 
static const wxStringGetTimestamp ()
 Returns the current timestamp format string.
 
static void SetTimestamp (const wxString &format)
 Sets the timestamp format prepended by the default log targets to all messages.
 
static void DisableTimestamp ()
 Disables time stamping of the log messages.
 
static bool GetVerbose ()
 Returns whether the verbose mode is currently active.
 
static void SetVerbose (bool verbose=true)
 Activates or deactivates verbose mode in which the verbose messages are logged as the normal ones instead of being silently dropped.
 
- Protected Member Functions inherited from wxLog
virtual void DoLogRecord (wxLogLevel level, const wxString &msg, const wxLogRecordInfo &info)
 Called to log a new record.
 
virtual void DoLogTextAtLevel (wxLogLevel level, const wxString &msg)
 Called to log the specified string at given level.
 
virtual void DoLogText (const wxString &msg)
 Called to log the specified string.
 

Constructor & Destructor Documentation

wxLogChain::wxLogChain ( wxLog logger)

Sets the specified logger (which may be NULL) as the default log target but the log messages are also passed to the previous log target if any.

virtual wxLogChain::~wxLogChain ( )
virtual

Destroys the previous log target.

Member Function Documentation

void wxLogChain::DetachOldLog ( )

Detaches the old log target so it won't be destroyed when the wxLogChain object is destroyed.

wxLog* wxLogChain::GetOldLog ( ) const

Returns the pointer to the previously active log target (which may be NULL).

bool wxLogChain::IsPassingMessages ( ) const

Returns true if the messages are passed to the previously active log target (default) or false if PassMessages() had been called.

void wxLogChain::PassMessages ( bool  passMessages)

By default, the log messages are passed to the previously active log target.

Calling this function with false parameter disables this behaviour (presumably temporarily, as you shouldn't use wxLogChain at all otherwise) and it can be reenabled by calling it again with passMessages set to true.

void wxLogChain::SetLog ( wxLog logger)

Sets another log target to use (may be NULL).

The log target specified in the wxLogChain(wxLog*) constructor or in a previous call to this function is deleted. This doesn't change the old log target value (the one the messages are forwarded to) which still remains the same as was active when wxLogChain object was created.