Loading...
Searching...
No Matches
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:

OBERROR extern OBMessageHandler obErrorLog;
OpenBabel::OBMessageHandler::OBMessageHandler
OBMessageHandler()
Definition oberror.cpp:145
OpenBabel::obErrorLog
OBMessageHandler obErrorLog
Global OBMessageHandler error handler.
Definition oberror.h:187

Therefore, it is very easy to log errors:

if (atomIndex < 1 || atomIndex > mol.NumAtoms() )
obErrorLog.ThrowError(__FUNCTION__, "Requested Atom Out of Range", obDebug);
OpenBabel::obDebug
@ obDebug
for messages only useful for debugging purposes
Definition oberror.h:44

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);
OpenBabel::obInfo
@ obInfo
for informative messages (e.g., file is a non-standard format)
Definition oberror.h:42

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.
OpenBabel
Global namespace for all Open Babel code.
Definition alias.h:23

## Constructor & Destructor Documentation

## OBMessageHandler()

OBMessageHandler | ( |  | ) |

## ~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 ThrowError().

## 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.

## 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

## 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().

## 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

Count of messages at each message level.

Referenced by GetAuditMessageCount(), GetDebugMessageCount(), GetErrorMessageCount(), GetInfoMessageCount(), GetMessageSummary(), GetWarningMessageCount(), OBMessageHandler(), and ThrowError().

## _messageList

std::deque<OBError> _messageList

protected

Log of messages for later retrieval via GetMessagesOfLevel().

Referenced by ClearLog(), GetMessagesOfLevel(), and ThrowError().

## _outputLevel

obMessageLevel _outputLevel

protected

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

Referenced by GetOutputLevel(), OBMessageHandler(), SetOutputLevel(), and ThrowError().

## _outputStream

std::ostream* _outputStream

protected

Referenced by GetOutputStream(), OBMessageHandler(), SetOutputStream(), and ThrowError().

## _logging

bool _logging

protected

Whether messages will be logged into _messageList.

Referenced by OBMessageHandler(), StartLogging(), StopLogging(), and ThrowError().

## _maxEntries

unsigned int _maxEntries

protected

The maximum size of _messageList log.

Referenced by GetMaxLogEntries(), OBMessageHandler(), SetMaxLogEntries(), and ThrowError().

## _inWrapStreamBuf

std::streambuf* _inWrapStreamBuf

protected

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

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

## _filterStreamBuf

std::streambuf* _filterStreamBuf

protected

The filtered obLogBuf stream buffer to wrap error messages.

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

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

- oberror.h
- oberror.cpp