Open Babel  3.0
Public Member Functions | Protected Attributes | List of all members
OBMessageHandler Class Reference

#include <openbabel/oberror.h>

Public Member Functions

 OBMessageHandler ()
 
 ~OBMessageHandler ()
 
void ThrowError (OBError err, errorQualifier qqualifier=always)
 
void ThrowError (const std::string &method, const std::string &errorMsg, obMessageLevel level=obDebug, errorQualifier qualifier=always)
 
std::vector< std::string > GetMessagesOfLevel (const obMessageLevel)
 
void StartLogging ()
 
void StopLogging ()
 
void SetMaxLogEntries (unsigned int max)
 
unsigned int GetMaxLogEntries ()
 
void ClearLog ()
 
void SetOutputLevel (const obMessageLevel level)
 
obMessageLevel GetOutputLevel ()
 
void SetOutputStream (std::ostream *os)
 
std::ostream * GetOutputStream ()
 
bool StartErrorWrap ()
 
bool StopErrorWrap ()
 
unsigned int GetErrorMessageCount ()
 
unsigned int GetWarningMessageCount ()
 
unsigned int GetInfoMessageCount ()
 
unsigned int GetAuditMessageCount ()
 
unsigned int GetDebugMessageCount ()
 
std::string GetMessageSummary ()
 

Protected Attributes

unsigned int _messageCount [5]
 
std::deque< OBError_messageList
 
obMessageLevel _outputLevel
 
std::ostream * _outputStream
 
bool _logging
 
unsigned int _maxEntries
 
std::streambuf * _inWrapStreamBuf
 
std::streambuf * _filterStreamBuf
 

Detailed Description

Handle error messages, warnings, debugging information and the like.

OBMessageHandler represents a configurable error system for Open Babel.

A global error log is defined by the Open Babel library for use of internal code as well as code built on top of Open Babel. This class allows flexible filtering based on urgency (defined by the obMessageLevel type), an "audit log" of molecular changes, including recall using the GetMessagesOfLevel method, etc.

The default is to only log and output errors of priority obMessageLevel::obError or obMessageLevel::obWarning.

Long-running code may wish to set the size of the in-memory error log using the StartLogging / StopLogging methods and SetMaxLogEntries. Otherwise, the error log may easily fill up, requiring large amounts of memory.

If you wish to divert error output to a different std::ostream (i.e., for graphical display, or a file log), use the SetOutputStream method – the default goes to the std::clog stream. Furthermore, some older code uses std::cerr for direct error output, rather than the ThrowError() methods in this class. To prevent this, you can turn on "error wrapping" using the StartErrorWrap method – this behavior is turned off by default.

To make it easy to use the OBMessageHandler class and error logging facilities, a global log is defined:

Therefore, it is very easy to log errors:

if (atomIndex < 1 || atomIndex > mol.NumAtoms() )
obErrorLog.ThrowError(__FUNCTION__, "Requested Atom Out of Range", obDebug);

or

stringstream errorMsg;
errorMsg << " Could not parse line in type translation table types.txt -- incorect number of columns";
errorMsg << " found " << vc.size() << " expected " << _ncols << ".";
obErrorLog.ThrowError(__FUNCTION__, errorMsg.str(), obInfo);

The FUNCTION builtin is defined by many compilers (e.g., GCC) but can be defined to an empty string on some platforms without this compiler extension.

Output from the error log typically looks like:

==============================
Open Babel Audit Log in ReadChemObject
OpenBabel::Read molecule Protein Data Bank format
==============================
Open Babel Information in ParseConectRecord
WARNING: Problems reading a PDB file
Problems reading a CONECT record.
According to the PDB specification,
the record should have 70 columns, but OpenBabel found 61 columns.

Constructor & Destructor Documentation

◆ OBMessageHandler()

◆ ~OBMessageHandler()

Member Function Documentation

◆ ThrowError() [1/2]

void ThrowError ( OBError  err,
errorQualifier  qqualifier = always 
)

Throw an error with an already-formatted OBError object.

Referenced by FastSearchIndexer::Add(), OBMol::AddBond(), OBConversion::AddChemObject(), OBMol::AddNewHydrogens(), OBDescriptor::AddProperties(), OBMol::Align(), OpenBabel::alternate(), OBChemTsfm::Apply(), patty::assign_types(), OBAromaticTyper::AssignAromaticFlags(), OBAtomTyper::AssignHyb(), OBGastChrg::AssignPartialCharges(), OBMol::AssignTotalChargeToAtoms(), OBAtomTyper::AssignTypes(), OBRingTyper::AssignTypes(), OBBuilder::Build(), OpenBabel::CartesianToInternal(), OBMol::Center(), OBConversion::CheckForUnintendedBatch(), FptIndex::CheckFP(), OBMol::Clear(), OBDescriptor::Compare(), OBMol::ConnectTheDots(), OBConversion::Convert(), OBMol::ConvertDativeBonds(), OBPhModel::CorrectForPH(), OBMol::CorrectForPH(), OBBuilder::CorrectStereoAtoms(), OBMoleculeFormat::DeferMolOutput(), OBMoleculeFormat::DeleteDeferredMols(), OBMol::DeleteHydrogens(), OBMol::DeleteNonPolarHydrogens(), OBMol::DeletePolarHydrogens(), OpenBabel::DeleteStereoOnAtom(), OBMol::DoTransformations(), OBMol::EndModify(), AliasData::Expand(), OpenBabel::FatalAllocationError(), OBDescriptor::FilterCompare(), SpaceGroup::Find(), FastSearch::Find(), OBMol::FindLSSR(), OpenBabel::findMetalloceneBonds(), OBMol::FindRingAtomsAndBonds(), OBRotorList::FindRotors(), OBMol::FindSSSR(), OBFingerprint::Fold(), OBConversion::FullConvert(), OBMol::GetAtom(), OBMol::GetAtomById(), OpenBabel::GetAtomIDNumber(), OBMol::GetBond(), OBMol::GetBondById(), OBMol::GetFormula(), OBBuilder::GetFragmentCoord(), OBDescriptor::GetIdentifier(), OBMol::GetResidue(), OBRotorRules::GetRotorIncrements(), OBMol::GetSpacedFormula(), OBMol::GetTotalCharge(), OBMol::GetTotalSpinMultiplicity(), OBDescriptor::GetValues(), OBAtom::HtoMethyl(), OBGlobalDataBase::Init(), OpenBabel::InternalToCartesian(), OBPlugin::LoadAllPlugins(), OBBuilder::LoadFragments(), OBMoleculeFormat::MakeCombinedMolecule(), OBConversion::NumInputObjects(), OBConversion::OpenAndSetFormat(), OBConversion::OpenInAndOutFiles(), DLHandler::openLib(), OBAtomTyper::ParseLine(), OBRingTyper::ParseLine(), OBRotorRules::ParseLine(), OBPhModel::ParseLine(), OBTypeTable::ParseLine(), OBMol::PerceiveBondOrders(), patty::read_rules(), OBConversion::ReadFile(), OBMoleculeFormat::ReadNameIndex(), OBDescriptor::ReadStringFromFilter(), OBConversion::RegisterOptionParam(), OBMol::RenumberAtoms(), OBMol::Rotate(), OpenBabel::SafeOpen(), OBTypeTable::SetFromType(), OBAtom::SetHybAndGeom(), OBMol::SetInternalCoord(), OBMol::SetTorsion(), OBTypeTable::SetToType(), OBRotorList::Setup(), OBSmartsPattern::SMARTSError(), OBMol::StripSalts(), OBMessageHandler::ThrowError(), OpenBabel::ThrowError(), OBTetraNonPlanarStereo::ToConfig(), OBMol::ToInertialFrame(), OBTypeTable::Translate(), OBMol::Translate(), patty::type_to_int(), OpenBabel::UnitNameToConversionFactor(), OBMoleculeFormat::WriteChemObjectImpl(), OBConversion::WriteFile(), and FastSearchIndexer::~FastSearchIndexer().

◆ ThrowError() [2/2]

void ThrowError ( const std::string &  method,
const std::string &  errorMsg,
obMessageLevel  level = obDebug,
errorQualifier  qualifier = always 
)

Throw an error in the specified method with an appropriate level.

◆ GetMessagesOfLevel()

std::vector< std::string > GetMessagesOfLevel ( const obMessageLevel  level)
Returns
all messages matching a specified level

◆ StartLogging()

void StartLogging ( )
inline

Start logging messages (default)

◆ StopLogging()

void StopLogging ( )
inline

Stop logging messages completely.

◆ SetMaxLogEntries()

void SetMaxLogEntries ( unsigned int  max)
inline

Set the maximum number of entries (or 0 for no limit)

◆ GetMaxLogEntries()

unsigned int GetMaxLogEntries ( )
inline
Returns
the current maximum number of entries (default = 0 for no limit)

◆ ClearLog()

void ClearLog ( )
inline

Clear the current message log entirely.

Referenced by OBConversion::FullConvert().

◆ SetOutputLevel()

void SetOutputLevel ( const obMessageLevel  level)
inline

Set the level of messages to output (i.e., messages with at least this priority will be output)

◆ GetOutputLevel()

obMessageLevel GetOutputLevel ( )
inline
Returns
the current output level

Referenced by OBMol::Clear(), and OBMol::FindRingAtomsAndBonds().

◆ SetOutputStream()

void SetOutputStream ( std::ostream *  os)
inline

◆ GetOutputStream()

std::ostream* GetOutputStream ( )
inline

◆ StartErrorWrap()

bool StartErrorWrap ( )

Start "wrapping" messages to cerr into ThrowError calls.

◆ StopErrorWrap()

bool StopErrorWrap ( )

Turn off "wrapping" messages, restoring normal cerr use (default)

Referenced by OBMessageHandler::~OBMessageHandler().

◆ GetErrorMessageCount()

unsigned int GetErrorMessageCount ( )
inline
Returns
Count of messages received at the obError level

◆ GetWarningMessageCount()

unsigned int GetWarningMessageCount ( )
inline
Returns
Count of messages received at the obWarning level

◆ GetInfoMessageCount()

unsigned int GetInfoMessageCount ( )
inline
Returns
Count of messages received at the obInfo level

◆ GetAuditMessageCount()

unsigned int GetAuditMessageCount ( )
inline
Returns
Count of messages received at the obAuditMsg level

◆ GetDebugMessageCount()

unsigned int GetDebugMessageCount ( )
inline
Returns
Count of messages received at the obDebug level

◆ GetMessageSummary()

string GetMessageSummary ( )
Returns
Summary of messages received at all levels

Member Data Documentation

◆ _messageCount

unsigned int _messageCount[5]
protected

◆ _messageList

std::deque<OBError> _messageList
protected

Log of messages for later retrieval via GetMessagesOfLevel()

Referenced by OBMessageHandler::GetMessagesOfLevel(), and OBMessageHandler::ThrowError().

◆ _outputLevel

obMessageLevel _outputLevel
protected

Filtering level for messages and logging (messages of lower priority will be ignored.

Referenced by OBMessageHandler::ThrowError().

◆ _outputStream

std::ostream* _outputStream
protected

◆ _logging

bool _logging
protected

Whether messages will be logged into _messageList.

Referenced by OBMessageHandler::ThrowError().

◆ _maxEntries

unsigned int _maxEntries
protected

The maximum size of _messageList log.

Referenced by OBMessageHandler::ThrowError().

◆ _inWrapStreamBuf

std::streambuf* _inWrapStreamBuf
protected

The default stream buffer for the output stream (saved if wrapping is ued)

Referenced by OBMessageHandler::OBMessageHandler(), OBMessageHandler::StartErrorWrap(), and OBMessageHandler::StopErrorWrap().

◆ _filterStreamBuf

std::streambuf* _filterStreamBuf
protected

The filtered obLogBuf stream buffer to wrap error messages.

Referenced by OBMessageHandler::OBMessageHandler(), OBMessageHandler::StartErrorWrap(), and OBMessageHandler::~OBMessageHandler().


The documentation for this class was generated from the following files: