[Smtk-developers] Operators and changes to Logger
David Thompson
david.thompson at kitware.com
Wed Dec 17 14:59:50 EST 2014
Hi all,
Last night I pushed changes to master that add some methods to smtk::io::Logger for easier debugging as well as inter-process communication of operator results:
+ void setFlushToStream(
std::ostream* output, bool ownFile, bool includePast);
+ bool setFlushToFile( std::string filename, bool includePast);
+ void setFlushToStdout(bool includePast);
+ void setFlushToStderr(bool includePast);
Each Logger now stores an ostream* (which it may own and delete when modified). If non-NULL, then each time a record is added or another Logger is appended, the new records are printed to the stream and the stream flushed. Thus a logger created at startup and set to flush to a temporary file can be used for debugging.
The changes also modify the model manager so that it owns a logger. Model operators now record results of modeling operations to their manager's log and these are automatically appended to the OperatorResult attribute's "log" item (a StringItem).
Finally, the smtk::io::{Import,Export}JSON classes can serialize/deserialize log records to/from JSON. Applications wishing to present informational or error messages from Operators can:
OperatorPtr op; // = model->op("set property"), for instance.
OperatorResult res = op->operate();
StringItemPtr opmsg = res->findString("log");
if (opmsg->numberOfValues() > 0)
{
Logger oplog;
ImportJSON::ofLogger(cJSON_Parse(opmsg->value()), oplog);
// Now display oplog entries in the GUI
}
David
More information about the Smtk-developers
mailing list