Open Babel
3.0
|
#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 |
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:
or
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:
OBMessageHandler | ( | ) |
~OBMessageHandler | ( | ) |
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().
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.
std::vector< std::string > GetMessagesOfLevel | ( | const obMessageLevel | level | ) |
|
inline |
Start logging messages (default)
|
inline |
Stop logging messages completely.
|
inline |
Set the maximum number of entries (or 0 for no limit)
|
inline |
|
inline |
Clear the current message log entirely.
Referenced by OBConversion::FullConvert().
|
inline |
Set the level of messages to output (i.e., messages with at least this priority will be output)
|
inline |
Referenced by OBMol::Clear(), and OBMol::FindRingAtomsAndBonds().
|
inline |
|
inline |
bool StartErrorWrap | ( | ) |
Start "wrapping" messages to cerr into ThrowError calls.
bool StopErrorWrap | ( | ) |
Turn off "wrapping" messages, restoring normal cerr use (default)
Referenced by OBMessageHandler::~OBMessageHandler().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
string GetMessageSummary | ( | ) |
|
protected |
Count of messages at each message level.
Referenced by OBMessageHandler::GetMessageSummary(), OBMessageHandler::OBMessageHandler(), and OBMessageHandler::ThrowError().
|
protected |
Log of messages for later retrieval via GetMessagesOfLevel()
Referenced by OBMessageHandler::GetMessagesOfLevel(), and OBMessageHandler::ThrowError().
|
protected |
Filtering level for messages and logging (messages of lower priority will be ignored.
Referenced by OBMessageHandler::ThrowError().
|
protected |
Referenced by OBMessageHandler::ThrowError().
|
protected |
Whether messages will be logged into _messageList.
Referenced by OBMessageHandler::ThrowError().
|
protected |
The maximum size of _messageList log.
Referenced by OBMessageHandler::ThrowError().
|
protected |
The default stream buffer for the output stream (saved if wrapping is ued)
Referenced by OBMessageHandler::OBMessageHandler(), OBMessageHandler::StartErrorWrap(), and OBMessageHandler::StopErrorWrap().
|
protected |
The filtered obLogBuf stream buffer to wrap error messages.
Referenced by OBMessageHandler::OBMessageHandler(), OBMessageHandler::StartErrorWrap(), and OBMessageHandler::~OBMessageHandler().